Skip to content

Commit bbeaafd

Browse files
committed
extmod: Add dynamic-runtime guards to btree/framebuf/uheapq/ure/uzlib.
So they can be built as dynamic native modules, as well as existing static native modules.
1 parent e5acd06 commit bbeaafd

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

extmod/modbtree.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ typedef struct _mp_obj_btree_t {
5252
byte next_flags;
5353
} mp_obj_btree_t;
5454

55+
#if !MICROPY_ENABLE_DYNRUNTIME
5556
STATIC const mp_obj_type_t btree_type;
57+
#endif
5658

5759
#define CHECK_ERROR(res) \
5860
if (res == RET_ERROR) { \
@@ -295,6 +297,7 @@ STATIC mp_obj_t btree_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs
295297
}
296298
}
297299

300+
#if !MICROPY_ENABLE_DYNRUNTIME
298301
STATIC const mp_rom_map_elem_t btree_locals_dict_table[] = {
299302
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&btree_close_obj) },
300303
{ MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&btree_flush_obj) },
@@ -319,6 +322,7 @@ STATIC const mp_obj_type_t btree_type = {
319322
.subscr = btree_subscr,
320323
.locals_dict = (void*)&btree_locals_dict,
321324
};
325+
#endif
322326

323327
STATIC const FILEVTABLE btree_stream_fvtable = {
324328
mp_stream_posix_read,
@@ -327,6 +331,7 @@ STATIC const FILEVTABLE btree_stream_fvtable = {
327331
mp_stream_posix_fsync
328332
};
329333

334+
#if !MICROPY_ENABLE_DYNRUNTIME
330335
STATIC mp_obj_t mod_btree_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
331336
static const mp_arg_t allowed_args[] = {
332337
{ MP_QSTR_flags, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
@@ -373,5 +378,6 @@ const mp_obj_module_t mp_module_btree = {
373378
.base = { &mp_type_module },
374379
.globals = (mp_obj_dict_t*)&mp_module_btree_globals,
375380
};
381+
#endif
376382

377383
#endif // MICROPY_PY_BTREE

extmod/modframebuf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ STATIC mp_obj_t framebuf_text(size_t n_args, const mp_obj_t *args) {
580580
}
581581
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_text_obj, 4, 5, framebuf_text);
582582

583+
#if !MICROPY_ENABLE_DYNRUNTIME
583584
STATIC const mp_rom_map_elem_t framebuf_locals_dict_table[] = {
584585
{ MP_ROM_QSTR(MP_QSTR_fill), MP_ROM_PTR(&framebuf_fill_obj) },
585586
{ MP_ROM_QSTR(MP_QSTR_fill_rect), MP_ROM_PTR(&framebuf_fill_rect_obj) },
@@ -601,6 +602,7 @@ STATIC const mp_obj_type_t mp_type_framebuf = {
601602
.buffer_p = { .get_buffer = framebuf_get_buffer },
602603
.locals_dict = (mp_obj_dict_t*)&framebuf_locals_dict,
603604
};
605+
#endif
604606

605607
// this factory function is provided for backwards compatibility with old FrameBuffer1 class
606608
STATIC mp_obj_t legacy_framebuffer1(size_t n_args, const mp_obj_t *args) {
@@ -624,6 +626,7 @@ STATIC mp_obj_t legacy_framebuffer1(size_t n_args, const mp_obj_t *args) {
624626
}
625627
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(legacy_framebuffer1_obj, 3, 4, legacy_framebuffer1);
626628

629+
#if !MICROPY_ENABLE_DYNRUNTIME
627630
STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = {
628631
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_framebuf) },
629632
{ MP_ROM_QSTR(MP_QSTR_FrameBuffer), MP_ROM_PTR(&mp_type_framebuf) },
@@ -644,5 +647,6 @@ const mp_obj_module_t mp_module_framebuf = {
644647
.base = { &mp_type_module },
645648
.globals = (mp_obj_dict_t*)&framebuf_module_globals,
646649
};
650+
#endif
647651

648652
#endif // MICROPY_PY_FRAMEBUF

extmod/moduheapq.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ STATIC mp_obj_t mod_uheapq_heapify(mp_obj_t heap_in) {
103103
}
104104
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_uheapq_heapify_obj, mod_uheapq_heapify);
105105

106+
#if !MICROPY_ENABLE_DYNRUNTIME
106107
STATIC const mp_rom_map_elem_t mp_module_uheapq_globals_table[] = {
107108
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uheapq) },
108109
{ MP_ROM_QSTR(MP_QSTR_heappush), MP_ROM_PTR(&mod_uheapq_heappush_obj) },
@@ -116,5 +117,6 @@ const mp_obj_module_t mp_module_uheapq = {
116117
.base = { &mp_type_module },
117118
.globals = (mp_obj_dict_t*)&mp_module_uheapq_globals,
118119
};
120+
#endif
119121

120122
#endif //MICROPY_PY_UHEAPQ

extmod/modure.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(match_end_obj, 1, 2, match_end);
144144

145145
#endif
146146

147+
#if !MICROPY_ENABLE_DYNRUNTIME
147148
STATIC const mp_rom_map_elem_t match_locals_dict_table[] = {
148149
{ MP_ROM_QSTR(MP_QSTR_group), MP_ROM_PTR(&match_group_obj) },
149150
#if MICROPY_PY_URE_MATCH_GROUPS
@@ -164,6 +165,7 @@ STATIC const mp_obj_type_t match_type = {
164165
.print = match_print,
165166
.locals_dict = (void*)&match_locals_dict,
166167
};
168+
#endif
167169

168170
STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
169171
(void)kind;
@@ -363,6 +365,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_sub_obj, 3, 5, re_sub);
363365

364366
#endif
365367

368+
#if !MICROPY_ENABLE_DYNRUNTIME
366369
STATIC const mp_rom_map_elem_t re_locals_dict_table[] = {
367370
{ MP_ROM_QSTR(MP_QSTR_match), MP_ROM_PTR(&re_match_obj) },
368371
{ MP_ROM_QSTR(MP_QSTR_search), MP_ROM_PTR(&re_search_obj) },
@@ -380,6 +383,7 @@ STATIC const mp_obj_type_t re_type = {
380383
.print = re_print,
381384
.locals_dict = (void*)&re_locals_dict,
382385
};
386+
#endif
383387

384388
STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
385389
(void)n_args;
@@ -437,6 +441,7 @@ STATIC mp_obj_t mod_re_sub(size_t n_args, const mp_obj_t *args) {
437441
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_re_sub_obj, 3, 5, mod_re_sub);
438442
#endif
439443

444+
#if !MICROPY_ENABLE_DYNRUNTIME
440445
STATIC const mp_rom_map_elem_t mp_module_re_globals_table[] = {
441446
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ure) },
442447
{ MP_ROM_QSTR(MP_QSTR_compile), MP_ROM_PTR(&mod_re_compile_obj) },
@@ -456,6 +461,7 @@ const mp_obj_module_t mp_module_ure = {
456461
.base = { &mp_type_module },
457462
.globals = (mp_obj_dict_t*)&mp_module_re_globals,
458463
};
464+
#endif
459465

460466
// Source files #include'd here to make sure they're compiled in
461467
// only if module is enabled by config setting.

extmod/moduzlib.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,29 @@ STATIC mp_uint_t decompio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er
122122
return o->decomp.dest - (byte*)buf;
123123
}
124124

