Debian Codegraph @

pypy/module/cpyext/include/pymem.h

raw symbols SCIP
1 #include <stdlib.h>
2
3 #ifndef Py_PYMEM_H
4 #define Py_PYMEM_H
5
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
10 #ifndef Py_LIMITED_API
11 PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size);
12 PyAPI_FUNC(void *) PyMem_RawCalloc(size_t nelem, size_t elsize);
13 PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size);
14 PyAPI_FUNC(void) PyMem_RawFree(void *ptr);
15 #endif
16
17 PyAPI_FUNC(void *) PyMem_Malloc(size_t size);
18 PyAPI_FUNC(void *) PyMem_Calloc(size_t nelem, size_t elsize);
19 PyAPI_FUNC(void *) PyMem_Realloc(void *ptr, size_t new_size);
20 PyAPI_FUNC(void) PyMem_Free(void *ptr);
21
22 #define PyMem_MALLOC(n) PyMem_Malloc(n)
23 #define PyMem_REALLOC(p, n) PyMem_Realloc(p, n)
24 #define PyMem_FREE(p) PyMem_Free(p)
25
26
27 /*
28 * Type-oriented memory interface
29 * ==============================
30 *
31 * Allocate memory for n objects of the given type. Returns a new pointer
32 * or NULL if the request was too large or memory allocation failed. Use
33 * these macros rather than doing the multiplication yourself so that proper
34 * overflow checking is always done.
35 */
36
37 #define PyMem_New(type, n) \
38 ( ((n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL : \
39 ( (type *) PyMem_Malloc((n) * sizeof(type)) ) )
40 #define PyMem_NEW(type, n) \
41 ( ((n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL : \
42 ( (type *) PyMem_MALLOC((n) * sizeof(type)) ) )
43
44 /*
45 * The value of (p) is always clobbered by this macro regardless of success.
46 * The caller MUST check if (p) is NULL afterwards and deal with the memory
47 * error if so. This means the original value of (p) MUST be saved for the
48 * caller's memory error handler to not lose track of it.
49 */
50 #define PyMem_Resize(p, type, n) \
51 ( (p) = ((n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL : \
52 (type *) PyMem_Realloc((p), (n) * sizeof(type)) )
53 #define PyMem_RESIZE(p, type, n) \
54 ( (p) = ((n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL : \
55 (type *) PyMem_REALLOC((p), (n) * sizeof(type)) )
56
57 /* PyMem{Del,DEL} are left over from ancient days, and shouldn't be used
58 * anymore. They're just confusing aliases for PyMem_{Free,FREE} now.
59 */
60 #define PyMem_Del PyMem_Free
61 #define PyMem_DEL PyMem_FREE
62
63
64 /* From CPython 3.6, with a different goal. PyTraceMalloc_Track()
65 * is equivalent to __pypy__.add_memory_pressure(size); it works with
66 * or without the GIL. PyTraceMalloc_Untrack() is an empty stub.
67 * From CPython 3.7 these are public API functions
68 *
69 * #if defined(PYPY_TRACEMALLOC) || \
70 * (PY_VERSION_HEX >= 0x03060000 && !defined(Py_LIMITED_API))
71 */
72 #define PYPY_TRACEMALLOC 1
73
74 PyAPI_FUNC(int) PyTraceMalloc_Track(
75 unsigned int domain,
76 uintptr_t ptr,
77 size_t size);
78
79 PyAPI_FUNC(int) PyTraceMalloc_Untrack(
80 unsigned int domain,
81 uintptr_t ptr);
82
83
84 #ifdef __cplusplus
85 }
86 #endif
87
88 #endif /* !Py_PYMEM_H */