mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
gh-81057: Move the Allocators to _PyRuntimeState (gh-99217)
The global allocators were stored in 3 static global variables: _PyMem_Raw, _PyMem, and _PyObject. State for the "small block" allocator was stored in another 13. That makes a total of 16 global variables. We are moving all 16 to the _PyRuntimeState struct as part of the work for gh-81057. (If PEP 684 is accepted then we will follow up by moving them all to PyInterpreterState.) https://github.com/python/cpython/issues/81057
This commit is contained in:
parent
55c96e8053
commit
67807cfc87
14 changed files with 1129 additions and 925 deletions
|
|
@ -11,6 +11,27 @@ extern "C" {
|
|||
#include "pymem.h" // PyMemAllocatorName
|
||||
|
||||
|
||||
typedef struct {
|
||||
/* We tag each block with an API ID in order to tag API violations */
|
||||
char api_id;
|
||||
PyMemAllocatorEx alloc;
|
||||
} debug_alloc_api_t;
|
||||
|
||||
struct _pymem_allocators {
|
||||
struct {
|
||||
PyMemAllocatorEx raw;
|
||||
PyMemAllocatorEx mem;
|
||||
PyMemAllocatorEx obj;
|
||||
} standard;
|
||||
struct {
|
||||
debug_alloc_api_t raw;
|
||||
debug_alloc_api_t mem;
|
||||
debug_alloc_api_t obj;
|
||||
} debug;
|
||||
PyObjectArenaAllocator obj_arena;
|
||||
};
|
||||
|
||||
|
||||
/* Set the memory allocator of the specified domain to the default.
|
||||
Save the old allocator into *old_alloc if it's non-NULL.
|
||||
Return on success, or return -1 if the domain is unknown. */
|
||||
|
|
@ -94,20 +115,6 @@ struct _PyTraceMalloc_Config {
|
|||
|
||||
PyAPI_DATA(struct _PyTraceMalloc_Config) _Py_tracemalloc_config;
|
||||
|
||||
/* Allocate memory directly from the O/S virtual memory system,
|
||||
* where supported. Otherwise fallback on malloc */
|
||||
void *_PyObject_VirtualAlloc(size_t size);
|
||||
void _PyObject_VirtualFree(void *, size_t size);
|
||||
|
||||
/* This function returns the number of allocated memory blocks, regardless of size */
|
||||
PyAPI_FUNC(Py_ssize_t) _Py_GetAllocatedBlocks(void);
|
||||
|
||||
/* Macros */
|
||||
#ifdef WITH_PYMALLOC
|
||||
// Export the symbol for the 3rd party guppy3 project
|
||||
PyAPI_FUNC(int) _PyObject_DebugMallocStats(FILE *out);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue