remove legacy sys.atexit() implementation

This commit is contained in:
microDev 2021-07-30 10:00:00 +05:30
parent a3998d0626
commit 4938851122
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
9 changed files with 4 additions and 67 deletions

View File

@ -690,13 +690,6 @@ MP_NOINLINE int main_(int argc, char **argv) {
MP_STATE_THREAD(prof_trace_callback) = MP_OBJ_NULL; MP_STATE_THREAD(prof_trace_callback) = MP_OBJ_NULL;
#endif #endif
#if MICROPY_PY_SYS_ATEXIT
// Beware, the sys.settrace callback should be disabled before running sys.atexit.
if (mp_obj_is_callable(MP_STATE_VM(sys_exitfunc))) {
mp_call_function_0(MP_STATE_VM(sys_exitfunc));
}
#endif
#if MICROPY_PY_MICROPYTHON_MEM_INFO #if MICROPY_PY_MICROPYTHON_MEM_INFO
if (mp_verbose_flag) { if (mp_verbose_flag) {
mp_micropython_mem_info(0, NULL); mp_micropython_mem_info(0, NULL);

View File

@ -106,7 +106,6 @@
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1) #define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
#define MICROPY_PY_BUILTINS_SLICE_INDICES (1) #define MICROPY_PY_BUILTINS_SLICE_INDICES (1)
#define MICROPY_PY_SYS_EXIT (1) #define MICROPY_PY_SYS_EXIT (1)
#define MICROPY_PY_SYS_ATEXIT (1)
#if MICROPY_PY_SYS_SETTRACE #if MICROPY_PY_SYS_SETTRACE
#define MICROPY_PERSISTENT_CODE_SAVE (1) #define MICROPY_PERSISTENT_CODE_SAVE (1)
#define MICROPY_COMP_CONST (0) #define MICROPY_COMP_CONST (0)

View File

@ -166,16 +166,6 @@ STATIC mp_obj_t mp_sys_getsizeof(mp_obj_t obj) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_getsizeof_obj, mp_sys_getsizeof); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_getsizeof_obj, mp_sys_getsizeof);
#endif #endif
#if MICROPY_PY_SYS_ATEXIT
// atexit(callback): Callback is called when sys.exit is called.
STATIC mp_obj_t mp_sys_atexit(mp_obj_t obj) {
mp_obj_t old = MP_STATE_VM(sys_exitfunc);
MP_STATE_VM(sys_exitfunc) = obj;
return old;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_atexit_obj, mp_sys_atexit);
#endif
#if MICROPY_PY_SYS_SETTRACE #if MICROPY_PY_SYS_SETTRACE
// settrace(tracefunc): Set the systems trace function. // settrace(tracefunc): Set the systems trace function.
STATIC mp_obj_t mp_sys_settrace(mp_obj_t obj) { STATIC mp_obj_t mp_sys_settrace(mp_obj_t obj) {
@ -237,14 +227,6 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
#if MICROPY_PY_SYS_GETSIZEOF #if MICROPY_PY_SYS_GETSIZEOF
{ MP_ROM_QSTR(MP_QSTR_getsizeof), MP_ROM_PTR(&mp_sys_getsizeof_obj) }, { MP_ROM_QSTR(MP_QSTR_getsizeof), MP_ROM_PTR(&mp_sys_getsizeof_obj) },
#endif #endif
/*
* Extensions to CPython
*/
#if MICROPY_PY_SYS_ATEXIT
{ MP_ROM_QSTR(MP_QSTR_atexit), MP_ROM_PTR(&mp_sys_atexit_obj) },
#endif
}; };
STATIC MP_DEFINE_CONST_DICT(mp_module_sys_globals, mp_module_sys_globals_table); STATIC MP_DEFINE_CONST_DICT(mp_module_sys_globals, mp_module_sys_globals_table);

View File

@ -1311,11 +1311,6 @@ typedef double mp_float_t;
#define MICROPY_PY_SYS_EXIT (1) #define MICROPY_PY_SYS_EXIT (1)
#endif #endif
// Whether to provide "sys.atexit" function (MicroPython extension)
#ifndef MICROPY_PY_SYS_ATEXIT
#define MICROPY_PY_SYS_ATEXIT (0)
#endif
// Whether to provide "sys.settrace" function // Whether to provide "sys.settrace" function
#ifndef MICROPY_PY_SYS_SETTRACE #ifndef MICROPY_PY_SYS_SETTRACE
#define MICROPY_PY_SYS_SETTRACE (0) #define MICROPY_PY_SYS_SETTRACE (0)

View File

@ -157,11 +157,6 @@ typedef struct _mp_state_vm_t {
mp_obj_base_t *cur_exception; mp_obj_base_t *cur_exception;
#endif #endif
#if MICROPY_PY_SYS_ATEXIT
// exposed through sys.atexit function
mp_obj_t sys_exitfunc;
#endif
// dictionary for the __main__ module // dictionary for the __main__ module
mp_obj_dict_t dict_main; mp_obj_dict_t dict_main;

View File

@ -130,10 +130,6 @@ void mp_init(void) {
sizeof(MP_STATE_VM(fs_user_mount)) - MICROPY_FATFS_NUM_PERSISTENT); sizeof(MP_STATE_VM(fs_user_mount)) - MICROPY_FATFS_NUM_PERSISTENT);
#endif #endif
#if MICROPY_PY_SYS_ATEXIT
MP_STATE_VM(sys_exitfunc) = mp_const_none;
#endif
#if MICROPY_PY_SYS_SETTRACE #if MICROPY_PY_SYS_SETTRACE
MP_STATE_THREAD(prof_trace_callback) = MP_OBJ_NULL; MP_STATE_THREAD(prof_trace_callback) = MP_OBJ_NULL;
MP_STATE_THREAD(prof_callback_is_executing) = false; MP_STATE_THREAD(prof_callback_is_executing) = false;

View File

@ -1,21 +0,0 @@
# test sys.atexit() function
import sys
try:
sys.atexit
except AttributeError:
print("SKIP")
raise SystemExit
some_var = None
def do_at_exit():
print("done at exit:", some_var)
sys.atexit(do_at_exit)
some_var = "ok"
print("done before exit")

View File

@ -1,2 +0,0 @@
done before exit
done at exit: ok

View File

@ -41,10 +41,10 @@ ime
utime utimeq utime utimeq
argv atexit byteorder exc_info argv byteorder exc_info exit
exit getsizeof implementation maxsize getsizeof implementation maxsize modules
modules path platform stderr path platform stderr stdin
stdin stdout version version_info stdout version version_info
ementation ementation
# attrtuple # attrtuple
(start=1, stop=2, step=3) (start=1, stop=2, step=3)