diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2017-09-05 19:01:17 -0700 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2017-09-05 22:01:17 -0400 |
| commit | 6baacf46b746b897cc8fea0f32df4379370b2c04 (patch) | |
| tree | 11493160b03af33caf2a374e89eacca65af16f97 | |
| parent | f9c54665f7d53477c1b90edc8722ec3b6c30572d (diff) | |
py: Only load frozen modules when the filename has the prefix. (#235)
* py: Only load frozen modules when the filename has the prefix.
This allows one to override a built-in module by loading a newer
version onto the file system.
* Unbreak mpys
| -rw-r--r-- | py/builtinimport.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c index 3edf10512..5894309ff 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -190,30 +190,37 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) { char *file_str = vstr_null_terminated_str(file); #endif - // If we support frozen modules (either as str or mpy) then try to find the - // requested filename in the list of frozen module filenames. - #if MICROPY_MODULE_FROZEN - void *modref; - int frozen_type = mp_find_frozen_module(file_str, file->len, &modref); - #endif + #if MICROPY_MODULE_FROZEN || MICROPY_MODULE_FROZEN_MPY + if (strncmp(MP_FROZEN_FAKE_DIR_SLASH, + file_str, + MP_FROZEN_FAKE_DIR_SLASH_LENGTH) == 0) { + // If we support frozen modules (either as str or mpy) then try to find the + // requested filename in the list of frozen module filenames. + #if MICROPY_MODULE_FROZEN + void *modref; + int frozen_type = mp_find_frozen_module(file_str + MP_FROZEN_FAKE_DIR_SLASH_LENGTH, file->len - MP_FROZEN_FAKE_DIR_SLASH_LENGTH, &modref); + #endif - // If we support frozen str modules and the compiler is enabled, and we - // found the filename in the list of frozen files, then load and execute it. - #if MICROPY_MODULE_FROZEN_STR - if (frozen_type == MP_FROZEN_STR) { - do_load_from_lexer(module_obj, modref); - return; - } - #endif + // If we support frozen str modules and the compiler is enabled, and we + // found the filename in the list of frozen files, then load and execute it. + #if MICROPY_MODULE_FROZEN_STR + if (frozen_type == MP_FROZEN_STR) { + do_load_from_lexer(module_obj, modref); + return; + } + #endif + + // If we support frozen mpy modules and we found a corresponding file (and + // its data) in the list of frozen files, execute it. + #if MICROPY_MODULE_FROZEN_MPY + if (frozen_type == MP_FROZEN_MPY) { + do_execute_raw_code(module_obj, modref); + return; + } + #endif - // If we support frozen mpy modules and we found a corresponding file (and - // its data) in the list of frozen files, execute it. - #if MICROPY_MODULE_FROZEN_MPY - if (frozen_type == MP_FROZEN_MPY) { - do_execute_raw_code(module_obj, modref); - return; } - #endif + #endif // MICROPY_MODULE_FROZEN || MICROPY_MODULE_FROZEN_MPY // If we support loading .mpy files then check if the file extension is of // the correct format and, if so, load and execute the file. |
