Skip to content

Commit eb2fc97

Browse files
committed
unix modtime: Convert to static module structures.
1 parent de82922 commit eb2fc97

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

unix/main.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,6 @@ int main(int argc, char **argv) {
357357
#endif
358358

359359
microsocket_init();
360-
#if MICROPY_MOD_TIME
361-
time_init();
362-
#endif
363360
#if MICROPY_MOD_FFI
364361
ffi_init();
365362
#endif

unix/modtime.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,26 @@ STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) {
5151
}
5252
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_obj, mod_time_sleep);
5353

54-
void time_init() {
55-
mp_obj_t m = mp_obj_new_module(QSTR_FROM_STR_STATIC("time"));
56-
mp_store_attr(m, QSTR_FROM_STR_STATIC("time"), (mp_obj_t)&mod_time_time_obj);
57-
mp_store_attr(m, QSTR_FROM_STR_STATIC("clock"), (mp_obj_t)&mod_time_clock_obj);
58-
mp_store_attr(m, QSTR_FROM_STR_STATIC("sleep"), (mp_obj_t)&mod_time_sleep_obj);
59-
}
54+
STATIC const mp_map_elem_t mp_module_time_globals_table[] = {
55+
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_time) },
56+
{ MP_OBJ_NEW_QSTR(MP_QSTR_clock), (mp_obj_t)&mod_time_clock_obj },
57+
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&mod_time_sleep_obj },
58+
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&mod_time_time_obj },
59+
};
60+
61+
STATIC const mp_obj_dict_t mp_module_time_globals = {
62+
.base = {&mp_type_dict},
63+
.map = {
64+
.all_keys_are_qstrs = 1,
65+
.table_is_fixed_array = 1,
66+
.used = sizeof(mp_module_time_globals_table) / sizeof(mp_map_elem_t),
67+
.alloc = sizeof(mp_module_time_globals_table) / sizeof(mp_map_elem_t),
68+
.table = (mp_map_elem_t*)mp_module_time_globals_table,
69+
},
70+
};
71+
72+
const mp_obj_module_t mp_module_time = {
73+
.base = { &mp_type_module },
74+
.name = MP_QSTR_time,
75+
.globals = (mp_obj_dict_t*)&mp_module_time_globals,
76+
};

unix/mpconfigport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#define MICROPY_MOD_SYS_STDFILES (1)
1818
#define MICROPY_ENABLE_MOD_CMATH (1)
1919

20+
extern const struct _mp_obj_module_t mp_module_time;
21+
#define MICROPY_EXTRA_BUILTIN_MODULES \
22+
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&mp_module_time }, \
23+
2024
// type definitions for the specific machine
2125

2226
#ifdef __LP64__

unix/qstrdefsport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ Q(fficallback)
3030
Q(ffivar)
3131
Q(func)
3232
Q(var)
33+
34+
Q(time)
35+
Q(clock)
36+
Q(sleep)

0 commit comments

Comments
 (0)