Skip to content

Commit d99e908

Browse files
committed
modsys, unix: Add sys.exit(), should be implemented by a port.
1 parent d80e247 commit d99e908

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

py/modsys.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#if MICROPY_ENABLE_MOD_SYS
3838

39+
MP_DECLARE_CONST_FUN_OBJ(mp_sys_exit_obj);
40+
3941
// These should be implemented by ports, specific types don't matter,
4042
// only addresses.
4143
struct _dummy_t;
@@ -53,6 +55,9 @@ STATIC const MP_DEFINE_STR_OBJ(version_obj, "3.4.0");
5355

5456
STATIC const mp_map_elem_t mp_module_sys_globals_table[] = {
5557
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_sys) },
58+
// Should be implemented by port
59+
{ MP_OBJ_NEW_QSTR(MP_QSTR_exit), (mp_obj_t)&mp_sys_exit_obj },
60+
5661
{ MP_OBJ_NEW_QSTR(MP_QSTR_path), (mp_obj_t)&mp_sys_path_obj },
5762
{ MP_OBJ_NEW_QSTR(MP_QSTR_argv), (mp_obj_t)&mp_sys_argv_obj },
5863
{ MP_OBJ_NEW_QSTR(MP_QSTR_version), (mp_obj_t)&version_obj },

py/qstrdefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ Q(utf-8)
329329
Q(argv)
330330
Q(byteorder)
331331
Q(big)
332+
Q(exit)
332333
Q(little)
333334
Q(stdin)
334335
Q(stdout)

unix/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,15 @@ int main(int argc, char **argv) {
371371
return 0;
372372
}
373373

374+
STATIC mp_obj_t mp_sys_exit(uint n_args, const mp_obj_t *args) {
375+
int rc = 0;
376+
if (n_args > 0) {
377+
rc = mp_obj_get_int(args[0]);
378+
}
379+
exit(rc);
380+
}
381+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit);
382+
374383
uint mp_import_stat(const char *path) {
375384
struct stat st;
376385
if (stat(path, &st) == 0) {

0 commit comments

Comments
 (0)