@@ -2569,7 +2569,7 @@ subtype_dealloc(PyObject *self)
25692569 _PyObject_GC_TRACK (self );
25702570 if (PyObject_CallFinalizerFromDealloc (self ) < 0 ) {
25712571 /* Resurrected */
2572- goto endlabel ;
2572+ return ;
25732573 }
25742574 _PyObject_GC_UNTRACK (self );
25752575 }
@@ -2591,7 +2591,7 @@ subtype_dealloc(PyObject *self)
25912591 type -> tp_del (self );
25922592 if (Py_REFCNT (self ) > 0 ) {
25932593 /* Resurrected */
2594- goto endlabel ;
2594+ return ;
25952595 }
25962596 _PyObject_GC_UNTRACK (self );
25972597 }
@@ -2655,44 +2655,6 @@ subtype_dealloc(PyObject *self)
26552655 _Py_DECREF_TYPE (type );
26562656 }
26572657
2658- endlabel :
2659-
2660- /* Explanation of the weirdness around the trashcan macros:
2661-
2662- Q. What do the trashcan macros do?
2663-
2664- A. Read the comment titled "Trashcan mechanism" in object.h.
2665- For one, this explains why there must be a call to GC-untrack
2666- before the trashcan begin macro. Without understanding the
2667- trashcan code, the answers to the following questions don't make
2668- sense.
2669-
2670- Q. Why do we GC-untrack before the trashcan and then immediately
2671- GC-track again afterward?
2672-
2673- A. In the case that the base class is GC-aware, the base class
2674- probably GC-untracks the object. If it does that using the
2675- UNTRACK macro, this will crash when the object is already
2676- untracked. Because we don't know what the base class does, the
2677- only safe thing is to make sure the object is tracked when we
2678- call the base class dealloc. But... The trashcan begin macro
2679- requires that the object is *untracked* before it is called. So
2680- the dance becomes:
2681-
2682- GC untrack
2683- trashcan begin
2684- GC track
2685-
2686- Q. Why did the last question say "immediately GC-track again"?
2687- It's nowhere near immediately.
2688-
2689- A. Because the code *used* to re-track immediately. Bad Idea.
2690- self has a refcount of 0, and if gc ever gets its hands on it
2691- (which can happen if any weakref callback gets invoked), it
2692- looks like trash to gc too, and gc also tries to delete self
2693- then. But we're already deleting self. Double deallocation is
2694- a subtle disaster.
2695- */
26962658}
26972659
26982660static PyTypeObject * solid_base (PyTypeObject * type );
0 commit comments