@@ -31,11 +31,11 @@ _Py_freelists_GET(void)
3131
3232// Pushes `op` to the freelist, calls `freefunc` if the freelist is full
3333#define _Py_FREELIST_FREE (NAME , op , freefunc ) \
34- _PyFreeList_Free(&_Py_freelists_GET()->NAME, _PyObject_CAST(op), \
35- Py_ ## NAME ## _MAXFREELIST, freefunc)
34+ _PyFreeList_Free(&_Py_freelists_GET()->NAME, _PyObject_CAST(op), freefunc)
35+
3636// Pushes `op` to the freelist, returns 1 if successful, 0 if the freelist is full
37- #define _Py_FREELIST_PUSH (NAME , op , limit ) \
38- _PyFreeList_Push(&_Py_freelists_GET()->NAME, _PyObject_CAST(op), limit )
37+ #define _Py_FREELIST_PUSH (NAME , op ) \
38+ _PyFreeList_Push(&_Py_freelists_GET()->NAME, _PyObject_CAST(op))
3939
4040// Pops a PyObject from the freelist, returns NULL if the freelist is empty.
4141#define _Py_FREELIST_POP (TYPE , NAME ) \
@@ -46,26 +46,39 @@ _Py_freelists_GET(void)
4646#define _Py_FREELIST_POP_MEM (NAME ) \
4747 _PyFreeList_PopMem(&_Py_freelists_GET()->NAME)
4848
49- #define _Py_FREELIST_SIZE (NAME ) (int)((_Py_freelists_GET()->NAME).size)
49+ static inline uint32_t
50+ _PyFreeList_Size (struct _Py_freelist * fl )
51+ {
52+ return fl -> capacity - fl -> available ;
53+ }
54+
55+ #define _Py_FREELIST_SIZE (NAME ) _PyFreeList_Size(&_Py_freelists_GET()->NAME)
56+
57+ static inline void
58+ _PyFreeList_Init (struct _Py_freelist * fl , uint32_t capacity )
59+ {
60+ fl -> freelist = NULL ;
61+ fl -> capacity = fl -> available = capacity ;
62+ }
5063
5164static inline int
52- _PyFreeList_Push (struct _Py_freelist * fl , void * obj , Py_ssize_t maxsize )
65+ _PyFreeList_Push (struct _Py_freelist * fl , void * obj )
5366{
54- if (fl -> size < maxsize && fl -> size > = 0 ) {
67+ if (fl -> available ! = 0 ) {
5568 FT_ATOMIC_STORE_PTR_RELAXED (* (void * * )obj , fl -> freelist );
5669 fl -> freelist = obj ;
57- fl -> size ++ ;
70+ fl -> available -- ;
5871 OBJECT_STAT_INC (to_freelist );
5972 return 1 ;
6073 }
6174 return 0 ;
6275}
6376
6477static inline void
65- _PyFreeList_Free (struct _Py_freelist * fl , void * obj , Py_ssize_t maxsize ,
78+ _PyFreeList_Free (struct _Py_freelist * fl , void * obj ,
6679 freefunc dofree )
6780{
68- if (!_PyFreeList_Push (fl , obj , maxsize )) {
81+ if (!_PyFreeList_Push (fl , obj )) {
6982 dofree (obj );
7083 }
7184}
@@ -75,9 +88,10 @@ _PyFreeList_PopNoStats(struct _Py_freelist *fl)
7588{
7689 void * obj = fl -> freelist ;
7790 if (obj != NULL ) {
78- assert (fl -> size > 0 );
91+ assert (fl -> capacity > 0 );
7992 fl -> freelist = * (void * * )obj ;
80- fl -> size -- ;
93+ fl -> available ++ ;
94+ assert (fl -> available <= fl -> capacity );
8195 }
8296 return obj ;
8397}
@@ -97,9 +111,7 @@ static inline void *
97111_PyFreeList_PopMem (struct _Py_freelist * fl )
98112{
99113 void * op = _PyFreeList_PopNoStats (fl );
100- if (op != NULL ) {
101- OBJECT_STAT_INC (from_freelist );
102- }
114+ OBJECT_STAT_INC_COND (from_freelist , op != NULL );
103115 return op ;
104116}
105117
0 commit comments