Skip to content

Commit a81bb72

Browse files
committed
Handle tp_is_gc in _PyTrash_thread_deposit_object
1 parent 7101e8f commit a81bb72

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

Objects/object.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,12 +3042,19 @@ void
30423042
_PyTrash_thread_deposit_object(PyThreadState *tstate, PyObject *op)
30433043
{
30443044
_PyObject_ASSERT(op, Py_REFCNT(op) == 0);
3045-
assert(PyObject_IS_GC(op));
3046-
int tracked = _PyObject_GC_IS_TRACKED(op);
3047-
if (tracked) {
3048-
_PyObject_GC_UNTRACK(op);
3045+
PyTypeObject *tp = Py_TYPE(op);
3046+
assert(tp->tp_flags & Py_TPFLAGS_HAVE_GC);
3047+
uintptr_t tagged_ptr;
3048+
if (tp->tp_is_gc == NULL || tp->tp_is_gc(op)) {
3049+
int tracked = _PyObject_GC_IS_TRACKED(op);
3050+
if (tracked) {
3051+
_PyObject_GC_UNTRACK(op);
3052+
}
3053+
tagged_ptr = ((uintptr_t)tstate->delete_later) | tracked;
3054+
}
3055+
else {
3056+
tagged_ptr = ((uintptr_t)tstate->delete_later);
30493057
}
3050-
uintptr_t tagged_ptr = ((uintptr_t)tstate->delete_later) | tracked;
30513058
#ifdef Py_GIL_DISABLED
30523059
op->ob_tid = tagged_ptr;
30533060
#else
@@ -3150,11 +3157,11 @@ void
31503157
_Py_Dealloc(PyObject *op)
31513158
{
31523159
PyTypeObject *type = Py_TYPE(op);
3153-
unsigned long gc_flags = type->tp_flags & Py_TPFLAGS_HAVE_GC;
3160+
unsigned long gc_flag = type->tp_flags & Py_TPFLAGS_HAVE_GC;
31543161
destructor dealloc = type->tp_dealloc;
31553162
PyThreadState *tstate = _PyThreadState_GET();
31563163
intptr_t margin = _Py_RecursionLimit_GetMargin(tstate);
3157-
if (margin < 2 && gc_flags) {
3164+
if (margin < 2 && gc_flag) {
31583165
_PyTrash_thread_deposit_object(tstate, (PyObject *)op);
31593166
return;
31603167
}
@@ -3200,7 +3207,7 @@ _Py_Dealloc(PyObject *op)
32003207
Py_XDECREF(old_exc);
32013208
Py_DECREF(type);
32023209
#endif
3203-
if (tstate->delete_later && margin >= 4 && gc_flags) {
3210+
if (tstate->delete_later && margin >= 4 && gc_flag) {
32043211
_PyTrash_thread_destroy_chain(tstate);
32053212
}
32063213
}

0 commit comments

Comments
 (0)