[Python-checkins] bpo-35081: Move Py_BUILD_CORE code to internal/mem.h (GH-10249)

Victor Stinner webhook-mailer at python.org
Wed Oct 31 15:19:34 EDT 2018


https://github.com/python/cpython/commit/2be00d987d37682a55db67c298e82c405d01b868
commit: 2be00d987d37682a55db67c298e82c405d01b868
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-10-31T20:19:24+01:00
summary:

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.

files:
M Include/internal/mem.h
M Include/pymem.h
M Modules/main.c
M Objects/obmalloc.c
M Python/coreconfig.c
M Python/import.c
M Python/pathconfig.c
M Python/pylifecycle.c
M Python/pystate.c
M Python/sysmodule.c

diff --git a/Include/internal/mem.h b/Include/internal/mem.h
index a731e30e6af7..4a41b77734ac 100644
--- a/Include/internal/mem.h
+++ b/Include/internal/mem.h
@@ -4,6 +4,10 @@
 extern "C" {
 #endif
 
+#ifndef Py_BUILD_CORE
+#  error "Py_BUILD_CORE must be defined to include this header"
+#endif
+
 #include "objimpl.h"
 #include "pymem.h"
 
@@ -145,6 +149,14 @@ PyAPI_FUNC(void) _PyGC_Initialize(struct _gc_runtime_state *);
 
 #define _PyGC_generation0 _PyRuntime.gc.generation0
 
+
+/* 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. */
+PyAPI_FUNC(int) _PyMem_SetDefaultAllocator(
+    PyMemAllocatorDomain domain,
+    PyMemAllocatorEx *old_alloc);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/Include/pymem.h b/Include/pymem.h
index 19f0c8a2d9bf..23457adb5a45 100644
--- a/Include/pymem.h
+++ b/Include/pymem.h
@@ -198,16 +198,6 @@ PyAPI_FUNC(void) PyMem_SetAllocator(PyMemAllocatorDomain domain,
 PyAPI_FUNC(void) PyMem_SetupDebugHooks(void);
 #endif   /* Py_LIMITED_API */
 
-#ifdef Py_BUILD_CORE
-/* 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. */
-PyAPI_FUNC(int) _PyMem_SetDefaultAllocator(
-    PyMemAllocatorDomain domain,
-    PyMemAllocatorEx *old_alloc);
-#endif
-
-
 /* bpo-35053: expose _Py_tracemalloc_config for performance:
    _Py_NewReference() needs an efficient check to test if tracemalloc is
    tracing.
diff --git a/Modules/main.c b/Modules/main.c
index 455178af8bab..6a8aa05fc370 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -2,6 +2,7 @@
 
 #include "Python.h"
 #include "osdefs.h"
+#include "internal/mem.h"
 #include "internal/pygetopt.h"
 #include "internal/pystate.h"
 
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index fbc947806908..88ded83a29e4 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -1,4 +1,5 @@
 #include "Python.h"
+#include "internal/mem.h"
 
 #include <stdbool.h>
 
diff --git a/Python/coreconfig.c b/Python/coreconfig.c
index a82175e4fd26..81086f42d679 100644
--- a/Python/coreconfig.c
+++ b/Python/coreconfig.c
@@ -1,4 +1,5 @@
 #include "Python.h"
+#include "internal/mem.h"
 #include "internal/pystate.h"
 #include <locale.h>
 #ifdef HAVE_LANGINFO_H
diff --git a/Python/import.c b/Python/import.c
index e761f65c66ba..338cd302dcc0 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -5,6 +5,7 @@
 #include "Python-ast.h"
 #undef Yield /* undefine macro conflicting with winbase.h */
 #include "internal/hash.h"
+#include "internal/mem.h"
 #include "internal/pystate.h"
 #include "errcode.h"
 #include "marshal.h"
diff --git a/Python/pathconfig.c b/Python/pathconfig.c
index 4e0830f4cf9a..efccb8d6bb85 100644
--- a/Python/pathconfig.c
+++ b/Python/pathconfig.c
@@ -2,6 +2,7 @@
 
 #include "Python.h"
 #include "osdefs.h"
+#include "internal/mem.h"
 #include "internal/pystate.h"
 #include <wchar.h>
 
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index f1579c781df7..78691a54f37f 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -6,6 +6,7 @@
 #undef Yield /* undefine macro conflicting with winbase.h */
 #include "internal/context.h"
 #include "internal/hamt.h"
+#include "internal/mem.h"
 #include "internal/pystate.h"
 #include "grammar.h"
 #include "node.h"
diff --git a/Python/pystate.c b/Python/pystate.c
index d04981121c1c..98e954d9d91d 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -2,6 +2,7 @@
 /* Thread and interpreter state structures and their interfaces */
 
 #include "Python.h"
+#include "internal/mem.h"
 #include "internal/pystate.h"
 
 #define _PyThreadState_SET(value) \
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 9579eae4ff5f..71414c959789 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -15,6 +15,7 @@ Data members:
 */
 
 #include "Python.h"
+#include "internal/mem.h"
 #include "internal/pystate.h"
 #include "code.h"
 #include "frameobject.h"



More information about the Python-checkins mailing list