Skip to content

Commit 8f81b5c

Browse files
committed
py: Put SystemExit in builtin namespace.
Also fix unix port so that SystemExit with no arg exits with value 0.
1 parent b63be37 commit 8f81b5c

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

py/builtintables.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ STATIC const mp_map_elem_t mp_builtin_object_table[] = {
138138
{ MP_OBJ_NEW_QSTR(MP_QSTR_StopIteration), (mp_obj_t)&mp_type_StopIteration },
139139
{ MP_OBJ_NEW_QSTR(MP_QSTR_SyntaxError), (mp_obj_t)&mp_type_SyntaxError },
140140
{ MP_OBJ_NEW_QSTR(MP_QSTR_SystemError), (mp_obj_t)&mp_type_SystemError },
141+
{ MP_OBJ_NEW_QSTR(MP_QSTR_SystemExit), (mp_obj_t)&mp_type_SystemExit },
141142
{ MP_OBJ_NEW_QSTR(MP_QSTR_TypeError), (mp_obj_t)&mp_type_TypeError },
142143
{ MP_OBJ_NEW_QSTR(MP_QSTR_ValueError), (mp_obj_t)&mp_type_ValueError },
143144
{ MP_OBJ_NEW_QSTR(MP_QSTR_ZeroDivisionError), (mp_obj_t)&mp_type_ZeroDivisionError },

unix/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ STATIC int execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind,
130130
// check for SystemExit
131131
mp_obj_t exc = (mp_obj_t)nlr.ret_val;
132132
if (mp_obj_is_subclass_fast(mp_obj_get_type(exc), &mp_type_SystemExit)) {
133-
exit(mp_obj_get_int(mp_obj_exception_get_value(exc)));
133+
mp_obj_t exit_val = mp_obj_exception_get_value(exc);
134+
mp_int_t val;
135+
if (!mp_obj_get_int_maybe(exit_val, &val)) {
136+
val = 0;
137+
}
138+
exit(val);
134139
}
135140
mp_obj_print_exception((mp_obj_t)nlr.ret_val);
136141
return 1;

0 commit comments

Comments
 (0)