mirror of
https://github.com/python/cpython.git
synced 2026-01-04 14:32:21 +00:00
gh-85283: Add PyMem_RawMalloc() to the limited C API (#108570)
Add PyMem_RawMalloc(), PyMem_RawCalloc(), PyMem_RawRealloc() and PyMem_RawFree() to the limited C API. These functions were added by Python 3.4 and are needed to port stdlib extensions to the limited C API, like grp and pwd. Co-authored-by: Erlend E. Aasland <erlend@python.org>
This commit is contained in:
parent
cf9c25c719
commit
cc71cc9256
8 changed files with 39 additions and 6 deletions
|
|
@ -2,12 +2,6 @@
|
|||
# error "this header file must not be included directly"
|
||||
#endif
|
||||
|
||||
PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size);
|
||||
PyAPI_FUNC(void *) PyMem_RawCalloc(size_t nelem, size_t elsize);
|
||||
PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size);
|
||||
PyAPI_FUNC(void) PyMem_RawFree(void *ptr);
|
||||
|
||||
|
||||
typedef enum {
|
||||
/* PyMem_RawMalloc(), PyMem_RawRealloc() and PyMem_RawFree() */
|
||||
PYMEM_DOMAIN_RAW,
|
||||
|
|
|
|||
|
|
@ -87,6 +87,17 @@ PyAPI_FUNC(void) PyMem_Free(void *ptr);
|
|||
#define PyMem_DEL(p) PyMem_Free((p))
|
||||
|
||||
|
||||
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
|
||||
// Memory allocator which doesn't require the GIL to be held.
|
||||
// Usually, it's just a thin wrapper to functions of the standard C library:
|
||||
// malloc(), calloc(), realloc() and free(). The difference is that
|
||||
// tracemalloc can track these memory allocations.
|
||||
PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size);
|
||||
PyAPI_FUNC(void *) PyMem_RawCalloc(size_t nelem, size_t elsize);
|
||||
PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size);
|
||||
PyAPI_FUNC(void) PyMem_RawFree(void *ptr);
|
||||
#endif
|
||||
|
||||
#ifndef Py_LIMITED_API
|
||||
# define Py_CPYTHON_PYMEM_H
|
||||
# include "cpython/pymem.h"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue