Skip to content

Commit eb5c327

Browse files
committed
expose more types from obj.h to native modules
1 parent f020eac commit eb5c327

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

py/dynruntime.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,15 @@ static inline void *m_realloc_dyn(void *ptr, size_t new_num_bytes) {
7575
#define MP_OBJ_NEW_QSTR(x) MP_OBJ_NEW_QSTR_ ## x
7676

7777
#define mp_type_type (*mp_fun_table.type_type)
78+
#define mp_type_NoneType (*mp_fun_table.type_NoneType)
79+
#define mp_type_bool (*mp_fun_table.type_bool)
80+
#define mp_type_int (*mp_fun_table.type_int)
7881
#define mp_type_str (*mp_fun_table.type_str)
82+
#define mp_type_bytes (*mp_fun_table.type_bytes)
83+
#define mp_type_float (*mp_fun_table.type_float)
84+
#define mp_type_tuple (*mp_fun_table.type_tuple)
7985
#define mp_type_list (*mp_fun_table.type_list)
86+
#define mp_type_dict (*mp_fun_table.type_dict)
8087
#define mp_type_EOFError (*(mp_obj_type_t*)(mp_load_global(MP_QSTR_EOFError)))
8188
#define mp_type_IndexError (*(mp_obj_type_t*)(mp_load_global(MP_QSTR_IndexError)))
8289
#define mp_type_KeyError (*(mp_obj_type_t*)(mp_load_global(MP_QSTR_KeyError)))
@@ -104,18 +111,22 @@ static inline void *m_realloc_dyn(void *ptr, size_t new_num_bytes) {
104111
#define mp_obj_new_bytearray_by_ref(n, i) (mp_fun_table.obj_new_bytearray_by_ref((n), (i)))
105112
#define mp_obj_new_tuple(n, items) (mp_fun_table.new_tuple((n), (items)))
106113
#define mp_obj_new_list(n, items) (mp_fun_table.new_list((n), (items)))
114+
#define mp_obj_new_dict(n) (mp_fun_table.new_dict((n)))
107115

108116
#define mp_obj_get_type(o) (mp_fun_table.obj_get_type((o)))
109117
#define mp_obj_get_int(o) (mp_fun_table.native_from_obj(o, MP_NATIVE_TYPE_INT))
110118
#define mp_obj_get_int_truncated(o) (mp_fun_table.native_from_obj(o, MP_NATIVE_TYPE_UINT))
111119
#define mp_obj_str_get_str(s) ((void*)mp_fun_table.native_from_obj(s, MP_NATIVE_TYPE_PTR))
120+
#define mp_obj_bytes_get_bytes(s) ((void*)mp_fun_table.native_from_obj(s, MP_NATIVE_TYPE_PTR))
121+
112122
#define mp_obj_str_get_data(o, len) (mp_obj_str_get_data_dyn((o), (len)))
113123
#define mp_get_buffer_raise(o, bufinfo, fl) (mp_fun_table.get_buffer_raise((o), (bufinfo), (fl)))
114124
#define mp_get_stream_raise(s, flags) (mp_fun_table.get_stream_raise((s), (flags)))
115125

116126
#define mp_obj_len(o) (mp_obj_len_dyn(o))
117127
#define mp_obj_subscr(base, index, val) (mp_fun_table.obj_subscr((base), (index), (val)))
118128
#define mp_obj_list_append(list, item) (mp_fun_table.list_append((list), (item)))
129+
#define mp_obj_dict_store(dict, key, val) (mp_fun_table.dict_store(dict, key, val))
119130

120131
static inline mp_obj_t mp_obj_new_str_of_type_dyn(const mp_obj_type_t *type, const byte* data, size_t len) {
121132
if (type == &mp_type_str) {

py/nativeglue.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,13 @@ const mp_fun_table_t mp_fun_table = {
332332
mp_get_stream_raise,
333333
&mp_plat_print,
334334
&mp_type_type,
335+
&mp_type_NoneType,
336+
&mp_type_bool,
337+
&mp_type_int,
335338
&mp_type_str,
339+
&mp_type_bytes,
340+
&mp_type_float,
341+
&mp_type_tuple,
336342
&mp_type_list,
337343
&mp_type_dict,
338344
&mp_type_fun_builtin_0,

py/nativeglue.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,23 @@ typedef struct _mp_fun_table_t {
157157
void (*get_buffer_raise)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
158158
const mp_stream_p_t *(*get_stream_raise)(mp_obj_t self_in, int flags);
159159
const mp_print_t *plat_print;
160+
160161
const mp_obj_type_t *type_type;
162+
const mp_obj_type_t *type_NoneType;
163+
const mp_obj_type_t *type_bool;
164+
const mp_obj_type_t *type_int;
161165
const mp_obj_type_t *type_str;
166+
const mp_obj_type_t *type_bytes;
167+
const mp_obj_type_t *type_float;
168+
const mp_obj_type_t *type_tuple;
162169
const mp_obj_type_t *type_list;
163170
const mp_obj_type_t *type_dict;
164171
const mp_obj_type_t *type_fun_builtin_0;
165172
const mp_obj_type_t *type_fun_builtin_1;
166173
const mp_obj_type_t *type_fun_builtin_2;
167174
const mp_obj_type_t *type_fun_builtin_3;
168175
const mp_obj_type_t *type_fun_builtin_var;
176+
169177
const mp_obj_fun_builtin_var_t *stream_read_obj;
170178
const mp_obj_fun_builtin_var_t *stream_readinto_obj;
171179
const mp_obj_fun_builtin_var_t *stream_unbuffered_readline_obj;

tools/mpy_ld.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,13 @@ def link_objects(env, native_qstr_vals_len, native_qstr_objs_len):
666666
fun_table = {key: 67 + idx
667667
for idx, key in enumerate([
668668
'mp_type_type',
669+
'mp_type_NoneType',
670+
'mp_type_bool',
671+
'mp_type_int',
669672
'mp_type_str',
673+
'mp_type_bytes',
674+
'mp_type_float',
675+
'mp_type_tuple',
670676
'mp_type_list',
671677
'mp_type_dict',
672678
'mp_type_fun_builtin_0',

0 commit comments

Comments
 (0)