forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-100240: Use a consistent implementation for freelists (pytho…
…n#121934) This combines and updates our freelist handling to use a consistent implementation. Objects in the freelist are linked together using the first word of memory block. If configured with freelists disabled, these operations are essentially no-ops.
- Loading branch information
Showing
27 changed files
with
290 additions
and
700 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef Py_INTERNAL_FREELIST_STATE_H | ||
#define Py_INTERNAL_FREELIST_STATE_H | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifndef Py_BUILD_CORE | ||
# error "this header requires Py_BUILD_CORE define" | ||
#endif | ||
|
||
#ifdef WITH_FREELISTS | ||
// with freelists | ||
# define PyTuple_MAXSAVESIZE 20 // Largest tuple to save on freelist | ||
# define Py_tuple_MAXFREELIST 2000 // Maximum number of tuples of each size to save | ||
# define Py_lists_MAXFREELIST 80 | ||
# define Py_dicts_MAXFREELIST 80 | ||
# define Py_dictkeys_MAXFREELIST 80 | ||
# define Py_floats_MAXFREELIST 100 | ||
# define Py_slices_MAXFREELIST 1 | ||
# define Py_contexts_MAXFREELIST 255 | ||
# define Py_async_gens_MAXFREELIST 80 | ||
# define Py_async_gen_asends_MAXFREELIST 80 | ||
# define Py_object_stack_chunks_MAXFREELIST 4 | ||
#else | ||
# define PyTuple_MAXSAVESIZE 0 | ||
#endif | ||
|
||
// A generic freelist of either PyObjects or other data structures. | ||
struct _Py_freelist { | ||
// Entries are linked together using the first word of the the object. | ||
// For PyObjects, this overlaps with the `ob_refcnt` field or the `ob_tid` | ||
// field. | ||
void *freelist; | ||
|
||
// The number of items in the free list or -1 if the free list is disabled | ||
Py_ssize_t size; | ||
}; | ||
|
||
struct _Py_freelists { | ||
#ifdef WITH_FREELISTS | ||
struct _Py_freelist floats; | ||
struct _Py_freelist tuples[PyTuple_MAXSAVESIZE]; | ||
struct _Py_freelist lists; | ||
struct _Py_freelist dicts; | ||
struct _Py_freelist dictkeys; | ||
struct _Py_freelist slices; | ||
struct _Py_freelist contexts; | ||
struct _Py_freelist async_gens; | ||
struct _Py_freelist async_gen_asends; | ||
struct _Py_freelist object_stack_chunks; | ||
#else | ||
char _unused; // Empty structs are not allowed. | ||
#endif | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif /* !Py_INTERNAL_FREELIST_STATE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.