py/runtime: Allow initialising sys.path/argv with defaults.
If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is enabled (which it is by default) then sys.path and sys.argv will be initialised and populated with default values. This keeps all bare-metal ports aligned. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
86394f70fc
commit
de43b500bd
|
@ -53,8 +53,6 @@ The basic MicroPython firmware is implemented in the main port file, e.g ``main.
|
||||||
mp_stack_ctrl_init();
|
mp_stack_ctrl_init();
|
||||||
gc_init(heap, heap + sizeof(heap));
|
gc_init(heap, heap + sizeof(heap));
|
||||||
mp_init();
|
mp_init();
|
||||||
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_path), 0);
|
|
||||||
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), 0);
|
|
||||||
|
|
||||||
// Start a normal REPL; will exit when ctrl-D is entered on a blank line.
|
// Start a normal REPL; will exit when ctrl-D is entered on a blank line.
|
||||||
pyexec_friendly_repl();
|
pyexec_friendly_repl();
|
||||||
|
|
|
@ -192,8 +192,6 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
set_fmode_binary();
|
set_fmode_binary();
|
||||||
#endif
|
#endif
|
||||||
mp_obj_list_init(mp_sys_path, 0);
|
|
||||||
mp_obj_list_init(mp_sys_argv, 0);
|
|
||||||
|
|
||||||
#if MICROPY_EMIT_NATIVE
|
#if MICROPY_EMIT_NATIVE
|
||||||
// Set default emitter options
|
// Set default emitter options
|
||||||
|
|
|
@ -139,9 +139,6 @@ soft_reset:
|
||||||
|
|
||||||
// MicroPython init
|
// MicroPython init
|
||||||
mp_init();
|
mp_init();
|
||||||
mp_obj_list_init(mp_sys_path, 0);
|
|
||||||
mp_obj_list_init(mp_sys_argv, 0);
|
|
||||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
|
|
||||||
|
|
||||||
// execute all basic initializations
|
// execute all basic initializations
|
||||||
mp_irq_init0();
|
mp_irq_init0();
|
||||||
|
|
|
@ -140,13 +140,7 @@ soft_reset:
|
||||||
mp_stack_set_limit(MP_TASK_STACK_SIZE - MP_TASK_STACK_LIMIT_MARGIN);
|
mp_stack_set_limit(MP_TASK_STACK_SIZE - MP_TASK_STACK_LIMIT_MARGIN);
|
||||||
gc_init(mp_task_heap, mp_task_heap + mp_task_heap_size);
|
gc_init(mp_task_heap, mp_task_heap + mp_task_heap_size);
|
||||||
mp_init();
|
mp_init();
|
||||||
mp_obj_list_init(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_));
|
|
||||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
|
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
|
||||||
mp_obj_list_init(mp_sys_argv, 0);
|
|
||||||
readline_init0();
|
readline_init0();
|
||||||
|
|
||||||
// initialise peripherals
|
// initialise peripherals
|
||||||
|
|
|
@ -52,14 +52,8 @@ STATIC void mp_reset(void) {
|
||||||
mp_hal_init();
|
mp_hal_init();
|
||||||
gc_init(heap, heap + sizeof(heap));
|
gc_init(heap, heap + sizeof(heap));
|
||||||
mp_init();
|
mp_init();
|
||||||
mp_obj_list_init(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_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
|
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
|
||||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_));
|
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_));
|
||||||
mp_obj_list_init(mp_sys_argv, 0);
|
|
||||||
#if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA
|
#if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA
|
||||||
extern void esp_native_code_init(void);
|
extern void esp_native_code_init(void);
|
||||||
esp_native_code_init();
|
esp_native_code_init();
|
||||||
|
|
|
@ -91,10 +91,6 @@ void mp_js_init(int heap_size) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mp_init();
|
mp_init();
|
||||||
|
|
||||||
mp_obj_list_init(mp_sys_path, 0);
|
|
||||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_));
|
|
||||||
mp_obj_list_init(mp_sys_argv, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_js_init_repl() {
|
void mp_js_init_repl() {
|
||||||
|
|
|
@ -75,12 +75,6 @@ int main(void) {
|
||||||
gc_init(&_gc_heap_start, &_gc_heap_end);
|
gc_init(&_gc_heap_start, &_gc_heap_end);
|
||||||
mp_init();
|
mp_init();
|
||||||
|
|
||||||
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_));
|
|
||||||
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), 0);
|
|
||||||
#if MICROPY_PY_NETWORK
|
#if MICROPY_PY_NETWORK
|
||||||
mod_network_init();
|
mod_network_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -129,16 +129,8 @@ soft_reset:
|
||||||
gc_init(&_heap_start, &_heap_end);
|
gc_init(&_heap_start, &_heap_end);
|
||||||
|
|
||||||
mp_init();
|
mp_init();
|
||||||
mp_obj_list_init(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_sys_argv, 0);
|
|
||||||
|
|
||||||
readline_init0();
|
readline_init0();
|
||||||
|
|
||||||
|
|
||||||
#if MICROPY_PY_MACHINE_HW_SPI
|
#if MICROPY_PY_MACHINE_HW_SPI
|
||||||
spi_init0();
|
spi_init0();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -100,13 +100,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
// Initialise MicroPython runtime.
|
// Initialise MicroPython runtime.
|
||||||
mp_init();
|
mp_init();
|
||||||
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_));
|
|
||||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
|
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
|
||||||
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), 0);
|
|
||||||
|
|
||||||
// Initialise sub-systems.
|
// Initialise sub-systems.
|
||||||
readline_init0();
|
readline_init0();
|
||||||
|
|
|
@ -41,9 +41,6 @@ void samd_main(void) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
gc_init(&_sheap, &_eheap);
|
gc_init(&_sheap, &_eheap);
|
||||||
mp_init();
|
mp_init();
|
||||||
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_path), 0);
|
|
||||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_));
|
|
||||||
mp_obj_list_init(MP_OBJ_TO_PTR(mp_sys_argv), 0);
|
|
||||||
|
|
||||||
// Execute _boot.py to set up the filesystem.
|
// Execute _boot.py to set up the filesystem.
|
||||||
pyexec_frozen_module("_boot.py");
|
pyexec_frozen_module("_boot.py");
|
||||||
|
|
|
@ -494,12 +494,6 @@ soft_reset:
|
||||||
|
|
||||||
// MicroPython init
|
// MicroPython init
|
||||||
mp_init();
|
mp_init();
|
||||||
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);
|
|
||||||
|
|
||||||
// Initialise low-level sub-systems. Here we need to very basic things like
|
// Initialise low-level sub-systems. Here we need to very basic things like
|
||||||
// zeroing out memory and resetting any of the sub-systems. Following this
|
// zeroing out memory and resetting any of the sub-systems. Following this
|
||||||
|
|
|
@ -269,9 +269,6 @@ soft_reset:
|
||||||
|
|
||||||
// MicroPython init
|
// MicroPython init
|
||||||
mp_init();
|
mp_init();
|
||||||
mp_obj_list_init(mp_sys_path, 0);
|
|
||||||
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_sys_argv, 0);
|
|
||||||
|
|
||||||
readline_init0();
|
readline_init0();
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,7 @@
|
||||||
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
|
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
|
||||||
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
|
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
|
||||||
#define MICROPY_PY_BUILTINS_SLICE_INDICES (1)
|
#define MICROPY_PY_BUILTINS_SLICE_INDICES (1)
|
||||||
|
#define MICROPY_PY_SYS_PATH_ARGV_DEFAULTS (0)
|
||||||
#define MICROPY_PY_SYS_EXIT (1)
|
#define MICROPY_PY_SYS_EXIT (1)
|
||||||
#define MICROPY_PY_SYS_ATEXIT (1)
|
#define MICROPY_PY_SYS_ATEXIT (1)
|
||||||
#if MICROPY_PY_SYS_SETTRACE
|
#if MICROPY_PY_SYS_SETTRACE
|
||||||
|
|
|
@ -85,6 +85,7 @@
|
||||||
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
|
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
|
||||||
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
|
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
|
||||||
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
|
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
|
||||||
|
#define MICROPY_PY_SYS_PATH_ARGV_DEFAULTS (0)
|
||||||
#define MICROPY_PY_SYS_EXIT (1)
|
#define MICROPY_PY_SYS_EXIT (1)
|
||||||
#define MICROPY_PY_SYS_ATEXIT (1)
|
#define MICROPY_PY_SYS_ATEXIT (1)
|
||||||
#define MICROPY_PY_SYS_PLATFORM "win32"
|
#define MICROPY_PY_SYS_PLATFORM "win32"
|
||||||
|
|
|
@ -139,9 +139,6 @@ soft_reset:
|
||||||
gc_init(heap, heap + sizeof(heap));
|
gc_init(heap, heap + sizeof(heap));
|
||||||
#endif
|
#endif
|
||||||
mp_init();
|
mp_init();
|
||||||
mp_obj_list_init(mp_sys_path, 0);
|
|
||||||
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_sys_argv, 0);
|
|
||||||
|
|
||||||
#ifdef CONFIG_USB
|
#ifdef CONFIG_USB
|
||||||
usb_enable(NULL);
|
usb_enable(NULL);
|
||||||
|
|
|
@ -1306,6 +1306,11 @@ typedef double mp_float_t;
|
||||||
#define MICROPY_PY_SYS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
|
#define MICROPY_PY_SYS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
|
||||||
#endif
|
#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
|
// Whether to provide "sys.maxsize" constant
|
||||||
#ifndef MICROPY_PY_SYS_MAXSIZE
|
#ifndef MICROPY_PY_SYS_MAXSIZE
|
||||||
#define MICROPY_PY_SYS_MAXSIZE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
|
#define MICROPY_PY_SYS_MAXSIZE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
|
||||||
|
|
|
@ -153,7 +153,8 @@ typedef struct _mp_state_vm_t {
|
||||||
// dictionary for the __main__ module
|
// dictionary for the __main__ module
|
||||||
mp_obj_dict_t dict_main;
|
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_path_obj;
|
||||||
mp_obj_list_t mp_sys_argv_obj;
|
mp_obj_list_t mp_sys_argv_obj;
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,15 @@ void mp_init(void) {
|
||||||
MP_STATE_VM(vfs_mount_table) = NULL;
|
MP_STATE_VM(vfs_mount_table) = NULL;
|
||||||
#endif
|
#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
|
#if MICROPY_PY_SYS_ATEXIT
|
||||||
MP_STATE_VM(sys_exitfunc) = mp_const_none;
|
MP_STATE_VM(sys_exitfunc) = mp_const_none;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue