summaryrefslogtreecommitdiff
path: root/Cython
diff options
context:
space:
mode:
authorJohn Kirkham <kirkhamj@janelia.hhmi.org>2018-08-07 17:00:43 -0400
committerJohn Kirkham <kirkhamj@janelia.hhmi.org>2018-08-09 14:39:59 -0400
commit8d324dfd3da2c38292f6312b299ecaa843b2fd00 (patch)
treeb887bf6a63b217b35724e842e5cf989d44212428 /Cython
parent9fbbf21650abf0cad2d4d7dae66361d0db8ab6ad (diff)
downloadcython-8d324dfd3da2c38292f6312b299ecaa843b2fd00.tar.gz
Define Python Raw Mem helpers in ModuleSetupCode
To handle the Python version differences, handle the definitions of `PyMem_Raw*` functions in `ModuleSetupCode`. Then extern them in `cpython.mem` without using a version check or a specific header.
Diffstat (limited to 'Cython')
-rw-r--r--Cython/Includes/cpython/mem.pxd14
-rw-r--r--Cython/Utility/ModuleSetupCode.c6
2 files changed, 11 insertions, 9 deletions
diff --git a/Cython/Includes/cpython/mem.pxd b/Cython/Includes/cpython/mem.pxd
index ba77bc283..75ab56f21 100644
--- a/Cython/Includes/cpython/mem.pxd
+++ b/Cython/Includes/cpython/mem.pxd
@@ -1,5 +1,10 @@
from cpython.version cimport PY_VERSION_HEX
+cdef extern from *:
+ void* PyMem_RawMalloc(size_t n) nogil
+ void* PyMem_RawRealloc(void *p, size_t n) nogil
+ void PyMem_RawFree(void *p) nogil
+
cdef extern from "Python.h":
#####################################################################
@@ -24,15 +29,6 @@ cdef extern from "Python.h":
# for the I/O buffer escapes completely the Python memory
# manager."
- IF PY_VERSION_HEX >= 0x03040000:
- void* PyMem_RawMalloc(size_t n) nogil
- void* PyMem_RawRealloc(void *p, size_t n) nogil
- void PyMem_RawFree(void *p) nogil
- ELSE:
- void* PyMem_RawMalloc "PyMem_Malloc" (size_t n) nogil
- void* PyMem_RawRealloc "PyMem_Realloc" (void *p, size_t n) nogil
- void PyMem_RawFree "PyMem_Free" (void *p) nogil
-
# The following function sets, modeled after the ANSI C standard,
# but specifying behavior when requesting zero bytes, are
# available for allocating and releasing memory from the Python
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c
index ac6264574..9f7e3d875 100644
--- a/Cython/Utility/ModuleSetupCode.c
+++ b/Cython/Utility/ModuleSetupCode.c
@@ -441,6 +441,12 @@ class __Pyx_FakeReference {
#define PyObject_Realloc(p) PyMem_Realloc(p)
#endif
+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x03040000
+ #define PyMem_RawMalloc(n) PyMem_Malloc(n)
+ #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n)
+ #define PyMem_RawFree(p) PyMem_Free(p)
+#endif
+
#if CYTHON_COMPILING_IN_PYSTON
// special C-API functions only in Pyston
#define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)