8000 gh-81057: Move the Allocators to _PyRuntimeState by ericsnowcurrently · Pull Request #99217 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-81057: Move the Allocators to _PyRuntimeState #99217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9a44e7a
Look up the current interpreter in PyObject_Malloc().
ericsnowcurrently Oct 5, 2022
16cd128
Move the low-level allocator implementations to a header file.
ericsnowcurrently Oct 6, 2022
737877c
Move the top-level allocators state.
ericsnowcurrently Oct 6, 2022
6dd7ba5
Move the allocators to the runtime state.
ericsnowcurrently Oct 6, 2022
56251cb
Drop debug code.
ericsnowcurrently Oct 6, 2022
007eed4
Move the top-level object allocator to the runtime state.
ericsnowcurrently Oct 6, 2022
38a80d8
Move the arenas state to the runtime state.
ericsnowcurrently Oct 7, 2022
83d397f
Pass the context to initializers explicitly.
ericsnowcurrently Oct 7, 2022
991dfc8
Move the allocator groupings to pycore_allocators.h.
ericsnowcurrently Nov 8, 2022
ac5cfb0
Move the arena allocator to pycore_pymem_init.h.
ericsnowcurrently Nov 8, 2022
9f32218
Add a NEWS entry.
ericsnowcurrently Nov 7, 2022
e5fc139
Move the object allocator definitions to pycore_obmalloc*.h.
ericsnowcurrently Nov 8, 2022
d61b410
pycore_allocators.h -> pycore_pymem_allocators.h
ericsnowcurrently Nov 8, 2022
0efcef7
Move the arena allocator impl to its own file.
ericsnowcurrently Nov 8000 8, 2022
ec01f99
Move _Py_GetAllocatedBlocks() over.
ericsnowcurrently Nov 8, 2022
a1ff9b0
Move _PyObject_DebugMallocStat() over.
ericsnowcurrently Nov 8, 2022
3172cbe
Restore uint for obmalloc.
ericsnowcurrently Nov 8, 2022
adc60e2
Do not define the functions in header files.
ericsnowcurrently Nov 9, 2022
5262207
Drop pycore_*_allocators.h.
ericsnowcurrently Nov 9, 2022
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
Restore uint for obmalloc.
  • Loading branch information
ericsnowcurrently committed Nov 8, 2022
commit 3172cbeaf0b6efa6152fa7b6ce67f3f16e10b3cf
14 changes: 12 additions & 2 deletions Include/internal/pycore_obmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif


typedef unsigned int pymem_uint; /* assuming >= 16 bits */

#undef uint
#define uint pymem_uint


/* An object allocator for Python.

Here is an introduction to the layers of the Python memory architecture,
Expand Down Expand Up @@ -130,7 +137,7 @@ extern "C" {
#endif

/* Return the number of bytes in size class I, as a uint. */
#define INDEX2SIZE(I) (((uint)(I) + 1) << ALIGNMENT_SHIFT)
#define INDEX2SIZE(I) (((pymem_uint)(I) + 1) << ALIGNMENT_SHIFT)

/*
* Max size threshold below which malloc requests are considered to be
Expand Down Expand Up @@ -307,7 +314,7 @@ struct arena_object {
#define POOL_ADDR(P) ((poolp)_Py_ALIGN_DOWN((P), POOL_SIZE))

/* Return total number of blocks in pool of size index I, as a uint. */
#define NUMBLOCKS(I) ((uint)(POOL_SIZE - POOL_OVERHEAD) / INDEX2SIZE(I))
#define NUMBLOCKS(I) ((pymem_uint)(POOL_SIZE - POOL_OVERHEAD) / INDEX2SIZE(I))

/*==========================================================================*/

Expand Down Expand Up @@ -657,6 +664,9 @@ struct _obmalloc_state {
};


#undef uint


/* Allocate memory directly from the O/S virtual memory system,
* where supported. Otherwise fallback on malloc */
void *_PyObject_VirtualAlloc(size_t size);
Expand Down
10 changes: 6 additions & 4 deletions Objects/obmalloc.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#include "Python.h"
#include "pycore_pymem.h" // _PyTraceMalloc_Config
#include "pycore_code.h" // stats
#include "pycore_pystate.h" // _PyInterpreterState_GET

#include "pycore_obmalloc.h"
#include "pycore_pymem.h"
#include "pycore_pymem_allocators.h"

#include <stdbool.h>


#undef uint
#define uint pymem_uint


/* Defined in tracemalloc.c */
extern void _PyMem_DumpTraceback(int fd, const void *ptr);


/* Python's malloc wrappers (see pymem.h) */

#undef uint
#define uint unsigned int /* assuming >= 16 bits */

static void _PyObject_DebugDumpAddress(const void *p);
static void _PyMem_DebugCheckAddress(const char *func, char api_id, const void *p);

Expand Down
0