Skip to content

Commit

Permalink
unix/main: Update handle_uncaught_exception for consistency with pyexec.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
pi-anl authored and andrewleech committed Nov 24, 2024
1 parent 597decc commit 733b1d4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ports/unix/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "extmod/modplatform.h"
#include "extmod/vfs.h"
#include "extmod/vfs_posix.h"
#include "shared/runtime/pyexec.h"
#include "genhdr/mpversion.h"
#include "input.h"

Expand Down Expand Up @@ -86,11 +87,10 @@ static void stderr_print_strn(void *env, const char *str, size_t len) {

const mp_print_t mp_stderr_print = {NULL, stderr_print_strn};

#define FORCED_EXIT (0x100)
// If exc is SystemExit, return value where FORCED_EXIT bit set,
// and lower 8 bits are SystemExit value. For all other exceptions,
// return 1.
static int handle_uncaught_exception(mp_obj_base_t *exc) {
int pyexec_handle_uncaught_exception(mp_obj_base_t *exc) {
// check for SystemExit
if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(exc->type), MP_OBJ_FROM_PTR(&mp_type_SystemExit))) {
// None is an exit value of 0; an int is its value; anything else is 1
Expand All @@ -99,7 +99,7 @@ static int handle_uncaught_exception(mp_obj_base_t *exc) {
if (exit_val != mp_const_none && !mp_obj_get_int_maybe(exit_val, &val)) {
val = 1;
}
return FORCED_EXIT | (val & 255);
return PYEXEC_FORCED_EXIT | (val & 255);
}

// Report all other exceptions
Expand Down Expand Up @@ -170,7 +170,7 @@ static int execute_from_lexer(int source_kind, const void *source, mp_parse_inpu
// uncaught exception
mp_hal_set_interrupt_char(-1);
mp_handle_pending(false);
return handle_uncaught_exception(nlr.ret_val);
return pyexec_handle_uncaught_exception(nlr.ret_val);
}
}

Expand Down Expand Up @@ -270,7 +270,7 @@ static int do_repl(void) {
mp_hal_stdio_mode_orig();

ret = execute_from_lexer(LEX_SRC_VSTR, &line, parse_input_kind, true);
if (ret & FORCED_EXIT) {
if (ret & PYEXEC_FORCED_EXIT) {
return ret;
}
}
Expand Down Expand Up @@ -298,7 +298,7 @@ static int do_repl(void) {

int ret = execute_from_lexer(LEX_SRC_STR, line, MP_PARSE_SINGLE_INPUT, true);
free(line);
if (ret & FORCED_EXIT) {
if (ret & PYEXEC_FORCED_EXIT) {
return ret;
}
}
Expand Down Expand Up @@ -676,7 +676,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
nlr_pop();
} else {
// uncaught exception
return handle_uncaught_exception(nlr.ret_val) & 0xff;
return pyexec_handle_uncaught_exception(nlr.ret_val) & 0xff;
}

// If this module is a package, see if it has a `__main__.py`.
Expand Down

0 comments on commit 733b1d4

Please sign in to comment.