diff options
author | Donghee Na <donghee.na@python.org> | 2024-02-10 00:57:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-10 00:57:04 (GMT) |
commit | d4d5bae1471788b345155e8e93a2fe4ab92d09dc (patch) | |
tree | 989f7efdc60aff606679d12b4f1853174dd4365d /Objects | |
parent | 564385612cdf72c2fa8e629a68225fb2cd3b3d99 (diff) | |
download | cpython-d4d5bae1471788b345155e8e93a2fe4ab92d09dc.zip cpython-d4d5bae1471788b345155e8e93a2fe4ab92d09dc.tar.gz cpython-d4d5bae1471788b345155e8e93a2fe4ab92d09dc.tar.bz2 |
gh-111968: Refactor _PyXXX_Fini to integrate with _PyObject_ClearFreeLists (gh-114899)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/floatobject.c | 10 | ||||
-rw-r--r-- | Objects/genobject.c | 11 | ||||
-rw-r--r-- | Objects/listobject.c | 10 | ||||
-rw-r--r-- | Objects/object.c | 15 | ||||
-rw-r--r-- | Objects/sliceobject.c | 12 | ||||
-rw-r--r-- | Objects/tupleobject.c | 5 |
6 files changed, 19 insertions, 44 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index c440e0d..9b322c5 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -2011,16 +2011,6 @@ _PyFloat_ClearFreeList(_PyFreeListState *freelist_state, int is_finalization) } void -_PyFloat_Fini(_PyFreeListState *state) -{ - // With Py_GIL_DISABLED: - // the freelists for the current thread state have already been cleared. -#ifndef Py_GIL_DISABLED - _PyFloat_ClearFreeList(state, 1); -#endif -} - -void _PyFloat_FiniType(PyInterpreterState *interp) { _PyStructSequence_FiniBuiltin(interp, &FloatInfoType); diff --git a/Objects/genobject.c b/Objects/genobject.c index ab523e4..59ab7ab 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -1682,17 +1682,6 @@ _PyAsyncGen_ClearFreeLists(_PyFreeListState *freelist_state, int is_finalization #endif } -void -_PyAsyncGen_Fini(_PyFreeListState *state) -{ - // With Py_GIL_DISABLED: - // the freelists for the current thread state have already been cleared. -#ifndef Py_GIL_DISABLED - _PyAsyncGen_ClearFreeLists(state, 1); -#endif -} - - static PyObject * async_gen_unwrap_value(PyAsyncGenObject *gen, PyObject *result) { diff --git a/Objects/listobject.c b/Objects/listobject.c index 307b8f1..7fdb91e 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -135,16 +135,6 @@ _PyList_ClearFreeList(_PyFreeListState *freelist_state, int is_finalization) #endif } -void -_PyList_Fini(_PyFreeListState *state) -{ - // With Py_GIL_DISABLED: - // the freelists for the current thread state have already been cleared. -#ifndef Py_GIL_DISABLED - _PyList_ClearFreeList(state, 1); -#endif -} - /* Print summary info about the state of the optimized allocator */ void _PyList_DebugMallocStats(FILE *out) diff --git a/Objects/object.c b/Objects/object.c index 61e6131..275aa671 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -793,6 +793,21 @@ PyObject_Bytes(PyObject *v) return PyBytes_FromObject(v); } +void +_PyObject_ClearFreeLists(_PyFreeListState *state, int is_finalization) +{ + // In the free-threaded build, freelists are per-PyThreadState and cleared in PyThreadState_Clear() + // In the default build, freelists are per-interpreter and cleared in finalize_interp_types() + _PyFloat_ClearFreeList(state, is_finalization); + _PyTuple_ClearFreeList(state, is_finalization); + _PyList_ClearFreeList(state, is_finalization); + _PyDict_ClearFreeList(state, is_finalization); + _PyContext_ClearFreeList(state, is_finalization); + _PyAsyncGen_ClearFreeLists(state, is_finalization); + // Only be cleared if is_finalization is true. + _PyObjectStackChunk_ClearFreeList(state, is_finalization); + _PySlice_ClearFreeList(state, is_finalization); +} /* def _PyObject_FunctionStr(x): diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index 8b9d6bb..9880c12 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -103,8 +103,11 @@ PyObject _Py_EllipsisObject = _PyObject_HEAD_INIT(&PyEllipsis_Type); /* Slice object implementation */ -void _PySlice_ClearCache(_PyFreeListState *state) +void _PySlice_ClearFreeList(_PyFreeListState *state, int is_finalization) { + if (!is_finalization) { + return; + } #ifdef WITH_FREELISTS PySliceObject *obj = state->slices.slice_cache; if (obj != NULL) { @@ -114,13 +117,6 @@ void _PySlice_ClearCache(_PyFreeListState *state) #endif } -void _PySlice_Fini(_PyFreeListState *state) -{ -#ifdef WITH_FREELISTS - _PySlice_ClearCache(state); -#endif -} - /* start, stop, and step are python objects with None indicating no index is present. */ diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index b9bf6cd..7d73c3f 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -964,11 +964,6 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize) static void maybe_freelist_clear(_PyFreeListState *, int); -void -_PyTuple_Fini(_PyFreeListState *state) -{ - maybe_freelist_clear(state, 1); -} void _PyTuple_ClearFreeList(_PyFreeListState *state, int is_finalization) |