1 #ifndef Py_INTERNAL_ATEXIT_H 2 #define Py_INTERNAL_ATEXIT_H 3 4 #include "pycore_lock.h" // PyMutex 5 6 #ifdef __cplusplus 7 extern "C" { 8 #endif 9 10 #ifndef Py_BUILD_CORE 11 # error "this header requires Py_BUILD_CORE define" 12 #endif 13 14 15 //############### 16 // runtime atexit 17 18 typedef void (*atexit_callbackfunc)(void); 19 20 struct _atexit_runtime_state { 21 PyMutex mutex; 22 #define NEXITFUNCS 32 23 atexit_callbackfunc callbacks[NEXITFUNCS]; 24 int ncallbacks; 25 }; 26 27 28 //################### 29 // interpreter atexit 30 31 typedef void (*atexit_datacallbackfunc)(void *); 32 33 typedef struct atexit_callback { 34 atexit_datacallbackfunc func; 35 void *data; 36 struct atexit_callback *next; 37 } atexit_callback; 38 39 typedef struct { 40 PyObject *func; 41 PyObject *args; 42 PyObject *kwargs; 43 } atexit_py_callback; 44 45 struct atexit_state { 46 atexit_callback *ll_callbacks; 47 atexit_callback *last_ll_callback; 48 49 // XXX The rest of the state could be moved to the atexit module state 50 // and a low-level callback added for it during module exec. 51 // For the moment we leave it here. 52 atexit_py_callback **callbacks; 53 int ncallbacks; 54 int callback_len; 55 }; 56 57 // Export for '_interpchannels' shared extension 58 PyAPI_FUNC(int) _Py_AtExit( 59 PyInterpreterState *interp, 60 atexit_datacallbackfunc func, 61 void *data); 62 63 #ifdef __cplusplus 64 } 65 #endif 66 #endif /* !Py_INTERNAL_ATEXIT_H */ 67