Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add _PyFreeList_Disable
  • Loading branch information
iritkatriel committed Feb 9, 2023
commit 827b81b97427dbd7c1da8258e4c75c189bb59ba4
13 changes: 7 additions & 6 deletions Include/internal/pycore_pymem.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ PyAPI_FUNC(int) _PyMem_GetAllocatorName(
PyAPI_FUNC(int) _PyMem_SetupAllocators(PyMemAllocatorName allocator);


#if WITH_FREELISTS
/* Free lists.
*
* Free lists have a pointer to their first entry and
Expand All @@ -111,7 +110,8 @@ typedef struct _freelist {

extern void *_PyFreeList_HalfFillAndAllocate(_PyFreeList *list);
extern void _PyFreeList_FreeToFull(_PyFreeList *list, void *ptr);

extern void _PyFreeList_Clear(_PyFreeList *list);
extern void _PyFreeList_Disable(_PyFreeList *list);

static inline void *
_PyFreeList_Alloc(_PyFreeList *list) {
Expand Down Expand Up @@ -151,13 +151,14 @@ static inline void
_PyFreeList_Init(_PyFreeList *list, int size, int capacity)
{
list->ptr = NULL;
list->space = list->capacity = capacity;
list->size = size;
#if WITH_FREELISTS
list->space = list->capacity = capacity;
#else
_PyFreeList_Disable(list);
#endif
}

extern void _PyFreeList_Clear(_PyFreeList *list);
#endif /* WITH_FREELISTS */

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 6 additions & 2 deletions Objects/obmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,6 @@ PyObject_Free(void *ptr)
#endif


#if WITH_FREELISTS
void *
_PyFreeList_HalfFillAndAllocate(_PyFreeList *list)
{
Expand Down Expand Up @@ -759,6 +758,12 @@ _PyFreeList_Clear(_PyFreeList *list)
list->space += space;
}

void
_PyFreeList_Disable(_PyFreeList *list)
{
list->space = list->capacity = 0;
}

void
_PyFreeList_FreeToFull(_PyFreeList *list, void *ptr)
{
Expand All @@ -769,7 +774,6 @@ _PyFreeList_FreeToFull(_PyFreeList *list, void *ptr)
}
_PyFreeList_Clear(list);
}
#endif /* WITH_FREELISTS */

#ifdef WITH_PYMALLOC

Expand Down
3 changes: 1 addition & 2 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,7 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)

for (int i=0; i < INTERP_NUM_FREELISTS; i++) {
_PyFreeList_Clear(&interp->freelists[i]);
interp->freelists[i].space = 0;
interp->freelists[i].capacity = 0;
_PyFreeList_Disable(&interp->freelists[i]);
}

/* It is possible that any of the objects below have a finalizer
Expand Down