8000 expose all types from obj.h to native modules · micropython/micropython@8a8698c · GitHub
[go: up one dir, main page]

Skip to content

Commit 8a8698c

Browse files
committed
expose all types from obj.h to native modules
1 parent f020eac commit 8a8698c

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

py/dynruntime.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,16 @@ static inline void *m_realloc_dyn(void *ptr, size_t new_num_bytes) {
109109
#define mp_obj_get_int(o) (mp_fun_table.native_from_obj(o, MP_NATIVE_TYPE_INT))
110110
#define mp_obj_get_int_truncated(o) (mp_fun_table.native_from_obj(o, MP_NATIVE_TYPE_UINT))
111111
#define mp_obj_str_get_str(s) ((void*)mp_fun_table.native_from_obj(s, MP_NATIVE_TYPE_PTR))
112+
#define mp_obj_bytes_get_bytes(s) ((void*)mp_fun_table.native_from_obj(s, MP_NATIVE_TYPE_PTR))
113+
112114
#define mp_obj_str_get_data(o, len) 10000 (mp_obj_str_get_data_dyn((o), (len)))
113115
#define mp_get_buffer_raise(o, bufinfo, fl) (mp_fun_table.get_buffer_raise((o), (bufinfo), (fl)))
114116
#define mp_get_stream_raise(s, flags) (mp_fun_table.get_stream_raise((s), (flags)))
115117

116118
#define mp_obj_len(o) (mp_obj_len_dyn(o))
117119
#define mp_obj_subscr(base, index, val) (mp_fun_table.obj_subscr((base), (index), (val)))
118120
#define mp_obj_list_append(list, item) (mp_fun_table.list_append((list), (item)))
121+
#define mp_obj_dict_store(dict, key, val) (mp_fun_table.dict_store(dict, key, val))
119122

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

py/nativeglue.c

Lines changed: 10 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,14 +334,22 @@ 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,
339348
&mp_type_fun_builtin_1,
340349
&mp_type_fun_builtin_2,
341350
&mp_type_fun_builtin_3,
342351
&mp_type_fun_builtin_var,
352+
&mp_type_unsupported_type,
343353
&mp_stream_read_obj,
344354
&mp_stream_readinto_obj,
345355
&mp_stream_unbuffered_readline_obj,

py/nativeglue.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,25 @@ 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+
const mp_obj_type_t *type_unsupported_type;
178+
169179
const mp_obj_fun_builtin_var_t *stream_read_obj;
170180
const mp_obj_fun_builtin_var_t *stream_readinto_obj;
171181
const mp_obj_fun_builtin_var_t *stream_unbuffered_readline_obj;

py/obj.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
#include "py/stackctrl.h"
3838
#include "py/stream.h" // for mp_obj_print
3939

40+
const mp_obj_type_t mp_type_unsupported_type = {
41+
{ &mp_type_type },
42+
.name = MP_QSTR_unsupported_type,
43+
};
44+
4045
const mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in) {
4146
#if MICROPY_OBJ_IMMEDIATE_OBJS && MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A
4247

py/obj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ extern const mp_obj_type_t mp_type_stringio;
607607
extern const mp_obj_type_t mp_type_bytesio;
608608
extern const mp_obj_type_t mp_type_reversed;
609609
extern const mp_obj_type_t mp_type_polymorph_iter;
610+
extern const mp_obj_type_t mp_type_unsupported_type; // used to indicate that a type is not supported to a native module
610611

611612
// Exceptions
612613
extern const mp_obj_type_t mp_type_BaseException;

tools/mpy_ld.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,14 +666,22 @@ 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',
673680
'mp_type_fun_builtin_1',
674681
'mp_type_fun_builtin_2',
675682
'mp_type_fun_builtin_3',
676683
'mp_type_fun_builtin_var',
684+
'mp_type_unsupported_type',
677685
'mp_stream_read_obj',
678686
'mp_stream_readinto_obj',
679687
'mp_stream_unbuffered_readline_obj',

0 commit comments

Comments
 (0)
0