summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDonghee Na <donghee.na@python.org>2024-01-12 00:31:28 (GMT)
committerGitHub <noreply@github.com>2024-01-12 00:31:28 (GMT)
commitefa738e862da26f870ca659b01ff732649f400a7 (patch)
tree19c39fb02cb3089910fe65aaa235e918b68d0d6c
parent53d2e1f26c3fca88a9217f1935cb288f4ba78464 (diff)
downloadcpython-efa738e862da26f870ca659b01ff732649f400a7.zip
cpython-efa738e862da26f870ca659b01ff732649f400a7.tar.gz
cpython-efa738e862da26f870ca659b01ff732649f400a7.tar.bz2
gh-111968: Explicit handling for finalized freelist (gh-113929)
-rw-r--r--Objects/floatobject.c4
-rw-r--r--Objects/listobject.c22
2 files changed, 7 insertions, 19 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index f1a09c0..912c450 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -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);
diff --git a/Objects/listobject.c b/Objects/listobject.c
index c05c4fd..288c704 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -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)
{
@@ -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];
@@ -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",
@@ -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);
@@ -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);
}