aboutsummaryrefslogtreecommitdiff
path: root/lib/utils
diff options
context:
space:
mode:
authorDamien George2016-10-17 13:14:59 +1100
committerDamien George2016-10-17 13:14:59 +1100
commitad3724e0bc87305f9280f65226066a199042d736 (patch)
tree16de7f66f999c0fda8dc093be4b9c9f989f35488 /lib/utils
parent7d0d7215d2575a2d36d34c9a13b58cade0610a28 (diff)
lib/utils/pyexec: Allow behaviour of SystemExit to be configurable.
Setting the pyexec_system_exit variable to PYEXEC_FORCED_EXT allows SystemExit exceptions to terminate the pyexec functions.
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/pyexec.c6
-rw-r--r--lib/utils/pyexec.h5
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/utils/pyexec.c b/lib/utils/pyexec.c
index 5824e1403..d7c257024 100644
--- a/lib/utils/pyexec.c
+++ b/lib/utils/pyexec.c
@@ -45,6 +45,7 @@
#include "genhdr/mpversion.h"
pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
+int pyexec_system_exit = 0;
STATIC bool repl_display_debugging_info = 0;
#define EXEC_FLAG_PRINT_EOF (1)
@@ -61,6 +62,9 @@ STATIC int parse_compile_execute(void *source, mp_parse_input_kind_t input_kind,
int ret = 0;
uint32_t start = 0;
+ // by default a SystemExit exception returns 0
+ pyexec_system_exit = 0;
+
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_obj_t module_fun;
@@ -99,7 +103,7 @@ STATIC int parse_compile_execute(void *source, mp_parse_input_kind_t input_kind,
// check for SystemExit
if (mp_obj_is_subclass_fast(mp_obj_get_type((mp_obj_t)nlr.ret_val), &mp_type_SystemExit)) {
// at the moment, the value of SystemExit is unused
- ret = 0;
+ ret = pyexec_system_exit;
} else {
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
ret = 0;
diff --git a/lib/utils/pyexec.h b/lib/utils/pyexec.h
index e0f62440e..ae69a195e 100644
--- a/lib/utils/pyexec.h
+++ b/lib/utils/pyexec.h
@@ -33,6 +33,11 @@ typedef enum {
extern pyexec_mode_kind_t pyexec_mode_kind;
+// Set this to the value (eg PYEXEC_FORCED_EXIT) that will be propagated through
+// the pyexec functions if a SystemExit exception is raised by the running code.
+// It will reset to 0 at the start of each execution (eg each REPL entry).
+extern int pyexec_system_exit;
+
#define PYEXEC_FORCED_EXIT (0x100)
#define PYEXEC_SWITCH_MODE (0x200)