8000 stmhal: Enable module weak links. · eighthree/circuitpython@0107e90 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit 0107e90

Browse files
committed
stmhal: Enable module weak links.
os, time, select modules are now prefixed with u, but are still available (via weak links) as their original names. ure and ujson now available as re and json via weak links.
1 parent c14a816 commit 0107e90

File tree

6 files changed

+36
-19
lines changed

6 files changed

+36
-19
lines changed

stmhal/modos.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom);
330330
#endif
331331

332332
STATIC const mp_map_elem_t os_module_globals_table[] = {
333-
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_os) },
333+
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_uos) },
334334

335335
{ MP_OBJ_NEW_QSTR(MP_QSTR_chdir), (mp_obj_t)&os_chdir_obj },
336336
{ MP_OBJ_NEW_QSTR(MP_QSTR_getcwd), (mp_obj_t)&os_getcwd_obj },
@@ -362,8 +362,8 @@ STATIC const mp_obj_dict_t os_module_globals = {
362362
},
363363
};
364364

365-
const mp_obj_module_t os_module = {
365+
const mp_obj_module_t mp_module_uos = {
366366
.base = { &mp_type_module },
367-
.name = MP_QSTR_os,
367+
.name = MP_QSTR_uos,
368368
.globals = (mp_obj_dict_t*)&os_module_globals,
369369
};

stmhal/modselect.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ STATIC mp_obj_t select_poll(void) {
287287
MP_DEFINE_CONST_FUN_OBJ_0(mp_select_poll_obj, select_poll);
288288

289289
STATIC const mp_map_elem_t mp_module_select_globals_table[] = {
290-
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_select) },
290+
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_uselect) },
291291
{ MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_select_select_obj },
292292
{ MP_OBJ_NEW_QSTR(MP_QSTR_poll), (mp_obj_t)&mp_select_poll_obj },
293293
};
@@ -303,8 +303,8 @@ STATIC const mp_obj_dict_t mp_module_select_globals = {
303303
},
304304
};
305305

306-
const mp_obj_module_t mp_module_select = {
306+
const mp_obj_module_t mp_module_uselect = {
307307
.base = { &mp_type_module },
308-
.name = MP_QSTR_select,
308+
.name = MP_QSTR_uselect,
309309
.globals = (mp_obj_dict_t*)&mp_module_select_globals,
310310
};

stmhal/modtime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ STATIC mp_obj_t time_time(void) {
336336
MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
337337

338338
STATIC const mp_map_elem_t time_module_globals_table[] = {
339-
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_time) },
339+
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_utime) },
340340

341341
{ MP_OBJ_NEW_QSTR(MP_QSTR_localtime), (mp_obj_t)&time_localtime_obj },
342342
{ MP_OBJ_NEW_QSTR(MP_QSTR_mktime), (mp_obj_t)&time_mktime_obj },
@@ -355,8 +355,8 @@ STATIC const mp_obj_dict_t time_module_globals = {
355355
},
356356
};
357357

358-
const mp_obj_module_t time_module = {
358+
const mp_obj_module_t mp_module_utime = {
359359
.base = { &mp_type_module },
360-
.name = MP_QSTR_time,
360+
.name = MP_QSTR_utime,
361361
.globals = (mp_obj_dict_t*)&time_module_globals,
362362
};

stmhal/mpconfigport.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
*/
4949
#define MICROPY_ENABLE_LFN (1)
5050
#define MICROPY_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
51+
#define MICROPY_MODULE_WEAK_LINKS (1)
5152
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
5253
#define MICROPY_PY_BUILTINS_FROZENSET (1)
5354
#define MICROPY_PY_SYS_EXIT (1)
@@ -73,24 +74,33 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
7374
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
7475

7576
// extra built in modules to add to the list of known ones
76-
extern const struct _mp_obj_module_t os_module;
7777
extern const struct _mp_obj_module_t pyb_module;
7878
extern const struct _mp_obj_module_t stm_module;
79-
extern const struct _mp_obj_module_t time_module;
80-
extern const struct _mp_obj_module_t mp_module_select;
79+
extern const struct _mp_obj_module_t mp_module_ure;
80+
extern const struct _mp_obj_module_t mp_module_ujson;
81+
extern const struct _mp_obj_module_t mp_module_uos;
82+
extern const struct _mp_obj_module_t mp_module_utime;
83+
extern const struct _mp_obj_module_t mp_module_uselect;
8184
extern const struct _mp_obj_module_t mp_module_usocket;
8285
extern const struct _mp_obj_module_t mp_module_network;
8386

8487
#define MICROPY_PORT_BUILTIN_MODULES \
85-
{ MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module }, \
8688
{ MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \
8789
{ MP_OBJ_NEW_QSTR(MP_QSTR_stm), (mp_obj_t)&stm_module }, \
88-
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
89-
{ MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_select }, \
90+
{ MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_uos }, \
91+
{ MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&mp_module_utime }, \
92+
{ MP_OBJ_NEW_QSTR(MP_QSTR_uselect), (mp_obj_t)&mp_module_uselect }, \
9093
{ MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_usocket }, \
91-
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_usocket }, \
9294
{ MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&mp_module_network }, \
9395

96+
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
97+
{ MP_OBJ_NEW_QSTR(MP_QSTR_re), (mp_obj_t)&mp_module_ure }, \
98+
{ MP_OBJ_NEW_QSTR(MP_QSTR_json), (mp_obj_t)&mp_module_ujson }, \
99+
{ MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&mp_module_uos }, \
100+
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&mp_module_utime }, \
101+
{ MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_uselect }, \
102+
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_usocket }, \
103+
94104
// extra constants
95105
#define MICROPY_PORT_CONSTANTS \
96106
{ MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \

stmhal/portmodules.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
extern const mp_obj_module_t os_module;
2827
extern const mp_obj_module_t pyb_module;
2928
extern const mp_obj_module_t stm_module;
30-
extern const mp_obj_module_t time_module;
31-
extern const mp_obj_module_t mp_module_select;
29+
extern const mp_obj_module_t mp_module_uos;
30+
extern const mp_obj_module_t mp_module_utime;
31+
extern const mp_obj_module_t mp_module_uselect;
3232
extern const mp_obj_module_t mp_module_usocket;
3333

3434
// additional helper functions exported by the modules

stmhal/qstrdefsport.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ Q(micros)
7171
Q(elapsed_millis)
7272
Q(elapsed_micros)
7373

74+
// for module weak links
75+
Q(re)
76+
Q(json)
77+
7478
// for file class
7579
Q(seek)
7680
Q(tell)
@@ -296,6 +300,7 @@ Q(angle)
296300
Q(speed)
297301

298302
// for os module
303+
Q(uos)
299304
Q(os)
300305
Q(/)
301306
Q(flash)
@@ -312,12 +317,14 @@ Q(stat)
312317
Q(urandom)
313318

314319
// for time module
320+
Q(utime)
315321
Q(time)
316322
Q(localtime)
317323
Q(mktime)
318324
Q(sleep)
319325

320326
// for select module
327+
Q(uselect)
321328
Q(select)
322329
Q(poll)
323330
Q(register)

0 commit comments

Comments
 (0)
0