Skip to content

Commit fc9ec45

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

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include "py/nativeglue.h"
3535
#include "py/gc.h"
3636

37+
#define MICROPY_SET_TYPE_IF_SUPPORTED(SUPPORTED_DEFINE, TYPE) SUPPORTED_DEFINE?&TYPE:&mp_type_unsupported_type
38+
3739
#if MICROPY_DEBUG_VERBOSE // print debugging info
3840
#define DEBUG_printf DEBUG_printf
3941
#else // don't print debugging info
@@ -332,7 +334,14 @@ const mp_fun_table_t mp_fun_table = {
332334
mp_get_stream_raise,
333335
&mp_plat_print,
334336
&mp_type_type,
337+
&mp_type_object,
338+
&mp_type_NoneType,
339+
&mp_type_bool,
340+
&mp_type_int,
335341
&mp_type_str,
342+
&mp_type_bytes,
343+
&mp_type_float,
344+
&mp_type_tuple,
336345
&mp_type_list,
337346
&mp_type_dict,
338347
&mp_type_fun_builtin_0,

py/nativeglue.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,24 @@ 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_object;
163+
const mp_obj_type_t *type_NoneType;
164+
const mp_obj_type_t *type_bool;
165+
const mp_obj_type_t *type_int;
161166
const mp_obj_type_t *type_str;
167+
const mp_obj_type_t *type_bytes;
168+
const mp_obj_type_t *type_float;
169+
const mp_obj_type_t *type_tuple;
162170
const mp_obj_type_t *type_list;
163171
const mp_obj_type_t *type_dict;
164172
const mp_obj_type_t *type_fun_builtin_0;
165173
const mp_obj_type_t *type_fun_builtin_1;
166174
const mp_obj_type_t *type_fun_builtin_2;
167175
const mp_obj_type_t *type_fun_builtin_3;
168176
const mp_obj_type_t *type_fun_builtin_var;
177+
169178
const mp_obj_fun_builtin_var_t *stream_read_obj;
170179
const mp_obj_fun_builtin_var_t *stream_readinto_obj;
171180
const mp_obj_fun_builtin_var_t *stream_unbuffered_readline_obj;

tools/mpy_ld.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,14 @@ 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_object',
670+
'mp_type_NoneType',
671+
'mp_type_bool',
672+
'mp_type_int',
669673
'mp_type_str',
674+
'mp_type_bytes',
675+
'mp_type_float',
676+
'mp_type_tuple',
670677
'mp_type_list',
671678
'mp_type_dict',
672679
'mp_type_fun_builtin_0',

0 commit comments

Comments
 (0)