Skip to content

Commit 7101e8f

Browse files
committed
Don't empty trashcan unless object is GC'd
1 parent f89ddfd commit 7101e8f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Objects/object.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,10 +3150,11 @@ void
31503150
_Py_Dealloc(PyObject *op)
31513151
{
31523152
PyTypeObject *type = Py_TYPE(op);
3153+
unsigned long gc_flags = type->tp_flags & Py_TPFLAGS_HAVE_GC;
31533154
destructor dealloc = type->tp_dealloc;
31543155
PyThreadState *tstate = _PyThreadState_GET();
31553156
intptr_t margin = _Py_RecursionLimit_GetMargin(tstate);
3156-
if (margin < 2 && PyObject_IS_GC(op)) {
3157+
if (margin < 2 && gc_flags) {
31573158
_PyTrash_thread_deposit_object(tstate, (PyObject *)op);
31583159
return;
31593160
}
@@ -3199,7 +3200,7 @@ _Py_Dealloc(PyObject *op)
31993200
Py_XDECREF(old_exc);
32003201
Py_DECREF(type);
32013202
#endif
3202-
if (tstate->delete_later && margin >= 4) {
3203+
if (tstate->delete_later && margin >= 4 && gc_flags) {
32033204
_PyTrash_thread_destroy_chain(tstate);
32043205
}
32053206
}

0 commit comments

Comments
 (0)