From: Guido van Rossum Date: Tue, 5 Aug 1997 01:59:22 +0000 (+0000) Subject: Added Py_Malloc and friends as well as PyMem_Malloc and friends. X-Git-Tag: v1.5a3~148 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d085e88d3cb826fb144d4ca7544d247680d7a241;p=python Added Py_Malloc and friends as well as PyMem_Malloc and friends. --- diff --git a/Include/mymalloc.h b/Include/mymalloc.h index 944a4ddd52..e55fe7baab 100644 --- a/Include/mymalloc.h +++ b/Include/mymalloc.h @@ -58,8 +58,8 @@ PERFORMANCE OF THIS SOFTWARE. #endif #ifdef __cplusplus -// Move this down here since some C++ #include's don't like to be included -// inside an extern "C" +/* Move this down here since some C++ #include's don't like to be included + inside an extern "C" */ extern "C" { #endif @@ -97,6 +97,23 @@ extern void free Py_PROTO((ANY *)); /* XXX sometimes int on Unix old systems */ #define PyMem_DEL(p) free((ANY *)p) #define PyMem_XDEL(p) if ((p) == NULL) ; else PyMem_DEL(p) + +/* Two sets of function wrappers around malloc and friends; useful if + you need to be sure that you are using the same memory allocator as + Python. Note that the wrappers make sure that allocating 0 bytes + returns a non-NULL pointer, even if the underlying malloc doesn't. + The Python interpreter continues to use PyMem_NEW etc. */ + +/* These wrappers around malloc call PyErr_NoMemory() on failure */ +extern ANY *Py_Malloc Py_PROTO((size_t)); +extern ANY *Py_Realloc Py_PROTO((ANY *, size_t)); +extern void Py_Free Py_PROTO((ANY *)); + +/* These wrappers around malloc *don't* call anything on failure */ +extern ANY *PyMem_Malloc Py_PROTO((size_t)); +extern ANY *PyMem_Realloc Py_PROTO((ANY *, size_t)); +extern void PyMem_Free Py_PROTO((ANY *)); + #ifdef __cplusplus } #endif