aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-12-15 14:34:19 +0100
committerGitHub <noreply@github.com>2020-12-15 14:34:19 +0100
commitb8fa135908d294b350cdad04e2f512327a538dee (patch)
tree25b6b1516e3f6d29c9cf3cafb71c516cbc93a3c3 /Include
parentbpo-42246: Remove DO_NOT_EMIT_BYTECODE macros, so that while loops and if sta... (diff)
downloadcpython-b8fa135908d294b350cdad04e2f512327a538dee.tar.gz
cpython-b8fa135908d294b350cdad04e2f512327a538dee.tar.bz2
cpython-b8fa135908d294b350cdad04e2f512327a538dee.zip
bpo-42639: Move atexit state to PyInterpreterState (GH-23763)
* Add _PyAtExit_Call() function and remove pyexitfunc and pyexitmodule members of PyInterpreterState. The function logs atexit callback errors using _PyErr_WriteUnraisableMsg(). * Add _PyAtExit_Init() and _PyAtExit_Fini() functions. * Remove traverse, clear and free functions of the atexit module. Co-authored-by: Dong-hee Na <donghee.na@python.org>
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_interp.h18
-rw-r--r--Include/internal/pycore_pylifecycle.h4
2 files changed, 18 insertions, 4 deletions
diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h
index 12416c2e94d..9ec5358b5e3 100644
--- a/Include/internal/pycore_interp.h
+++ b/Include/internal/pycore_interp.h
@@ -159,6 +159,20 @@ struct _Py_exc_state {
};
+// atexit state
+typedef struct {
+ PyObject *func;
+ PyObject *args;
+ PyObject *kwargs;
+} atexit_callback;
+
+struct atexit_state {
+ atexit_callback **callbacks;
+ int ncallbacks;
+ int callback_len;
+};
+
+
/* interpreter state */
#define _PY_NSMALLPOSINTS 257
@@ -234,12 +248,10 @@ struct _is {
PyObject *after_forkers_child;
#endif
- /* AtExit module */
- PyObject *atexit_module;
-
uint64_t tstate_next_unique_id;
struct _warnings_runtime_state warnings;
+ struct atexit_state atexit;
PyObject *audit_hooks;
diff --git a/Include/internal/pycore_pylifecycle.h b/Include/internal/pycore_pylifecycle.h
index e6e4187cd5a..d1c23c81791 100644
--- a/Include/internal/pycore_pylifecycle.h
+++ b/Include/internal/pycore_pylifecycle.h
@@ -55,6 +55,7 @@ extern PyStatus _PyTypes_Init(void);
extern PyStatus _PyTypes_InitSlotDefs(void);
extern PyStatus _PyImportZip_Init(PyThreadState *tstate);
extern PyStatus _PyGC_Init(PyThreadState *tstate);
+extern PyStatus _PyAtExit_Init(PyThreadState *tstate);
/* Various internal finalizers */
@@ -85,6 +86,7 @@ extern void _PyHash_Fini(void);
extern void _PyTraceMalloc_Fini(void);
extern void _PyWarnings_Fini(PyInterpreterState *interp);
extern void _PyAST_Fini(PyInterpreterState *interp);
+extern void _PyAtExit_Fini(PyInterpreterState *interp);
extern PyStatus _PyGILState_Init(PyThreadState *tstate);
extern void _PyGILState_Fini(PyThreadState *tstate);
@@ -109,7 +111,7 @@ PyAPI_FUNC(void) _PyErr_Display(PyObject *file, PyObject *exception,
PyAPI_FUNC(void) _PyThreadState_DeleteCurrent(PyThreadState *tstate);
-extern void _PyAtExit_Call(PyObject *module);
+extern void _PyAtExit_Call(PyThreadState *tstate);
#ifdef __cplusplus
}