| 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 |
// Kept for ABI compatibility--do not use! (See GH-127791.) |
| 48 |
atexit_callback *last_ll_callback; |
| 49 |
|
| 50 |
// XXX The rest of the state could be moved to the atexit module state |
| 51 |
// and a low-level callback added for it during module exec. |
| 52 |
// For the moment we leave it here. |
| 53 |
atexit_py_callback **callbacks; |
| 54 |
int ncallbacks; |
| 55 |
int callback_len; |
| 56 |
}; |
| 57 |
|
| 58 |
// Export for '_interpchannels' shared extension |
| 59 |
PyAPI_FUNC(int) _Py_AtExit( |
| 60 |
PyInterpreterState *interp, |
| 61 |
atexit_datacallbackfunc func, |
| 62 |
void *data); |
| 63 |
|
| 64 |
#ifdef __cplusplus |
| 65 |
} |
| 66 |
#endif |
| 67 |
#endif /* !Py_INTERNAL_ATEXIT_H */ |