Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-111968: Explicit handling for finalized freelist #113929

Merged
merged 6 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ PyFloat_FromDouble(double fval)
struct _Py_float_state *state = get_float_state();
op = state->free_list;
if (op != NULL) {
#ifdef Py_DEBUG
// PyFloat_FromDouble() must not be called after _PyFloat_Fini()
assert(state->numfree != -1);
#endif
state->free_list = (PyFloatObject *) Py_TYPE(op);
state->numfree--;
OBJECT_STAT_INC(from_freelist);
Expand Down
22 changes: 7 additions & 15 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class list "PyListObject *" "&PyList_Type"

_Py_DECLARE_STR(list_err, "list index out of range");

#if PyList_MAXFREELIST > 0
#ifdef WITH_FREELISTS
static struct _Py_list_state *
get_list_state(void)
{
Expand Down Expand Up @@ -123,7 +123,7 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size)
void
_PyList_ClearFreeList(_PyFreeListState *freelist_state, int is_finalization)
{
#if PyList_MAXFREELIST > 0
#ifdef WITH_FREELISTS
struct _Py_list_state *state = &freelist_state->list_state;
while (state->numfree > 0) {
PyListObject *op = state->free_list[--state->numfree];
Expand All @@ -146,7 +146,7 @@ _PyList_Fini(_PyFreeListState *state)
void
_PyList_DebugMallocStats(FILE *out)
{
#if PyList_MAXFREELIST > 0
#ifdef WITH_FREELISTS
struct _Py_list_state *state = get_list_state();
_PyDebugAllocatorStats(out,
"free PyListObject",
Expand All @@ -164,13 +164,9 @@ PyList_New(Py_ssize_t size)
return NULL;
}

#if PyList_MAXFREELIST > 0
#ifdef WITH_FREELISTS
struct _Py_list_state *state = get_list_state();
#ifdef Py_DEBUG
// PyList_New() must not be called after _PyList_Fini()
assert(state->numfree != -1);
#endif
if (PyList_MAXFREELIST && state->numfree) {
if (PyList_MAXFREELIST && state->numfree > 0) {
state->numfree--;
op = state->free_list[state->numfree];
OBJECT_STAT_INC(from_freelist);
Expand Down Expand Up @@ -360,13 +356,9 @@ list_dealloc(PyObject *self)
}
PyMem_Free(op->ob_item);
}
#if PyList_MAXFREELIST > 0
#ifdef WITH_FREELISTS
struct _Py_list_state *state = get_list_state();
#ifdef Py_DEBUG
// list_dealloc() must not be called after _PyList_Fini()
assert(state->numfree != -1);
#endif
if (state->numfree < PyList_MAXFREELIST && PyList_CheckExact(op)) {
if (state->numfree < PyList_MAXFREELIST && state->numfree >= 0 && PyList_CheckExact(op)) {
state->free_list[state->numfree++] = op;
OBJECT_STAT_INC(to_freelist);
}
Expand Down
Loading