From 86fd93bd03d937713d4d23fa38ab359034c503c2 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 25 Feb 2020 12:13:08 -0800 Subject: Support importing native modules in native packages. This only fixes the `import` portion. It doesn't actually change reference behavior because modules within a package could already be referenced through the parent package even though an error should have been thrown. --- py/objmodule.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'py/objmodule.c') diff --git a/py/objmodule.c b/py/objmodule.c index 627ba79e8..c8b3a67a2 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -69,6 +69,13 @@ STATIC void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { // delete/store attribute mp_obj_dict_t *dict = self->globals; if (dict->map.is_fixed) { + mp_map_elem_t *elem = mp_map_lookup(&dict->map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP); + // Return success if the given value is already in the dictionary. This is the case for + // native packages with native submodules. + if (elem != NULL && elem->value == dest[1]) { + dest[0] = MP_OBJ_NULL; // indicate success + return; + } else #if MICROPY_CAN_OVERRIDE_BUILTINS if (dict == &mp_module_builtins_globals) { if (MP_STATE_VM(mp_module_builtins_override_dict) == NULL) { -- cgit v1.2.3