8000 py: Only load frozen modules when the filename has the prefix. by tannewt · Pull Request #235 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

py: Only load frozen modules when the filename has the prefix. 8000 #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 6, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
tannewt committed Sep 5, 2017
commit b3971550b5bc906a497f596c7e5f9c46b6e34906
66 changes: 36 additions & 30 deletions py/builtinimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,40 +190,46 @@ 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_PERSISTENT_CODE_LOAD
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);
Copy link
Collaborator
@dhalbert dhalbert Sep 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the checking for ".frozen/" here now means the checking for ".frozen/" in mp_find_frozen_module() is no longer needed. But we can just leave it in. Basically you hoisted that check up to where it was really needed.

This and pyexec_frozen_module() are the only calls to mp_find_frozen_module().

#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

// 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.
#if MICROPY_PERSISTENT_CODE_LOAD
if (file_str[file->len - 3] == 'm') {
mp_raw_code_t *raw_code = mp_raw_code_load_file(file_str);
do_execute_raw_code(module_obj, raw_code);
return;
// 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.
#if MICROPY_PERSISTENT_CODE_LOAD
if (file_str[file->len - 3] == 'm') {
mp_raw_code_t *raw_code = mp_raw_code_load_file(file_str + MP_FROZEN_FAKE_DIR_SLASH_LENGTH);
do_execute_raw_code(module_obj, raw_code);
return;
}
#endif
}
#endif
#endif // MICROPY_MODULE_FROZEN || MICROPY_PERSISTENT_CODE_LOAD

// If we can compile scripts then load the file and compile and execute it.
#if MICROPY_ENABLE_COMPILER
Expand Down
0