From 8dbbbbc793554f920cf352b0e67da46abe3974cf Mon Sep 17 00:00:00 2001
From: Damien George <damien.p.george@gmail.com>
Date: Mon, 4 Aug 2014 10:05:16 +0100
Subject: [PATCH] Put call to qstr_init and mp_init_emergency_exc_buf in
 mp_init.

qstr_init is always called exactly before mp_init, so makes sense to
just have mp_init call it.  Similarly with
mp_init_emergency_exception_buf.  Doing this makes the ports simpler and
less error prone (ie they can no longer forget to call these).
---
 bare-arm/main.c      |  1 -
 py/runtime.c         |  5 +++++
 qemu-arm/main.c      |  1 -
 qemu-arm/test_main.c |  1 -
 stmhal/main.c        | 21 ++++++++-------------
 teensy/main.c        |  2 +-
 unix-cpy/main.c      |  1 -
 unix/main.c          |  4 ----
 8 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/bare-arm/main.c b/bare-arm/main.c
index bdaded436..286e41cd4 100644
--- a/bare-arm/main.c
+++ b/bare-arm/main.c
@@ -53,7 +53,6 @@ void do_str(const char *src) {
 }
 
 int main(int argc, char **argv) {
-    qstr_init();
     mp_init();
     do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\n')");
     mp_deinit();
diff --git a/py/runtime.c b/py/runtime.c
index a478bb62f..59e47c7ff 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -70,8 +70,13 @@ const mp_obj_module_t mp_module___main__ = {
 };
 
 void mp_init(void) {
+    qstr_init();
     mp_stack_ctrl_init();
 
+#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
+    mp_init_emergency_exception_buf();
+#endif
+
     // call port specific initialization if any
 #ifdef MICROPY_PORT_INIT_FUNC
     MICROPY_PORT_INIT_FUNC;
diff --git a/qemu-arm/main.c b/qemu-arm/main.c
index 91c096289..7ba818f58 100644
--- a/qemu-arm/main.c
+++ b/qemu-arm/main.c
@@ -53,7 +53,6 @@ void do_str(const char *src) {
 }
 
 int main(int argc, char **argv) {
-    qstr_init();
     mp_init();
     do_str("print('hello world!')");
     mp_deinit();
diff --git a/qemu-arm/test_main.c b/qemu-arm/test_main.c
index 709bcf2f1..63f7e3f0c 100644
--- a/qemu-arm/test_main.c
+++ b/qemu-arm/test_main.c
@@ -59,7 +59,6 @@ end:
 
 int main() {
     const char a[] = {"sim"};
-    qstr_init();
     mp_init();
     int r = tinytest_main(1, (const char **) a, groups);
     mp_deinit();
diff --git a/stmhal/main.c b/stmhal/main.c
index 183f11b7a..442ff9934 100644
--- a/stmhal/main.c
+++ b/stmhal/main.c
@@ -310,9 +310,14 @@ soft_reset:
 
     // GC init
     gc_init(&_heap_start, &_heap_end);
-#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
-    mp_init_emergency_exception_buf();
-#endif
+
+    // Micro Python 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_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash));
+    mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash_slash_lib));
+    mp_obj_list_init(mp_sys_argv, 0);
 
     // Change #if 0 to #if 1 if you want REPL on UART_6 (or another uart)
     // as well as on USB VCP
@@ -328,17 +333,7 @@ soft_reset:
     pyb_stdio_uart = NULL;
 #endif
 
-    // Micro Python init
-    qstr_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_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash));
-    mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash_slash_lib));
-    mp_obj_list_init(mp_sys_argv, 0);
-
     readline_init();
-
     pin_init();
     extint_init();
 
diff --git a/teensy/main.c b/teensy/main.c
index a5b2d5b52..e00c3ff30 100644
--- a/teensy/main.c
+++ b/teensy/main.c
@@ -267,7 +267,7 @@ soft_reset:
     // GC init
     gc_init(&_heap_start, (void*)HEAP_END);
 
-    qstr_init();
+    // Micro Python init
     mp_init();
 
     readline_init();
diff --git a/unix-cpy/main.c b/unix-cpy/main.c
index 4a04aa4e8..ac142f50f 100644
--- a/unix-cpy/main.c
+++ b/unix-cpy/main.c
@@ -87,7 +87,6 @@ void do_file(const char *file) {
 }
 
 int main(int argc, char **argv) {
-    qstr_init();
     mp_init();
 
     if (argc == 2) {
diff --git a/unix/main.c b/unix/main.c
index 936d7a13a..9f9f07c25 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -278,11 +278,7 @@ int main(int argc, char **argv) {
     char *heap = malloc(heap_size);
     gc_init(heap, heap + heap_size);
 #endif
-#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
-    mp_init_emergency_exception_buf();
-#endif
 
-    qstr_init();
     mp_init();
 
     char *home = getenv("HOME");
-- 
GitLab