Kaydet (Commit) 9ff1a449 authored tarafından Guido van Rossum's avatar Guido van Rossum

Fix an edge case whereby the __del__() method of a classic class could

create a new weakref to the object.
üst 4956d2b8
...@@ -646,6 +646,16 @@ instance_dealloc(register PyInstanceObject *inst) ...@@ -646,6 +646,16 @@ instance_dealloc(register PyInstanceObject *inst)
*/ */
assert(inst->ob_refcnt > 0); assert(inst->ob_refcnt > 0);
if (--inst->ob_refcnt == 0) { if (--inst->ob_refcnt == 0) {
/* 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
being finalized that has already been destroyed. */
while (inst->in_weakreflist != NULL) {
_PyWeakref_ClearRef((PyWeakReference *)
(inst->in_weakreflist));
}
Py_DECREF(inst->in_class); Py_DECREF(inst->in_class);
Py_XDECREF(inst->in_dict); Py_XDECREF(inst->in_dict);
PyObject_GC_Del(inst); PyObject_GC_Del(inst);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment