object.h 19 KB

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