summaryrefslogtreecommitdiff
path: root/unix/main.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-09-15 15:53:09 +0100
committerDamien George <damien.p.george@gmail.com>2014-09-15 15:53:09 +0100
commitb92cbe612913a7c9d066c34912a3f77fe6392b2b (patch)
treeea267ba0d0d13a2dd7c4ef9ccb4b039bd993d328 /unix/main.c
parent83695596ed4fe3ad990b68cc5ff52c26caf2174d (diff)
py: Move definition of mp_sys_exit to core.
sys.exit always raises SystemExit so doesn't need a special implementation for each port. If C exit() is really needed, use the standard os._exit function. Also initialise mp_sys_path and mp_sys_argv in teensy port.
Diffstat (limited to 'unix/main.c')
-rw-r--r--unix/main.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/unix/main.c b/unix/main.c
index 177c76b53..f00bf3d33 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -130,10 +130,11 @@ STATIC int execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind,
// check for SystemExit
mp_obj_t exc = (mp_obj_t)nlr.ret_val;
if (mp_obj_is_subclass_fast(mp_obj_get_type(exc), &mp_type_SystemExit)) {
+ // None is an exit value of 0; an int is its value; anything else is 1
mp_obj_t exit_val = mp_obj_exception_get_value(exc);
- mp_int_t val;
- if (!mp_obj_get_int_maybe(exit_val, &val)) {
- val = 0;
+ mp_int_t val = 0;
+ if (exit_val != mp_const_none && !mp_obj_get_int_maybe(exit_val, &val)) {
+ val = 1;
}
exit(val);
}
@@ -406,15 +407,6 @@ int main(int argc, char **argv) {
return ret;
}
-STATIC mp_obj_t mp_sys_exit(uint n_args, const mp_obj_t *args) {
- int rc = 0;
- if (n_args > 0) {
- rc = mp_obj_get_int(args[0]);
- }
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_SystemExit, mp_obj_new_int(rc)));
-}
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit);
-
uint mp_import_stat(const char *path) {
struct stat st;
if (stat(path, &st) == 0) {