Skip to content

Commit 2be00d9

Browse files
authored
bpo-35081: Move Py_BUILD_CORE code to internal/mem.h (GH-10249)
* Add #include "internal/mem.h" to C files using _PyMem_SetDefaultAllocator(). * Include/internal/mem.h now requires Py_BUILD_CORE to be defined.
1 parent b08746b commit 2be00d9

File tree

10 files changed

+20
-10
lines changed

10 files changed

+20
-10
lines changed

Include/internal/mem.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
extern "C" {
55
#endif
66

7+
#ifndef Py_BUILD_CORE
8+
# error "Py_BUILD_CORE must be defined to include this header"
9+
#endif
10+
711
#include "objimpl.h"
812
#include "pymem.h"
913

@@ -145,6 +149,14 @@ PyAPI_FUNC(void) _PyGC_Initialize(struct _gc_runtime_state *);
145149

146150
#define _PyGC_generation0 _PyRuntime.gc.generation0
147151

152+
153+
/* Set the memory allocator of the specified domain to the default.
154+
Save the old allocator into *old_alloc if it's non-NULL.
155+
Return on success, or return -1 if the domain is unknown. */
156+
PyAPI_FUNC(int) _PyMem_SetDefaultAllocator(
157+
PyMemAllocatorDomain domain,
158+
PyMemAllocatorEx *old_alloc);
159+
148160
#ifdef __cplusplus
149161
}
150162
#endif

Include/pymem.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,6 @@ PyAPI_FUNC(void) PyMem_SetAllocator(PyMemAllocatorDomain domain,
198198
PyAPI_FUNC(void) PyMem_SetupDebugHooks(void);
199199
#endif /* Py_LIMITED_API */
200200

201-
#ifdef Py_BUILD_CORE
202-
/* Set the memory allocator of the specified domain to the default.
203-
Save the old allocator into *old_alloc if it's non-NULL.
204-
Return on success, or return -1 if the domain is unknown. */
205-
PyAPI_FUNC(int) _PyMem_SetDefaultAllocator(
206-
PyMemAllocatorDomain domain,
207-
PyMemAllocatorEx *old_alloc);
208-
#endif
209-
210-
211201
/* bpo-35053: expose _Py_tracemalloc_config for performance:
212202
_Py_NewReference() needs an efficient check to test if tracemalloc is
213203
tracing.

Modules/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "Python.h"
44
#include "osdefs.h"
5+
#include "internal/mem.h"
56
#include "internal/pygetopt.h"
67
#include "internal/pystate.h"
78

Objects/obmalloc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Python.h"
2+
#include "internal/mem.h"
23

34
#include <stdbool.h>
45

Python/coreconfig.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Python.h"
2+
#include "internal/mem.h"
23
#include "internal/pystate.h"
34
#include <locale.h>
45
#ifdef HAVE_LANGINFO_H

Python/import.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Python-ast.h"
66
#undef Yield /* undefine macro conflicting with winbase.h */
77
#include "internal/hash.h"
8+
#include "internal/mem.h"
89
#include "internal/pystate.h"
910
#include "errcode.h"
1011
#include "marshal.h"

Python/pathconfig.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "Python.h"
44
#include "osdefs.h"
5+
#include "internal/mem.h"
56
#include "internal/pystate.h"
67
#include <wchar.h>
78

Python/pylifecycle.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#undef Yield /* undefine macro conflicting with winbase.h */
77
#include "internal/context.h"
88
#include "internal/hamt.h"
9+
#include "internal/mem.h"
910
#include "internal/pystate.h"
1011
#include "grammar.h"
1112
#include "node.h"

Python/pystate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Thread and interpreter state structures and their interfaces */
33

44
#include "Python.h"
5+
#include "internal/mem.h"
56
#include "internal/pystate.h"
67

78
#define _PyThreadState_SET(value) \

Python/sysmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Data members:
1515
*/
1616

1717
#include "Python.h"
18+
#include "internal/mem.h"
1819
#include "internal/pystate.h"
1920
#include "code.h"
2021
#include "frameobject.h"

0 commit comments

Comments
 (0)