summaryrefslogtreecommitdiff
path: root/py/objmodule.c
diff options
context:
space:
mode:
authorJeff Epler <jeff@adafruit.com>2020-03-05 14:28:46 -0600
committerGitHub <noreply@github.com>2020-03-05 14:28:46 -0600
commit4fa90261a37f0f729b52289cf54492ec7108e16b (patch)
tree6af84444989778e70b8d327d636d88df04c40304 /py/objmodule.c
parente81930fb9e9cc9df55e7fad7726dcedbf7dcdeff (diff)
parent274cb597b0cd2a12b82d6efe2c40fb76402f8644 (diff)
Merge pull request #2657 from tannewt/builtin_package
Support importing native modules in native packages.
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 c7b080300..7405a6919 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) {