125+
#if !MICROPY_ENABLE_DYNRUNTIME
125126
STATIC const mp_rom_map_elem_t decompio_locals_dict_table[] = {
126127
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
127128
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
128129
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
129130
};
130131

131132
STATIC MP_DEFINE_CONST_DICT(decompio_locals_dict, decompio_locals_dict_table);
133+
#endif
132134

133135
STATIC const mp_stream_p_t decompio_stream_p = {
134136
.read = decompio_read,
135137
};
136138

139+
#if !MICROPY_ENABLE_DYNRUNTIME
137140
STATIC const mp_obj_type_t decompio_type = {
138141
{ &mp_type_type },
139142
.name = MP_QSTR_DecompIO,
140143
.make_new = decompio_make_new,
141144
.protocol = &decompio_stream_p,
142145
.locals_dict = (void*)&decompio_locals_dict,
143146
};
147+
#endif
144148

145149
STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
146150
mp_obj_t data = args[0];
@@ -201,6 +205,7 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
201205
}
202206
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_uzlib_decompress);
203207

208+
#if !MICROPY_ENABLE_DYNRUNTIME
204209
STATIC const mp_rom_map_elem_t mp_module_uzlib_globals_table[] = {
205210
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uzlib) },
206211
{ MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&mod_uzlib_decompress_obj) },
@@ -213,6 +218,7 @@ const mp_obj_module_t mp_module_uzlib = {
213218
.base = { &mp_type_module },
214219
.globals = (mp_obj_dict_t*)&mp_module_uzlib_globals,
215220
};
221+
#endif
216222

217223
// Source files #include'd here to make sure they're compiled in
218224
// only if module is enabled by config setting.

0 commit comments

Comments
 (0)