blob: 0db53c312f07b744376beb0cd4b76b0c946355a3 [file] [log] [blame]
Victor Stinner6eb99662018-11-26 17:09:16 +01001#ifndef Py_CPYTHON_OBJECT_H
2# error "this header file must not be included directly"
3#endif
4
Victor Stinnerf58bd7c2020-02-05 13:12:19 +01005PyAPI_FUNC(void) _Py_NewReference(PyObject *op);
6
7#ifdef Py_TRACE_REFS
8/* Py_TRACE_REFS is such major surgery that we call external routines. */
9PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);
10#endif
11
Victor Stinnerf58bd7c2020-02-05 13:12:19 +010012#ifdef Py_REF_DEBUG
13PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
14#endif
15
16
Victor Stinner6eb99662018-11-26 17:09:16 +010017/********************* String Literals ****************************************/
18/* This structure helps managing static strings. The basic usage goes like this:
19 Instead of doing
20
21 r = PyObject_CallMethod(o, "foo", "args", ...);
22
23 do
24
25 _Py_IDENTIFIER(foo);
26 ...
27 r = _PyObject_CallMethodId(o, &PyId_foo, "args", ...);
28
29 PyId_foo is a static variable, either on block level or file level. On first
30 usage, the string "foo" is interned, and the structures are linked. On interpreter
Victor Stinnerd6fb53f2020-05-14 01:11:54 +020031 shutdown, all strings are released.
Victor Stinner6eb99662018-11-26 17:09:16 +010032
33 Alternatively, _Py_static_string allows choosing the variable name.
34 _PyUnicode_FromId returns a borrowed reference to the interned string.
35 _PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*.
36*/
37typedef struct _Py_Identifier {
38 struct _Py_Identifier *next;
39 const char* string;
40 PyObject *object;
41} _Py_Identifier;
42
43#define _Py_static_string_init(value) { .next = NULL, .string = value, .object = NULL }
44#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value)
45#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
46
47/* buffer interface */
48typedef struct bufferinfo {
49 void *buf;
50 PyObject *obj; /* owned reference */
51 Py_ssize_t len;
52 Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
53 pointed to by strides in simple case.*/
54 int readonly;
55 int ndim;
56 char *format;
57 Py_ssize_t *shape;
58 Py_ssize_t *strides;
59 Py_ssize_t *suboffsets;
60 void *internal;
61} Py_buffer;
62
63typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
64typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
65
Jeroen Demeyeraacc77f2019-05-29 20:31:52 +020066typedef PyObject *(*vectorcallfunc)(PyObject *callable, PyObject *const *args,
67 size_t nargsf, PyObject *kwnames);
68
Victor Stinner6eb99662018-11-26 17:09:16 +010069/* Maximum number of dimensions */
70#define PyBUF_MAX_NDIM 64
71
72/* Flags for getting buffers */
73#define PyBUF_SIMPLE 0
74#define PyBUF_WRITABLE 0x0001
75/* we used to include an E, backwards compatible alias */
76#define PyBUF_WRITEABLE PyBUF_WRITABLE
77#define PyBUF_FORMAT 0x0004
78#define PyBUF_ND 0x0008
79#define PyBUF_STRIDES (0x0010 | PyBUF_ND)
80#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
81#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
82#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
83#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
84
85#define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)
86#define PyBUF_CONTIG_RO (PyBUF_ND)
87
88#define PyBUF_STRIDED (PyBUF_STRIDES | PyBUF_WRITABLE)
89#define PyBUF_STRIDED_RO (PyBUF_STRIDES)
90
91#define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT)
92#define PyBUF_RECORDS_RO (PyBUF_STRIDES | PyBUF_FORMAT)
93
94#define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT)
95#define PyBUF_FULL_RO (PyBUF_INDIRECT | PyBUF_FORMAT)
96
97
98#define PyBUF_READ 0x100
99#define PyBUF_WRITE 0x200
100/* End buffer interface */
101
102
103typedef struct {
104 /* Number implementations must check *both*
105 arguments for proper type and implement the necessary conversions
106 in the slot functions themselves. */
107
108 binaryfunc nb_add;
109 binaryfunc nb_subtract;
110 binaryfunc nb_multiply;
111 binaryfunc nb_remainder;
112 binaryfunc nb_divmod;
113 ternaryfunc nb_power;
114 unaryfunc nb_negative;
115 unaryfunc nb_positive;
116 unaryfunc nb_absolute;
117 inquiry nb_bool;
118 unaryfunc nb_invert;
119 binaryfunc nb_lshift;
120 binaryfunc nb_rshift;
121 binaryfunc nb_and;
122 binaryfunc nb_xor;
123 binaryfunc nb_or;
124 unaryfunc nb_int;
125 void *nb_reserved; /* the slot formerly known as nb_long */
126 unaryfunc nb_float;
127
128 binaryfunc nb_inplace_add;
129 binaryfunc nb_inplace_subtract;
130 binaryfunc nb_inplace_multiply;
131 binaryfunc nb_inplace_remainder;
132 ternaryfunc nb_inplace_power;
133 binaryfunc nb_inplace_lshift;
134 binaryfunc nb_inplace_rshift;
135 binaryfunc nb_inplace_and;
136 binaryfunc nb_inplace_xor;
137 binaryfunc nb_inplace_or;
138
139 binaryfunc nb_floor_divide;
140 binaryfunc nb_true_divide;
141 binaryfunc nb_inplace_floor_divide;
142 binaryfunc nb_inplace_true_divide;
143
144 unaryfunc nb_index;
145
146 binaryfunc nb_matrix_multiply;
147 binaryfunc nb_inplace_matrix_multiply;
148} PyNumberMethods;
149
150typedef struct {
151 lenfunc sq_length;
152 binaryfunc sq_concat;
153 ssizeargfunc sq_repeat;
154 ssizeargfunc sq_item;
155 void *was_sq_slice;
156 ssizeobjargproc sq_ass_item;
157 void *was_sq_ass_slice;
158 objobjproc sq_contains;
159
160 binaryfunc sq_inplace_concat;
161 ssizeargfunc sq_inplace_repeat;
162} PySequenceMethods;
163
164typedef struct {
165 lenfunc mp_length;
166 binaryfunc mp_subscript;
167 objobjargproc mp_ass_subscript;
168} PyMappingMethods;
169
170typedef struct {
171 unaryfunc am_await;
172 unaryfunc am_aiter;
173 unaryfunc am_anext;
174} PyAsyncMethods;
175
176typedef struct {
177 getbufferproc bf_getbuffer;
178 releasebufferproc bf_releasebuffer;
179} PyBufferProcs;
180
Jeroen Demeyeraacc77f2019-05-29 20:31:52 +0200181/* Allow printfunc in the tp_vectorcall_offset slot for
182 * backwards-compatibility */
183typedef Py_ssize_t printfunc;
Victor Stinner6eb99662018-11-26 17:09:16 +0100184
Victor Stinnerf95cd192020-02-07 01:43:25 +0100185struct _typeobject {
Victor Stinner6eb99662018-11-26 17:09:16 +0100186 PyObject_VAR_HEAD
187 const char *tp_name; /* For printing, in format "<module>.<name>" */
188 Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
189
190 /* Methods to implement standard operations */
191
192 destructor tp_dealloc;
Jeroen Demeyeraacc77f2019-05-29 20:31:52 +0200193 Py_ssize_t tp_vectorcall_offset;
Victor Stinner6eb99662018-11-26 17:09:16 +0100194 getattrfunc tp_getattr;
195 setattrfunc tp_setattr;
196 PyAsyncMethods *tp_as_async; /* formerly known as tp_compare (Python 2)
197 or tp_reserved (Python 3) */
198 reprfunc tp_repr;
199
200 /* Method suites for standard classes */
201
202 PyNumberMethods *tp_as_number;
203 PySequenceMethods *tp_as_sequence;
204 PyMappingMethods *tp_as_mapping;
205
206 /* More standard operations (here for binary compatibility) */
207
208 hashfunc tp_hash;
209 ternaryfunc tp_call;
210 reprfunc tp_str;
211 getattrofunc tp_getattro;
212 setattrofunc tp_setattro;
213
214 /* Functions to access object as input/output buffer */
215 PyBufferProcs *tp_as_buffer;
216
217 /* Flags to define presence of optional/expanded features */
218 unsigned long tp_flags;
219
220 const char *tp_doc; /* Documentation string */
221
222 /* Assigned meaning in release 2.0 */
223 /* call function for all accessible objects */
224 traverseproc tp_traverse;
225
226 /* delete references to contained objects */
227 inquiry tp_clear;
228
229 /* Assigned meaning in release 2.1 */
230 /* rich comparisons */
231 richcmpfunc tp_richcompare;
232
233 /* weak reference enabler */
234 Py_ssize_t tp_weaklistoffset;
235
236 /* Iterators */
237 getiterfunc tp_iter;
238 iternextfunc tp_iternext;
239
240 /* Attribute descriptor and subclassing stuff */
241 struct PyMethodDef *tp_methods;
242 struct PyMemberDef *tp_members;
243 struct PyGetSetDef *tp_getset;
244 struct _typeobject *tp_base;
245 PyObject *tp_dict;
246 descrgetfunc tp_descr_get;
247 descrsetfunc tp_descr_set;
248 Py_ssize_t tp_dictoffset;
249 initproc tp_init;
250 allocfunc tp_alloc;
251 newfunc tp_new;
252 freefunc tp_free; /* Low-level free-memory routine */
253 inquiry tp_is_gc; /* For PyObject_IS_GC */
254 PyObject *tp_bases;
255 PyObject *tp_mro; /* method resolution order */
256 PyObject *tp_cache;
257 PyObject *tp_subclasses;
258 PyObject *tp_weaklist;
259 destructor tp_del;
260
261 /* Type attribute cache version tag. Added in version 2.6 */
262 unsigned int tp_version_tag;
263
264 destructor tp_finalize;
Jeroen Demeyeraacc77f2019-05-29 20:31:52 +0200265 vectorcallfunc tp_vectorcall;
Victor Stinnerf95cd192020-02-07 01:43:25 +0100266};
Victor Stinner6eb99662018-11-26 17:09:16 +0100267
268/* The *real* layout of a type object when allocated on the heap */
269typedef struct _heaptypeobject {
270 /* Note: there's a dependency on the order of these members
271 in slotptr() in typeobject.c . */
272 PyTypeObject ht_type;
273 PyAsyncMethods as_async;
274 PyNumberMethods as_number;
275 PyMappingMethods as_mapping;
276 PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
277 so that the mapping wins when both
278 the mapping and the sequence define
279 a given operator (e.g. __getitem__).
280 see add_operators() in typeobject.c . */
281 PyBufferProcs as_buffer;
282 PyObject *ht_name, *ht_slots, *ht_qualname;
283 struct _dictkeysobject *ht_cached_keys;
Petr Viktorine1becf42020-05-07 15:39:59 +0200284 PyObject *ht_module;
Victor Stinner6eb99662018-11-26 17:09:16 +0100285 /* here are optional user slots, followed by the members. */
286} PyHeapTypeObject;
287
288/* access macro to the members which are floating "behind" the object */
289#define PyHeapType_GET_MEMBERS(etype) \
290 ((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))
291
292PyAPI_FUNC(const char *) _PyType_Name(PyTypeObject *);
293PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
294PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *);
295PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, _Py_Identifier *);
296PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
297PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *);
298PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *);
Petr Viktorin57aaaa82020-11-03 22:27:12 +0100299struct PyModuleDef;
300PyAPI_FUNC(PyObject *) _PyType_GetModuleByDef(PyTypeObject *, struct PyModuleDef *);
Victor Stinner6eb99662018-11-26 17:09:16 +0100301
302struct _Py_Identifier;
303PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
304PyAPI_FUNC(void) _Py_BreakPoint(void);
305PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
306PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
307
308PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *);
309PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *);
310PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *);
Victor Stinner6eb99662018-11-26 17:09:16 +0100311/* Replacements of PyObject_GetAttr() and _PyObject_GetAttrId() which
312 don't raise AttributeError.
313
314 Return 1 and set *result != NULL if an attribute is found.
315 Return 0 and set *result == NULL if an attribute is not found;
316 an AttributeError is silenced.
317 Return -1 and set *result == NULL if an error other than AttributeError
318 is raised.
319*/
320PyAPI_FUNC(int) _PyObject_LookupAttr(PyObject *, PyObject *, PyObject **);
321PyAPI_FUNC(int) _PyObject_LookupAttrId(PyObject *, struct _Py_Identifier *, PyObject **);
Jeroen Demeyerb2f94732019-06-14 12:37:15 +0200322
323PyAPI_FUNC(int) _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);
324
Victor Stinner6eb99662018-11-26 17:09:16 +0100325PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
326PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);
327PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *);
328PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *);
329
330/* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes
331 dict as the last parameter. */
332PyAPI_FUNC(PyObject *)
333_PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *, int);
334PyAPI_FUNC(int)
335_PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
336 PyObject *, PyObject *);
337
Jeroen Demeyerbf17d412019-11-05 16:48:04 +0100338PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *);
Victor Stinner6eb99662018-11-26 17:09:16 +0100339
340/* Safely decref `op` and set `op` to `op2`.
341 *
342 * As in case of Py_CLEAR "the obvious" code can be deadly:
343 *
344 * Py_DECREF(op);
345 * op = op2;
346 *
347 * The safe way is:
348 *
349 * Py_SETREF(op, op2);
350 *
351 * That arranges to set `op` to `op2` _before_ decref'ing, so that any code
352 * triggered as a side-effect of `op` getting torn down no longer believes
353 * `op` points to a valid object.
354 *
355 * Py_XSETREF is a variant of Py_SETREF that uses Py_XDECREF instead of
356 * Py_DECREF.
357 */
358
359#define Py_SETREF(op, op2) \
360 do { \
361 PyObject *_py_tmp = _PyObject_CAST(op); \
362 (op) = (op2); \
363 Py_DECREF(_py_tmp); \
364 } while (0)
365
366#define Py_XSETREF(op, op2) \
367 do { \
368 PyObject *_py_tmp = _PyObject_CAST(op); \
369 (op) = (op2); \
370 Py_XDECREF(_py_tmp); \
371 } while (0)
372
373
374PyAPI_DATA(PyTypeObject) _PyNone_Type;
375PyAPI_DATA(PyTypeObject) _PyNotImplemented_Type;
376
377/* Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.
378 * Defined in object.c.
379 */
380PyAPI_DATA(int) _Py_SwappedOp[];
381
Victor Stinner6eb99662018-11-26 17:09:16 +0100382PyAPI_FUNC(void)
383_PyDebugAllocatorStats(FILE *out, const char *block_name, int num_blocks,
384 size_t sizeof_block);
385PyAPI_FUNC(void)
386_PyObject_DebugTypeStats(FILE *out);
387
388/* Define a pair of assertion macros:
389 _PyObject_ASSERT_FROM(), _PyObject_ASSERT_WITH_MSG() and _PyObject_ASSERT().
390
391 These work like the regular C assert(), in that they will abort the
392 process with a message on stderr if the given condition fails to hold,
393 but compile away to nothing if NDEBUG is defined.
394
395 However, before aborting, Python will also try to call _PyObject_Dump() on
396 the given object. This may be of use when investigating bugs in which a
397 particular object is corrupt (e.g. buggy a tp_visit method in an extension
398 module breaking the garbage collector), to help locate the broken objects.
399
400 The WITH_MSG variant allows you to supply an additional message that Python
401 will attempt to print to stderr, after the object dump. */
402#ifdef NDEBUG
403 /* No debugging: compile away the assertions: */
404# define _PyObject_ASSERT_FROM(obj, expr, msg, filename, lineno, func) \
405 ((void)0)
406#else
407 /* With debugging: generate checks: */
408# define _PyObject_ASSERT_FROM(obj, expr, msg, filename, lineno, func) \
409 ((expr) \
410 ? (void)(0) \
411 : _PyObject_AssertFailed((obj), Py_STRINGIFY(expr), \
412 (msg), (filename), (lineno), (func)))
413#endif
414
415#define _PyObject_ASSERT_WITH_MSG(obj, expr, msg) \
416 _PyObject_ASSERT_FROM(obj, expr, msg, __FILE__, __LINE__, __func__)
417#define _PyObject_ASSERT(obj, expr) \
418 _PyObject_ASSERT_WITH_MSG(obj, expr, NULL)
419
420#define _PyObject_ASSERT_FAILED_MSG(obj, msg) \
421 _PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
422
423/* Declare and define _PyObject_AssertFailed() even when NDEBUG is defined,
424 to avoid causing compiler/linker errors when building extensions without
425 NDEBUG against a Python built with NDEBUG defined.
426
427 msg, expr and function can be NULL. */
Victor Stinner2a4903f2020-01-30 13:09:11 +0100428PyAPI_FUNC(void) _Py_NO_RETURN _PyObject_AssertFailed(
Victor Stinner6eb99662018-11-26 17:09:16 +0100429 PyObject *obj,
430 const char *expr,
431 const char *msg,
432 const char *file,
433 int line,
434 const char *function);
435
Victor Stinner0fc91ee2019-04-12 21:51:34 +0200436/* Check if an object is consistent. For example, ensure that the reference
437 counter is greater than or equal to 1, and ensure that ob_type is not NULL.
438
439 Call _PyObject_AssertFailed() if the object is inconsistent.
440
441 If check_content is zero, only check header fields: reduce the overhead.
442
443 The function always return 1. The return value is just here to be able to
444 write:
445
446 assert(_PyObject_CheckConsistency(obj, 1)); */
447PyAPI_FUNC(int) _PyObject_CheckConsistency(
448 PyObject *op,
449 int check_content);
450
Victor Stinner0fa4f432020-02-05 12:23:27 +0100451
452/* Trashcan mechanism, thanks to Christian Tismer.
453
454When deallocating a container object, it's possible to trigger an unbounded
455chain of deallocations, as each Py_DECREF in turn drops the refcount on "the
456next" object in the chain to 0. This can easily lead to stack overflows,
457especially in threads (which typically have less stack space to work with).
458
459A container object can avoid this by bracketing the body of its tp_dealloc
460function with a pair of macros:
461
462static void
463mytype_dealloc(mytype *p)
464{
465 ... declarations go here ...
466
467 PyObject_GC_UnTrack(p); // must untrack first
468 Py_TRASHCAN_BEGIN(p, mytype_dealloc)
469 ... The body of the deallocator goes here, including all calls ...
470 ... to Py_DECREF on contained objects. ...
471 Py_TRASHCAN_END // there should be no code after this
472}
473
474CAUTION: Never return from the middle of the body! If the body needs to
475"get out early", put a label immediately before the Py_TRASHCAN_END
476call, and goto it. Else the call-depth counter (see below) will stay
477above 0 forever, and the trashcan will never get emptied.
478
479How it works: The BEGIN macro increments a call-depth counter. So long
480as this counter is small, the body of the deallocator is run directly without
481further ado. But if the counter gets large, it instead adds p to a list of
482objects to be deallocated later, skips the body of the deallocator, and
483resumes execution after the END macro. The tp_dealloc routine then returns
484without deallocating anything (and so unbounded call-stack depth is avoided).
485
486When the call stack finishes unwinding again, code generated by the END macro
487notices this, and calls another routine to deallocate all the objects that
488may have been added to the list of deferred deallocations. In effect, a
489chain of N deallocations is broken into (N-1)/(PyTrash_UNWIND_LEVEL-1) pieces,
490with the call stack never exceeding a depth of PyTrash_UNWIND_LEVEL.
491
492Since the tp_dealloc of a subclass typically calls the tp_dealloc of the base
493class, we need to ensure that the trashcan is only triggered on the tp_dealloc
494of the actual class being deallocated. Otherwise we might end up with a
495partially-deallocated object. To check this, the tp_dealloc function must be
496passed as second argument to Py_TRASHCAN_BEGIN().
497*/
498
Victor Stinner38965ec2020-03-13 16:51:52 +0100499/* This is the old private API, invoked by the macros before 3.2.4.
500 Kept for binary compatibility of extensions using the stable ABI. */
501PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*);
502PyAPI_FUNC(void) _PyTrash_destroy_chain(void);
503
504/* This is the old private API, invoked by the macros before 3.9.
505 Kept for binary compatibility of extensions using the stable ABI. */
Victor Stinner0fa4f432020-02-05 12:23:27 +0100506PyAPI_FUNC(void) _PyTrash_thread_deposit_object(PyObject*);
507PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void);
508
Victor Stinner38965ec2020-03-13 16:51:52 +0100509/* Forward declarations for PyThreadState */
510struct _ts;
511
512/* Python 3.9 private API, invoked by the macros below. */
513PyAPI_FUNC(int) _PyTrash_begin(struct _ts *tstate, PyObject *op);
514PyAPI_FUNC(void) _PyTrash_end(struct _ts *tstate);
515
Victor Stinner0fa4f432020-02-05 12:23:27 +0100516#define PyTrash_UNWIND_LEVEL 50
517
518#define Py_TRASHCAN_BEGIN_CONDITION(op, cond) \
519 do { \
520 PyThreadState *_tstate = NULL; \
521 /* If "cond" is false, then _tstate remains NULL and the deallocator \
522 * is run normally without involving the trashcan */ \
523 if (cond) { \
524 _tstate = PyThreadState_GET(); \
Victor Stinner38965ec2020-03-13 16:51:52 +0100525 if (_PyTrash_begin(_tstate, _PyObject_CAST(op))) { \
Victor Stinner0fa4f432020-02-05 12:23:27 +0100526 break; \
527 } \
Victor Stinner0fa4f432020-02-05 12:23:27 +0100528 }
529 /* The body of the deallocator is here. */
530#define Py_TRASHCAN_END \
531 if (_tstate) { \
Victor Stinner38965ec2020-03-13 16:51:52 +0100532 _PyTrash_end(_tstate); \
Victor Stinner0fa4f432020-02-05 12:23:27 +0100533 } \
534 } while (0);
535
Victor Stinner38965ec2020-03-13 16:51:52 +0100536#define Py_TRASHCAN_BEGIN(op, dealloc) \
537 Py_TRASHCAN_BEGIN_CONDITION(op, \
Victor Stinner0fa4f432020-02-05 12:23:27 +0100538 Py_TYPE(op)->tp_dealloc == (destructor)(dealloc))
539
540/* For backwards compatibility, these macros enable the trashcan
541 * unconditionally */
542#define Py_TRASHCAN_SAFE_BEGIN(op) Py_TRASHCAN_BEGIN_CONDITION(op, 1)
543#define Py_TRASHCAN_SAFE_END(op) Py_TRASHCAN_END