aboutsummaryrefslogtreecommitdiff
path: root/py/builtinimport.c
diff options
context:
space:
mode:
authorSean Burton <Sean.Burton@thalesesecurity.com>2018-12-13 12:10:35 +0000
committerDamien George <damien.p.george@gmail.com>2019-01-27 11:08:25 +1100
commite33bc59712aa484107dc1cd4009dd8ab2da6dcb2 (patch)
tree5f15864a4926e76e8a4882f14d18b4835052d4bf /py/builtinimport.c
parent35687a87ec3fc28654933d7d37bfb82cb04f5227 (diff)
py: Remove calls to file reader functions when these are disabled.
If MICROPY_PERSISTENT_CODE_LOAD or MICROPY_ENABLE_COMPILER are enabled then code gets enabled that calls file reading functions which may be disabled if no readers have been implemented. To fix this, introduce a MICROPY_HAS_FILE_READER variable, which is automatically set if MICROPY_READER_POSIX or MICROPY_READER_VFS is set but can also be manually set if a custom reader is being implemented. Then disable the file reading calls if this is not set.
Diffstat (limited to 'py/builtinimport.c')
-rw-r--r--py/builtinimport.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c
index b8ed096ca..1a333b540 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -131,7 +131,7 @@ STATIC mp_import_stat_t find_file(const char *file_str, uint file_len, vstr_t *d
#endif
}
-#if MICROPY_ENABLE_COMPILER
+#if MICROPY_MODULE_FROZEN_STR || MICROPY_ENABLE_COMPILER
STATIC void do_load_from_lexer(mp_obj_t module_obj, mp_lexer_t *lex) {
#if MICROPY_PY___FILE__
qstr source_name = lex->source_name;
@@ -182,7 +182,7 @@ STATIC void do_execute_raw_code(mp_obj_t module_obj, mp_raw_code_t *raw_code) {
#endif
STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
- #if MICROPY_MODULE_FROZEN || MICROPY_PERSISTENT_CODE_LOAD || MICROPY_ENABLE_COMPILER
+ #if MICROPY_MODULE_FROZEN || MICROPY_ENABLE_COMPILER || (MICROPY_PERSISTENT_CODE_LOAD && MICROPY_HAS_FILE_READER)
char *file_str = vstr_null_terminated_str(file);
#endif
@@ -213,7 +213,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
// 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 MICROPY_HAS_FILE_READER && 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);
@@ -229,7 +229,6 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
return;
}
#else
-
// If we get here then the file was not frozen and we can't compile scripts.
mp_raise_msg(&mp_type_ImportError, "script compilation not supported");
#endif