File tree Expand file tree Collapse file tree 3 files changed +6
-4
lines changed Expand file tree Collapse file tree 3 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -15,4 +15,4 @@ Functions
15
15
16
16
.. function :: unregister(func)
17
17
18
- Remove func from the list of functions to be run at interpreter shutdown. Not enebled on all ports.
18
+ Remove func from the list of functions to be run at interpreter shutdown. Not enabled on all ports.
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ mp_obj_t mp_atexit_register(mp_obj_t function) {
39
39
mp_raise_ValueError (MP_ERROR_TEXT ("function not callable" ));
40
40
}
41
41
if (MP_STATE_VM (atexit_handlers ) == NULL ) {
42
- MP_STATE_VM (atexit_handlers ) = mp_obj_new_list (0 , NULL );
42
+ MP_STATE_VM (atexit_handlers ) = MP_OBJ_TO_PTR ( mp_obj_new_list (0 , NULL ) );
43
43
}
44
44
mp_obj_list_append (MP_OBJ_FROM_PTR (MP_STATE_VM (atexit_handlers )), function );
45
45
// return the passed in function so this can be used as a decorator
@@ -61,11 +61,13 @@ mp_obj_t mp_atexit_unregister(mp_obj_t function) {
61
61
static MP_DEFINE_CONST_FUN_OBJ_1 (mp_atexit_unregister_obj , mp_atexit_unregister ) ;
62
62
#endif
63
63
64
+ // port specific shutdown procedures should cLl this
65
+ // to run any registered atexit handlers.
64
66
int mp_atexit_execute (void ) {
65
67
int exit_code = 0 ;
66
68
if (MP_STATE_VM (atexit_handlers ) != NULL ) {
67
69
mp_obj_list_t * list = MP_STATE_VM (atexit_handlers );
68
- for (size_t i = 0 ; i < list -> len ; i ++ ) {
70
+ for (int i = list -> len - 1 ; i >= 0 ; i -- ) {
69
71
mp_obj_t function = list -> items [i ];
70
72
71
73
nlr_buf_t nlr ;
Original file line number Diff line number Diff line change @@ -172,7 +172,7 @@ void mp_init(void) {
172
172
#endif
173
173
174
174
#if MICROPY_PY_ATEXIT
175
- MP_STATE_VM (atexit ) = NULL ;
175
+ MP_STATE_VM (atexit_handlers ) = NULL ;
176
176
#endif
177
177
178
178
#if MICROPY_PY_BLUETOOTH
You can’t perform that action at this time.
0 commit comments