summaryrefslogtreecommitdiff
path: root/py/objmodule.c
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-02-25 12:13:08 -0800
committerScott Shawcroft <scott@tannewt.org>2020-02-25 15:32:55 -0800
commit86fd93bd03d937713d4d23fa38ab359034c503c2 (patch)
treee0e2c873e39ae788bec6afae62aa5ea6f1548c29 /py/objmodule.c
parent7037ebe0ecdbaedd108d284fb44492d56f2d0c50 (diff)
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.
Diffstat (limited to 'py/objmodule.c')
-rw-r--r--py/objmodule.c7
1 files changed, 7 insertions, 0 deletions
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) {