summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/develop/porting.rst2
-rw-r--r--mpy-cross/main.c2
-rw-r--r--ports/cc3200/mptask.c3
-rw-r--r--ports/esp32/main.c6
-rw-r--r--ports/esp8266/main.c6
-rw-r--r--ports/javascript/main.c4
-rw-r--r--ports/mimxrt/main.c6
-rw-r--r--ports/nrf/main.c8
-rw-r--r--ports/rp2/main.c6
-rw-r--r--ports/samd/main.c3
-rw-r--r--ports/stm32/main.c6
-rw-r--r--ports/teensy/main.c3
-rw-r--r--ports/unix/mpconfigport.h1
-rw-r--r--ports/windows/mpconfigport.h1
-rw-r--r--ports/zephyr/main.c3
-rw-r--r--py/mpconfig.h5
-rw-r--r--py/mpstate.h3
-rw-r--r--py/runtime.c9
18 files changed, 18 insertions, 59 deletions
diff --git a/docs/develop/porting.rst b/docs/develop/porting.rst
index 549227d76..ae0cfd8b0 100644
--- a/docs/develop/porting.rst
+++ b/docs/develop/porting.rst
@@ -53,8 +53,6 @@ The basic MicroPython firmware is implemented in the main port file, e.g ``main.
mp_stack_ctrl_init();
gc_init(heap, heap + sizeof(heap));
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.
pyexec_friendly_repl();
diff --git a/mpy-cross/main.c b/mpy-cross/main.c
index c677929c3..7218921b3 100644
--- a/mpy-cross/main.c
+++ b/mpy-cross/main.c
@@ -192,8 +192,6 @@ MP_NOINLINE int main_(int argc, char **argv) {
#ifdef _WIN32
set_fmode_binary();
#endif
- mp_obj_list_init(mp_sys_path, 0);
- mp_obj_list_init(mp_sys_argv, 0);
#if MICROPY_EMIT_NATIVE
// Set default emitter options
diff --git a/ports/cc3200/mptask.c b/ports/cc3200/mptask.c
index 599211bdf..81f00e538 100644
--- a/ports/cc3200/mptask.c
+++ b/ports/cc3200/mptask.c
@@ -139,9 +139,6 @@ soft_reset:
// MicroPython 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
mp_irq_init0();
diff --git a/ports/esp32/main.c b/ports/esp32/main.c
index e95930ed0..c9b033d62 100644
--- a/ports/esp32/main.c
+++ b/ports/esp32/main.c
@@ -140,13 +140,7 @@ soft_reset:
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);
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_init(mp_sys_argv, 0);
readline_init0();
// initialise peripherals
diff --git a/ports/esp8266/main.c b/ports/esp8266/main.c
index 14863a35b..5d7debced 100644
--- a/ports/esp8266/main.c
+++ b/ports/esp8266/main.c
@@ -52,14 +52,8 @@ STATIC void mp_reset(void) {
mp_hal_init();
gc_init(heap, heap + sizeof(heap));
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_));
- mp_obj_list_init(mp_sys_argv, 0);
#if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA
extern void esp_native_code_init(void);
esp_native_code_init();
diff --git a/ports/javascript/main.c b/ports/javascript/main.c
index 7a04b8eea..04a853f66 100644
--- a/ports/javascript/main.c
+++ b/ports/javascript/main.c
@@ -91,10 +91,6 @@ void mp_js_init(int heap_size) {
#endif
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() {
diff --git a/ports/mimxrt/main.c b/ports/mimxrt/main.c
index 28ee30d99..a6a0d2e19 100644
--- a/ports/mimxrt/main.c
+++ b/ports/mimxrt/main.c
@@ -75,12 +75,6 @@ int main(void) {
gc_init(&_gc_heap_start, &_gc_heap_end);
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
mod_network_init();
#endif
diff --git a/ports/nrf/main.c b/ports/nrf/main.c
index fc67bd657..2ec16194c 100644
--- a/ports/nrf/main.c
+++ b/ports/nrf/main.c
@@ -129,16 +129,8 @@ soft_reset:
gc_init(&_heap_start, &_heap_end);
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();
-
#if MICROPY_PY_MACHINE_HW_SPI
spi_init0();
#endif
diff --git a/ports/rp2/main.c b/ports/rp2/main.c
index 6a5bb8867..84f23af23 100644
--- a/ports/rp2/main.c
+++ b/ports/rp2/main.c
@@ -100,13 +100,7 @@ int main(int argc, char **argv) {
// Initialise MicroPython runtime.
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_init(MP_OBJ_TO_PTR(mp_sys_argv), 0);
// Initialise sub-systems.
readline_init0();
diff --git a/ports/samd/main.c b/ports/samd/main.c
index a08e66fda..63fe4013a 100644
--- a/ports/samd/main.c
+++ b/ports/samd/main.c
@@ -41,9 +41,6 @@ void samd_main(void) {
for (;;) {
gc_init(&_sheap, &_eheap);
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.
pyexec_frozen_module("_boot.py");
diff --git a/ports/stm32/main.c b/ports/stm32/main.c
index 51459682f..431fa20de 100644
--- a/ports/stm32/main.c
+++ b/ports/stm32/main.c
@@ -494,12 +494,6 @@ soft_reset:
// MicroPython 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
// zeroing out memory and resetting any of the sub-systems. Following this
diff --git a/ports/teensy/main.c b/ports/teensy/main.c
index 6ebdcde21..37a04c74f 100644
--- a/ports/teensy/main.c
+++ b/ports/teensy/main.c
@@ -269,9 +269,6 @@ soft_reset:
// MicroPython 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();
diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h
index 68d4d8d33..a995ac52c 100644
--- a/ports/unix/mpconfigport.h
+++ b/ports/unix/mpconfigport.h
@@ -110,6 +110,7 @@
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (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_ATEXIT (1)
#if MICROPY_PY_SYS_SETTRACE
diff --git a/ports/windows/mpconfigport.h b/ports/windows/mpconfigport.h
index 69193cb6a..30d8e09e6 100644
--- a/ports/windows/mpconfigport.h
+++ b/ports/windows/mpconfigport.h
@@ -85,6 +85,7 @@
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (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_ATEXIT (1)
#define MICROPY_PY_SYS_PLATFORM "win32"
diff --git a/ports/zephyr/main.c b/ports/zephyr/main.c
index 63190bd5e..f97276834 100644
--- a/ports/zephyr/main.c
+++ b/ports/zephyr/main.c
@@ -139,9 +139,6 @@ soft_reset:
gc_init(heap, heap + sizeof(heap));
#endif
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
usb_enable(NULL);
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