104 #ifdef PYMALLOC_DEBUG
105 PyAPI_FUNC(
void *) _PyObject_DebugMalloc(
size_t nbytes);
106 PyAPI_FUNC(
void *) _PyObject_DebugRealloc(
void *
p,
size_t nbytes);
107 PyAPI_FUNC(
void) _PyObject_DebugFree(
void *p);
108 PyAPI_FUNC(
void) _PyObject_DebugDumpAddress(const
void *p);
109 PyAPI_FUNC(
void) _PyObject_DebugCheckAddress(const
void *p);
110 PyAPI_FUNC(
void) _PyObject_DebugMallocStats(
void);
111 PyAPI_FUNC(
void *) _PyObject_DebugMallocApi(
char api,
size_t nbytes);
112 PyAPI_FUNC(
void *) _PyObject_DebugReallocApi(
char api,
void *p,
size_t nbytes);
113 PyAPI_FUNC(
void) _PyObject_DebugFreeApi(
char api,
void *p);
114 PyAPI_FUNC(
void) _PyObject_DebugCheckAddressApi(
char api, const
void *p);
115 PyAPI_FUNC(
void *) _PyMem_DebugMalloc(
size_t nbytes);
116 PyAPI_FUNC(
void *) _PyMem_DebugRealloc(
void *p,
size_t nbytes);
118 #define PyObject_MALLOC _PyObject_DebugMalloc
119 #define PyObject_Malloc _PyObject_DebugMalloc
120 #define PyObject_REALLOC _PyObject_DebugRealloc
121 #define PyObject_Realloc _PyObject_DebugRealloc
122 #define PyObject_FREE _PyObject_DebugFree
123 #define PyObject_Free _PyObject_DebugFree
126 #define PyObject_MALLOC PyObject_Malloc
127 #define PyObject_REALLOC PyObject_Realloc
128 #define PyObject_FREE PyObject_Free
132 #define PyObject_MALLOC PyMem_MALLOC
133 #define PyObject_REALLOC PyMem_REALLOC
134 #define PyObject_FREE PyMem_FREE
138 #define PyObject_Del PyObject_Free
139 #define PyObject_DEL PyObject_FREE
142 #define _PyObject_Del PyObject_Free
153 PyAPI_FUNC(PyObject *) _PyObject_New(PyTypeObject *);
156 #define PyObject_New(type, typeobj) \
157 ( (type *) _PyObject_New(typeobj) )
158 #define PyObject_NewVar(type, typeobj, n) \
159 ( (type *) _PyObject_NewVar((typeobj), (n)) )
163 #define PyObject_INIT(op, typeobj) \
164 ( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
165 #define PyObject_INIT_VAR(op, typeobj, size) \
166 ( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) )
168 #define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
180 #if ((SIZEOF_VOID_P - 1) & SIZEOF_VOID_P) != 0
181 # error "_PyObject_VAR_SIZE requires SIZEOF_VOID_P be a power of 2"
184 #define _PyObject_VAR_SIZE(typeobj, nitems) \
186 ( ( (typeobj)->tp_basicsize + \
187 (nitems)*(typeobj)->tp_itemsize + \
188 (SIZEOF_VOID_P - 1) \
189 ) & ~(SIZEOF_VOID_P - 1) \
192 #define PyObject_NEW(type, typeobj) \
193 ( (type *) PyObject_Init( \
194 (PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) )
196 #define PyObject_NEW_VAR(type, typeobj, n) \
197 ( (type *) PyObject_InitVar( \
198 (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE((typeobj),(n)) ),\
238 #define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
241 #define PyObject_IS_GC(o) (PyType_IS_GC(Py_TYPE(o)) && \
242 (Py_TYPE(o)->tp_is_gc == NULL || Py_TYPE(o)->tp_is_gc(o)))
244 PyAPI_FUNC(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, Py_ssize_t);
245 #define PyObject_GC_Resize(type, op, n) \
246 ( (type *) _PyObject_GC_Resize((PyVarObject *)(op), (n)) )
249 #define _PyObject_GC_Del PyObject_GC_Del
263 #define _Py_AS_GC(o) ((PyGC_Head *)(o)-1)
265 #define _PyGC_REFS_UNTRACKED (-2)
266 #define _PyGC_REFS_REACHABLE (-3)
267 #define _PyGC_REFS_TENTATIVELY_UNREACHABLE (-4)
271 #define _PyObject_GC_TRACK(o) do { \
272 PyGC_Head *g = _Py_AS_GC(o); \
273 if (g->gc.gc_refs != _PyGC_REFS_UNTRACKED) \
274 Py_FatalError("GC object already tracked"); \
275 g->gc.gc_refs = _PyGC_REFS_REACHABLE; \
276 g->gc.gc_next = _PyGC_generation0; \
277 g->gc.gc_prev = _PyGC_generation0->gc.gc_prev; \
278 g->gc.gc_prev->gc.gc_next = g; \
279 _PyGC_generation0->gc.gc_prev = g; \
286 #define _PyObject_GC_UNTRACK(o) do { \
287 PyGC_Head *g = _Py_AS_GC(o); \
288 assert(g->gc.gc_refs != _PyGC_REFS_UNTRACKED); \
289 g->gc.gc_refs = _PyGC_REFS_UNTRACKED; \
290 g->gc.gc_prev->gc.gc_next = g->gc.gc_next; \
291 g->gc.gc_next->gc.gc_prev = g->gc.gc_prev; \
292 g->gc.gc_next = NULL; \
296 #define _PyObject_GC_IS_TRACKED(o) \
297 ((_Py_AS_GC(o))->gc.gc_refs != _PyGC_REFS_UNTRACKED)
301 #define _PyObject_GC_MAY_BE_TRACKED(obj) \
302 (PyObject_IS_GC(obj) && \
303 (!PyTuple_CheckExact(obj) || _PyObject_GC_IS_TRACKED(obj)))
306 PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(
size_t);
307 PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *);
308 PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t);
313 #define PyObject_GC_New(type, typeobj) \
314 ( (type *) _PyObject_GC_New(typeobj) )
315 #define PyObject_GC_NewVar(type, typeobj, n) \
316 ( (type *) _PyObject_GC_NewVar((typeobj), (n)) )
324 #define Py_VISIT(op) \
327 int vret = visit((PyObject *)(op), arg); \
336 #define PyGC_HEAD_SIZE 0
337 #define PyObject_GC_Init(op)
338 #define PyObject_GC_Fini(op)
339 #define PyObject_AS_GC(op) (op)
340 #define PyObject_FROM_GC(op) (op)
344 #define PyType_SUPPORTS_WEAKREFS(t) \
345 (PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) \
346 && ((t)->tp_weaklistoffset > 0))
348 #define PyObject_GET_WEAKREFS_LISTPTR(o) \
349 ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset))