summaryrefslogtreecommitdiff
path: root/py/objmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/objmodule.c')
-rw-r--r--py/objmodule.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/py/objmodule.c b/py/objmodule.c
index 5ee2f7dc8..8c26cc55a 100644
--- a/py/objmodule.c
+++ b/py/objmodule.c
@@ -152,11 +152,13 @@ static const mp_rom_map_elem_t mp_builtin_module_table[] = {
};
MP_DEFINE_CONST_MAP(mp_builtin_module_map, mp_builtin_module_table);
+#if MICROPY_HAVE_REGISTERED_EXTENSIBLE_MODULES
static const mp_rom_map_elem_t mp_builtin_extensible_module_table[] = {
// built-in modules declared with MP_REGISTER_EXTENSIBLE_MODULE()
MICROPY_REGISTERED_EXTENSIBLE_MODULES
};
MP_DEFINE_CONST_MAP(mp_builtin_extensible_module_map, mp_builtin_extensible_module_table);
+#endif
#if MICROPY_MODULE_ATTR_DELEGATION && defined(MICROPY_MODULE_DELEGATIONS)
typedef struct _mp_module_delegation_entry_t {
@@ -173,7 +175,13 @@ static const mp_module_delegation_entry_t mp_builtin_module_delegation_table[] =
// Attempts to find (and initialise) a built-in, otherwise returns
// MP_OBJ_NULL.
mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) {
- mp_map_elem_t *elem = mp_map_lookup((mp_map_t *)(extensible ? &mp_builtin_extensible_module_map : &mp_builtin_module_map), MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP);
+ #if MICROPY_HAVE_REGISTERED_EXTENSIBLE_MODULES
+ const mp_map_t *map = extensible ? &mp_builtin_extensible_module_map : &mp_builtin_module_map;
+ #else
+ const mp_map_t *map = &mp_builtin_module_map;
+ #endif
+ mp_map_elem_t *elem = mp_map_lookup((mp_map_t *)map, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP);
+
if (!elem) {
#if MICROPY_PY_SYS
// Special case for sys, which isn't extensible but can always be
@@ -183,6 +191,7 @@ mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) {
}
#endif
+ #if MICROPY_HAVE_REGISTERED_EXTENSIBLE_MODULES
if (extensible) {
// At this point we've already tried non-extensible built-ins, the
// filesystem, and now extensible built-ins. No match, so fail
@@ -204,6 +213,8 @@ mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) {
return MP_OBJ_NULL;
}
elem = mp_map_lookup((mp_map_t *)&mp_builtin_extensible_module_map, MP_OBJ_NEW_QSTR(qstr_from_strn(module_name_str + 1, module_name_len - 1)), MP_MAP_LOOKUP);
+ #endif
+
if (!elem) {
return MP_OBJ_NULL;
}