diff options
author | Benjamin Peterson <benjamin@python.org> | 2016-10-04 07:00:23 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2016-10-04 07:00:23 (GMT) |
commit | 804480912c8328df7d042c6e5201cfe4abf21742 (patch) | |
tree | e78e67f7de97f402c3c2b26093ba3a25230fed3c /Objects | |
parent | fb12ce1cb3ded55e17833603715b1a38e15be20d (diff) | |
parent | 8f657c35b978b681e6e919f08358992e1aed7dc1 (diff) | |
download | cpython-804480912c8328df7d042c6e5201cfe4abf21742.zip cpython-804480912c8328df7d042c6e5201cfe4abf21742.tar.gz cpython-804480912c8328df7d042c6e5201cfe4abf21742.tar.bz2 |
merge 3.5 (#26617)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index e799a57..cb251dd 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1136,11 +1136,6 @@ subtype_dealloc(PyObject *self) Py_TRASHCAN_SAFE_BEGIN(self); --_PyTrash_delete_nesting; -- tstate->trash_delete_nesting; - /* DO NOT restore GC tracking at this point. weakref callbacks - * (if any, and whether directly here or indirectly in something we - * call) may trigger GC, and if self is tracked at that point, it - * will look like trash to GC and GC will try to delete self again. - */ /* Find the nearest base with a different tp_dealloc */ base = type; @@ -1151,30 +1146,36 @@ subtype_dealloc(PyObject *self) has_finalizer = type->tp_finalize || type->tp_del; - /* Maybe call finalizer; exit early if resurrected */ - if (has_finalizer) - _PyObject_GC_TRACK(self); - if (type->tp_finalize) { + _PyObject_GC_TRACK(self); if (PyObject_CallFinalizerFromDealloc(self) < 0) { /* Resurrected */ goto endlabel; } + _PyObject_GC_UNTRACK(self); } - /* If we added a weaklist, we clear it. Do this *before* calling - tp_del, clearing slots, or clearing the instance dict. */ + /* + If we added a weaklist, we clear it. Do this *before* calling tp_del, + clearing slots, or clearing the instance dict. + + GC tracking must be off at this point. weakref callbacks (if any, and + whether directly here or indirectly in something we call) may trigger GC, + and if self is tracked at that point, it will look like trash to GC and GC + will try to delete self again. + */ if (type->tp_weaklistoffset && !base->tp_weaklistoffset) PyObject_ClearWeakRefs(self); if (type->tp_del) { + _PyObject_GC_TRACK(self); type->tp_del(self); if (self->ob_refcnt > 0) { /* Resurrected */ goto endlabel; } + _PyObject_GC_UNTRACK(self); } if (has_finalizer) { - _PyObject_GC_UNTRACK(self); /* New weakrefs could be created during the finalizer call. If this occurs, clear them out without calling their finalizers since they might rely on part of the object |