summaryrefslogtreecommitdiffstatshomepage
path: root/py/objmodule.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-22 23:59:20 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-22 23:59:20 +0000
commit0d028743aa12ef935b27fdbaf0a5ad3ca62d7628 (patch)
treefef0f48e45badbc8bdab625721f314b01c77288d /py/objmodule.c
parentf64086f80f1493c7f5009e99f4bd1fba47332cd3 (diff)
downloadmicropython-0d028743aa12ef935b27fdbaf0a5ad3ca62d7628.tar.gz
micropython-0d028743aa12ef935b27fdbaf0a5ad3ca62d7628.zip
py: Initialise loaded_module map in rt_init.
STM port crashes without this re-init. There should not be any state in the core py/ code that relies on pre-initialised data.
Diffstat (limited to 'py/objmodule.c')
-rw-r--r--py/objmodule.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/py/objmodule.c b/py/objmodule.c
index 749d345bcf..f8a8d2620d 100644
--- a/py/objmodule.c
+++ b/py/objmodule.c
@@ -17,9 +17,6 @@ typedef struct _mp_obj_module_t {
mp_map_t *globals;
} mp_obj_module_t;
-// TODO: expose as sys.modules
-static mp_map_t *loaded_modules;
-
static void module_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
mp_obj_module_t *self = self_in;
print(env, "<module '%s' from '-unknown-file-'>", qstr_str(self->name));
@@ -49,10 +46,7 @@ const mp_obj_type_t module_type = {
};
mp_obj_t mp_obj_new_module(qstr module_name) {
- if (loaded_modules == NULL) {
- loaded_modules = mp_map_new(1);
- }
- mp_map_elem_t *el = mp_map_lookup(loaded_modules, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
+ mp_map_elem_t *el = mp_map_lookup(rt_loaded_modules_get(), MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND);
// We could error out if module already exists, but let C extensions
// add new members to existing modules.
if (el->value != MP_OBJ_NULL) {
@@ -69,7 +63,7 @@ mp_obj_t mp_obj_new_module(qstr module_name) {
}
mp_obj_t mp_obj_module_get(qstr module_name) {
- mp_map_elem_t *el = mp_map_lookup(loaded_modules, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP);
+ mp_map_elem_t *el = mp_map_lookup(rt_loaded_modules_get(), MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP);
if (el == NULL) {
return NULL;
}