diff options
author | Donghee Na <donghee.na@python.org> | 2024-01-09 23:04:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-09 23:04:41 (GMT) |
commit | 57bdc6c30d2665c2760ff5a88487e57c8b3c397a (patch) | |
tree | de5a4efb2a25eac14672c6a538ca6e50ae7ed582 /Objects | |
parent | cdca0ce0ad47604b7007229415817a7a152f7f9a (diff) | |
download | cpython-57bdc6c30d2665c2760ff5a88487e57c8b3c397a.zip cpython-57bdc6c30d2665c2760ff5a88487e57c8b3c397a.tar.gz cpython-57bdc6c30d2665c2760ff5a88487e57c8b3c397a.tar.bz2 |
gh-111968: Introduce _PyFreeListState and _PyFreeListState_GET API (gh-113584)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/listobject.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 5cd4a05..2fc57e1 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -24,8 +24,9 @@ _Py_DECLARE_STR(list_err, "list index out of range"); static struct _Py_list_state * get_list_state(void) { - PyInterpreterState *interp = _PyInterpreterState_GET(); - return &interp->list; + _PyFreeListState *state = _PyFreeListState_GET(); + assert(state != NULL); + return &state->list; } #endif @@ -120,26 +121,25 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size) } void -_PyList_ClearFreeList(PyInterpreterState *interp) +_PyList_ClearFreeList(_PyFreeListState *freelist_state, int is_finalization) { #if PyList_MAXFREELIST > 0 - struct _Py_list_state *state = &interp->list; - while (state->numfree) { + struct _Py_list_state *state = &freelist_state->list; + while (state->numfree > 0) { PyListObject *op = state->free_list[--state->numfree]; assert(PyList_CheckExact(op)); PyObject_GC_Del(op); } + if (is_finalization) { + state->numfree = -1; + } #endif } void -_PyList_Fini(PyInterpreterState *interp) +_PyList_Fini(_PyFreeListState *state) { - _PyList_ClearFreeList(interp); -#if defined(Py_DEBUG) && PyList_MAXFREELIST > 0 - struct _Py_list_state *state = &interp->list; - state->numfree = -1; -#endif + _PyList_ClearFreeList(state, 1); } /* Print summary info about the state of the optimized allocator */ |