@@ -20,7 +20,7 @@ class list "PyListObject *" "&PyList_Type"
20
20
21
21
_Py_DECLARE_STR (list_err , "list index out of range" );
22
22
23
- #if PyList_MAXFREELIST > 0
23
+ #ifdef WITH_FREELISTS
24
24
static struct _Py_list_state *
25
25
get_list_state (void )
26
26
{
@@ -123,7 +123,7 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size)
123
123
void
124
124
_PyList_ClearFreeList (_PyFreeListState * freelist_state , int is_finalization )
125
125
{
126
- #if PyList_MAXFREELIST > 0
126
+ #ifdef WITH_FREELISTS
127
127
struct _Py_list_state * state = & freelist_state -> list ;
128
128
while (state -> numfree > 0 ) {
129
129
PyListObject * op = state -> free_list [-- state -> numfree ];
@@ -146,7 +146,7 @@ _PyList_Fini(_PyFreeListState *state)
146
146
void
147
147
_PyList_DebugMallocStats (FILE * out )
148
148
{
149
- #if PyList_MAXFREELIST > 0
149
+ #ifdef WITH_FREELISTS
150
150
struct _Py_list_state * state = get_list_state ();
151
151
_PyDebugAllocatorStats (out ,
152
152
"free PyListObject" ,
@@ -164,13 +164,9 @@ PyList_New(Py_ssize_t size)
164
164
return NULL ;
165
165
}
166
166
167
- #if PyList_MAXFREELIST > 0
167
+ #ifdef WITH_FREELISTS
168
168
struct _Py_list_state * state = get_list_state ();
169
- #ifdef Py_DEBUG
170
- // PyList_New() must not be called after _PyList_Fini()
171
- assert (state -> numfree != -1 );
172
- #endif
173
- if (PyList_MAXFREELIST && state -> numfree ) {
169
+ if (PyList_MAXFREELIST && state -> numfree > 0 ) {
174
170
state -> numfree -- ;
175
171
op = state -> free_list [state -> numfree ];
176
172
OBJECT_STAT_INC (from_freelist );
@@ -360,13 +356,9 @@ list_dealloc(PyObject *self)
360
356
}
361
357
PyMem_Free (op -> ob_item );
362
358
}
363
- #if PyList_MAXFREELIST > 0
359
+ #ifdef WITH_FREELISTS
364
360
struct _Py_list_state * state = get_list_state ();
365
- #ifdef Py_DEBUG
366
- // list_dealloc() must not be called after _PyList_Fini()
367
- assert (state -> numfree != -1 );
368
- #endif
369
- if (state -> numfree < PyList_MAXFREELIST && PyList_CheckExact (op )) {
361
+ if (state -> numfree < PyList_MAXFREELIST && state -> numfree >= 0 && PyList_CheckExact (op )) {
370
362
state -> free_list [state -> numfree ++ ] = op ;
371
363
OBJECT_STAT_INC (to_freelist );
372
364
}
0 commit comments