@@ -385,11 +385,6 @@ PyAPI_DATA(PyTypeObject) _PyNotImplemented_Type;
385
385
*/
386
386
PyAPI_DATA (int ) _Py_SwappedOp [];
387
387
388
- /* This is the old private API, invoked by the macros before 3.2.4.
389
- Kept for binary compatibility of extensions using the stable ABI. */
390
- PyAPI_FUNC (void ) _PyTrash_deposit_object (PyObject * );
391
- PyAPI_FUNC (void ) _PyTrash_destroy_chain (void );
392
-
393
388
PyAPI_FUNC (void )
394
389
_PyDebugAllocatorStats (FILE * out , const char * block_name , int num_blocks ,
395
390
size_t sizeof_block );
@@ -507,10 +502,23 @@ partially-deallocated object. To check this, the tp_dealloc function must be
507
502
passed as second argument to Py_TRASHCAN_BEGIN().
508
503
*/
509
504
510
- /* The new thread-safe private API, invoked by the macros below. */
505
+ /* This is the old private API, invoked by the macros before 3.2.4.
506
+ Kept for binary compatibility of extensions using the stable ABI. */
507
+ PyAPI_FUNC (void ) _PyTrash_deposit_object (PyObject * );
508
+ PyAPI_FUNC (void ) _PyTrash_destroy_chain (void );
509
+
510
+ /* This is the old private API, invoked by the macros before 3.9.
511
+ Kept for binary compatibility of extensions using the stable ABI. */
511
512
PyAPI_FUNC (void ) _PyTrash_thread_deposit_object (PyObject * );
512
513
PyAPI_FUNC (void ) _PyTrash_thread_destroy_chain (void );
513
514
515
+ /* Forward declarations for PyThreadState */
516
+ struct _ts ;
517
+
518
+ /* Python 3.9 private API, invoked by the macros below. */
519
+ PyAPI_FUNC (int ) _PyTrash_begin (struct _ts * tstate , PyObject * op );
520
+ PyAPI_FUNC (void ) _PyTrash_end (struct _ts * tstate );
521
+
514
522
#define PyTrash_UNWIND_LEVEL 50
515
523
516
524
#define Py_TRASHCAN_BEGIN_CONDITION (op , cond ) \
@@ -520,24 +528,19 @@ PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void);
520
528
* is run normally without involving the trashcan */ \
521
529
if (cond ) { \
522
530
_tstate = PyThreadState_GET (); \
523
- if (_tstate -> trash_delete_nesting >= PyTrash_UNWIND_LEVEL ) { \
524
- /* Store the object (to be deallocated later) and jump past \
525
- * Py_TRASHCAN_END, skipping the body of the deallocator */ \
526
- _PyTrash_thread_deposit_object (_PyObject_CAST (op )); \
531
+ if (_PyTrash_begin (_tstate , _PyObject_CAST (op ))) { \
527
532
break ; \
528
533
} \
529
- ++ _tstate -> trash_delete_nesting ; \
530
534
}
531
535
/* The body of the deallocator is here. */
532
536
#define Py_TRASHCAN_END \
533
537
if (_tstate) { \
534
- --_tstate->trash_delete_nesting; \
535
- if (_tstate->trash_delete_later && _tstate->trash_delete_nesting <= 0) \
536
- _PyTrash_thread_destroy_chain(); \
538
+ _PyTrash_end(_tstate); \
537
539
} \
538
540
} while (0);
539
541
540
- #define Py_TRASHCAN_BEGIN (op , dealloc ) Py_TRASHCAN_BEGIN_CONDITION(op, \
542
+ #define Py_TRASHCAN_BEGIN (op , dealloc ) \
543
+ Py_TRASHCAN_BEGIN_CONDITION(op, \
541
544
Py_TYPE(op)->tp_dealloc == (destructor)(dealloc))
542
545
543
546
/* For backwards compatibility, these macros enable the trashcan
0 commit comments