diff options
Diffstat (limited to 'py/objmodule.c')
-rw-r--r-- | py/objmodule.c | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/py/objmodule.c b/py/objmodule.c index 63e9fa4757..6f061a9408 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -176,35 +176,10 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { MP_DEFINE_CONST_MAP(mp_builtin_module_map, mp_builtin_module_table); -// Tries to find a loaded module, otherwise attempts to load a builtin, otherwise MP_OBJ_NULL. -mp_obj_t mp_module_get_loaded_or_builtin(qstr module_name) { - // First try loaded modules. - mp_map_elem_t *elem = mp_map_lookup(&MP_STATE_VM(mp_loaded_modules_dict).map, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP); - - if (!elem) { - #if MICROPY_MODULE_WEAK_LINKS - return mp_module_get_builtin(module_name); - #else - // Otherwise try builtin. - elem = mp_map_lookup((mp_map_t *)&mp_builtin_module_map, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP); - if (!elem) { - return MP_OBJ_NULL; - } - - #if MICROPY_MODULE_BUILTIN_INIT - // If found, it's a newly loaded built-in, so init it. - mp_module_call_init(MP_OBJ_NEW_QSTR(module_name), elem->value); - #endif - #endif - } - - return elem->value; -} - -#if MICROPY_MODULE_WEAK_LINKS -// Tries to find a loaded module, otherwise attempts to load a builtin, otherwise MP_OBJ_NULL. +// Attempts to find (and initialise) a builtin, otherwise returns MP_OBJ_NULL. +// This must only be called after first checking the loaded modules, +// otherwise the module will be re-initialised. mp_obj_t mp_module_get_builtin(qstr module_name) { - // Try builtin. mp_map_elem_t *elem = mp_map_lookup((mp_map_t *)&mp_builtin_module_map, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP); if (!elem) { return MP_OBJ_NULL; @@ -217,7 +192,6 @@ mp_obj_t mp_module_get_builtin(qstr module_name) { return elem->value; } -#endif #if MICROPY_MODULE_BUILTIN_INIT STATIC void mp_module_register(mp_obj_t module_name, mp_obj_t module) { |