Skip to content

Commit ce2db5d

Browse files
Add _PyExc_FiniHeapObjects(), to call before _PyInterpreterState_Clear().
1 parent 5e9b17e commit ce2db5d

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

Include/internal/pycore_exceptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ extern "C" {
1616
extern PyStatus _PyExc_InitState(PyInterpreterState *);
1717
extern PyStatus _PyExc_InitGlobalObjects(PyInterpreterState *);
1818
extern int _PyExc_InitTypes(PyInterpreterState *);
19+
extern void _PyExc_FiniHeapObjects(PyInterpreterState *);
20+
extern void _PyExc_FiniTypes(PyInterpreterState *);
1921
extern void _PyExc_Fini(PyInterpreterState *);
2022

2123

@@ -32,7 +34,6 @@ struct _Py_exc_state {
3234
PyTypeObject *ExceptionSnapshotType;
3335
};
3436

35-
extern void _PyExc_ClearExceptionGroupType(PyInterpreterState *);
3637

3738
/* other API */
3839

Objects/exceptions.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3682,14 +3682,9 @@ _PyExc_InitTypes(PyInterpreterState *interp)
36823682
return 0;
36833683
}
36843684

3685-
3686-
static void
3687-
_exc_snapshot_clear_type(PyInterpreterState *interp);
3688-
3689-
static void
3685+
void
36903686
_PyExc_FiniTypes(PyInterpreterState *interp)
36913687
{
3692-
_exc_snapshot_clear_type(interp);
36933688
for (Py_ssize_t i=Py_ARRAY_LENGTH(static_exceptions) - 1; i >= 0; i--) {
36943689
PyTypeObject *exc = static_exceptions[i].exc;
36953690
_PyStaticType_Dealloc(interp, exc);
@@ -3806,11 +3801,16 @@ _PyBuiltins_AddExceptions(PyObject *bltinmod)
38063801
return 0;
38073802
}
38083803

3804+
3805+
// _PyExc_FiniHeapObjects() must be called before the interpreter
3806+
// state is cleared, since there are heap types to clean up.
3807+
38093808
void
3810-
_PyExc_ClearExceptionGroupType(PyInterpreterState *interp)
3809+
_PyExc_FiniHeapObjects(PyInterpreterState *interp)
38113810
{
3812-
struct _Py_exc_state *state = &interp->exc_state;
3811+
struct _Py_exc_state *state = get_exc_state(interp);
38133812
Py_CLEAR(state->PyExc_ExceptionGroup);
3813+
Py_CLEAR(state->ExceptionSnapshotType);
38143814
}
38153815

38163816
void
@@ -3819,8 +3819,6 @@ _PyExc_Fini(PyInterpreterState *interp)
38193819
struct _Py_exc_state *state = &interp->exc_state;
38203820
free_preallocated_memerrors(state);
38213821
Py_CLEAR(state->errnomap);
3822-
3823-
_PyExc_FiniTypes(interp);
38243822
}
38253823

38263824
int
@@ -3972,13 +3970,6 @@ _exc_snapshot_init_type(PyInterpreterState *interp)
39723970
return 0;
39733971
}
39743972

3975-
static void
3976-
_exc_snapshot_clear_type(PyInterpreterState *interp)
3977-
{
3978-
struct _Py_exc_state *state = get_exc_state(interp);
3979-
Py_CLEAR(state->ExceptionSnapshotType);
3980-
}
3981-
39823973
PyTypeObject *
39833974
_PyExc_GetExceptionSnapshotType(PyInterpreterState *interp)
39843975
{

Python/pylifecycle.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ finalize_interp_types(PyInterpreterState *interp)
17421742
{
17431743
_PyUnicode_FiniTypes(interp);
17441744
_PySys_FiniTypes(interp);
1745-
_PyExc_Fini(interp);
1745+
_PyExc_FiniTypes(interp);
17461746
_PyAsyncGen_Fini(interp);
17471747
_PyContext_Fini(interp);
17481748
_PyFloat_FiniType(interp);
@@ -1779,7 +1779,7 @@ finalize_interp_clear(PyThreadState *tstate)
17791779
int is_main_interp = _Py_IsMainInterpreter(tstate->interp);
17801780

17811781
_PyXI_Fini(tstate->interp);
1782-
_PyExc_ClearExceptionGroupType(tstate->interp);
1782+
_PyExc_FiniHeapObjects(tstate->interp);
17831783
_Py_clear_generic_types(tstate->interp);
17841784

17851785
/* Clear interpreter state and all thread states */
@@ -1799,6 +1799,7 @@ finalize_interp_clear(PyThreadState *tstate)
17991799
_PyPerfTrampoline_Fini();
18001800
}
18011801

1802+
_PyExc_Fini(tstate->interp);
18021803
finalize_interp_types(tstate->interp);
18031804
}
18041805

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy