summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorDonghee Na <donghee.na@python.org>2024-01-09 23:04:41 (GMT)
committerGitHub <noreply@github.com>2024-01-09 23:04:41 (GMT)
commit57bdc6c30d2665c2760ff5a88487e57c8b3c397a (patch)
treede5a4efb2a25eac14672c6a538ca6e50ae7ed582 /Objects
parentcdca0ce0ad47604b7007229415817a7a152f7f9a (diff)
downloadcpython-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.c22
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 */