@@ -20,7 +20,7 @@ class list "PyListObject *" "&PyList_Type"
2020
2121_Py_DECLARE_STR (list_err , "list index out of range" );
2222
23- #if    PyList_MAXFREELIST   >   0 
23+ #ifdef    WITH_FREELISTS 
2424static  struct  _Py_list_state  * 
2525get_list_state (void )
2626{
@@ -123,7 +123,7 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size)
123123void 
124124_PyList_ClearFreeList (_PyFreeListState  * freelist_state , int  is_finalization )
125125{
126- #if    PyList_MAXFREELIST   >   0 
126+ #ifdef    WITH_FREELISTS 
127127    struct  _Py_list_state  * state  =  & freelist_state -> list_state ;
128128    while  (state -> numfree  >  0 ) {
129129        PyListObject  * op  =  state -> free_list [-- state -> numfree ];
@@ -146,7 +146,7 @@ _PyList_Fini(_PyFreeListState *state)
146146void 
147147_PyList_DebugMallocStats (FILE  * out )
148148{
149- #if    PyList_MAXFREELIST   >   0 
149+ #ifdef    WITH_FREELISTS 
150150    struct  _Py_list_state  * state  =  get_list_state ();
151151    _PyDebugAllocatorStats (out ,
152152                           "free PyListObject" ,
@@ -164,13 +164,9 @@ PyList_New(Py_ssize_t size)
164164        return  NULL ;
165165    }
166166
167- #if    PyList_MAXFREELIST   >   0 
167+ #ifdef    WITH_FREELISTS 
168168    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 ) {
174170        state -> numfree -- ;
175171        op  =  state -> free_list [state -> numfree ];
176172        OBJECT_STAT_INC (from_freelist );
@@ -360,13 +356,9 @@ list_dealloc(PyObject *self)
360356        }
361357        PyMem_Free (op -> ob_item );
362358    }
363- #if    PyList_MAXFREELIST   >   0 
359+ #ifdef    WITH_FREELISTS 
364360    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 )) {
370362        state -> free_list [state -> numfree ++ ] =  op ;
371363        OBJECT_STAT_INC (to_freelist );
372364    }
0 commit comments