Closed
Description
I'm trying to expose the mp_type_int
, mp_type_float
and mp_type_bytes
to native modules. I have done the following things:
- modified
mp_fun_table_t
innativeglue.h
to add the types:
...
const mp_obj_type_t *type_type;
const mp_obj_type_t *type_int;
const mp_obj_type_t *type_float;
const mp_obj_type_t *type_str;
const mp_obj_type_t *type_bytes;
const mp_obj_type_t *type_list;
const mp_obj_type_t *type_dict;
const mp_obj_type_t *type_fun_builtin_0;
const mp_obj_type_t *type_fun_builtin_1;
const mp_obj_type_t *type_fun_builtin_2;
const mp_obj_type_t *type_fun_builtin_3;
const mp_obj_type_t *type_fun_builtin_var;
...
- modified
mp_fun_table
innativeglue.c
to set the pointer values:
...
&mp_type_type,
&mp_type_int,
&mp_type_float,
&mp_type_str,
&mp_type_bytes,
&mp_type_list,
&mp_type_dict,
&mp_type_fun_builtin_0,
&mp_type_fun_builtin_1,
&mp_type_fun_builtin_2,
&mp_type_fun_builtin_3,
&mp_type_fun_builtin_var,
...
- recompiled the micropython unix port.
Unfortunately I seem to be getting an odd error where the functions are no longer hooked up correctly, I suspect that this is because there is an offset in the exported function table somewhere which has not been updated, so mp_type_fun_builtin_1
is now mapped to mp_type_list
.
==26922== Memcheck, a memory error detector
==26922== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==26922== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==26922== Command: ../../../ports/unix/micropython
==26922==
MicroPython v1.12-88-gae3fadbc3-dirty on 2020-02-13; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import ucbor
>>> ucbor.loads(b'\x01')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'list' object isn't callable
>>>
I also noticed that in mpy_ld.py
there is a section which specifically resolves some other type symbols. Adjusting this to also add my new types did not solve the problem unfortunately (and I'm not getting a linker error anyway...)
Does anyone know where the table is that I am not updating properly?