diff options
Diffstat (limited to 'py')
| -rw-r--r-- | py/mpconfig.h | 5 | ||||
| -rw-r--r-- | py/mpstate.h | 3 | ||||
| -rw-r--r-- | py/runtime.c | 9 |
3 files changed, 16 insertions, 1 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h index 86e3e0f34..f0d11961d 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1306,6 +1306,11 @@ typedef double mp_float_t; #define MICROPY_PY_SYS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES) #endif +// Whether to initialise "sys.path" and "sys.argv" to their defaults in mp_init() +#ifndef MICROPY_PY_SYS_PATH_ARGV_DEFAULTS +#define MICROPY_PY_SYS_PATH_ARGV_DEFAULTS (1) +#endif + // Whether to provide "sys.maxsize" constant #ifndef MICROPY_PY_SYS_MAXSIZE #define MICROPY_PY_SYS_MAXSIZE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) diff --git a/py/mpstate.h b/py/mpstate.h index 69360738c..69fee0654 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -153,7 +153,8 @@ typedef struct _mp_state_vm_t { // dictionary for the __main__ module mp_obj_dict_t dict_main; - // these two lists must be initialised per port, after the call to mp_init + // If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is not enabled then these two lists + // must be initialised after the call to mp_init. mp_obj_list_t mp_sys_path_obj; mp_obj_list_t mp_sys_argv_obj; diff --git a/py/runtime.c b/py/runtime.c index 0120b70d7..7607ffb19 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -122,6 +122,15 @@ void mp_init(void) { MP_STATE_VM(vfs_mount_table) = NULL; #endif + #if MICROPY_PY_SYS_PATH_ARGV_DEFAULTS + mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_path), 0); + #if MICROPY_MODULE_FROZEN + mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen)); + #endif + mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script) + mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), 0); + #endif + #if MICROPY_PY_SYS_ATEXIT MP_STATE_VM(sys_exitfunc) = mp_const_none; #endif |
