Commit 0da92b56 authored by scoder's avatar scoder Committed by GitHub

Merge pull request #2537 from jakirkham/extern_py_raw_mem

Add Python Raw memory helper functions
parents 0f3ec28f fb158252
from cpython.version cimport PY_VERSION_HEX
cdef extern from "Python.h":
#####################################################################
......@@ -27,6 +29,7 @@ cdef extern from "Python.h":
# available for allocating and releasing memory from the Python
# heap:
void* PyMem_RawMalloc(size_t n) nogil
void* PyMem_Malloc(size_t n)
# Allocates n bytes and returns a pointer of type void* to the
# allocated memory, or NULL if the request fails. Requesting zero
......@@ -34,6 +37,7 @@ cdef extern from "Python.h":
# PyMem_Malloc(1) had been called instead. The memory will not
# have been initialized in any way.
void* PyMem_RawRealloc(void *p, size_t n) nogil
void* PyMem_Realloc(void *p, size_t n)
# Resizes the memory block pointed to by p to n bytes. The
# contents will be unchanged to the minimum of the old and the new
......@@ -43,6 +47,7 @@ cdef extern from "Python.h":
# NULL, it must have been returned by a previous call to
# PyMem_Malloc() or PyMem_Realloc().
void PyMem_RawFree(void *p) nogil
void PyMem_Free(void *p)
# Frees the memory block pointed to by p, which must have been
# returned by a previous call to PyMem_Malloc() or
......
......@@ -439,6 +439,12 @@ class __Pyx_FakeReference {
#define PyObject_Realloc(p) PyMem_Realloc(p)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
#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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment