Skip to content

Commit ff413af

Browse files
committed
This is Neil's fix for SF bug 535905 (Evil Trashcan and GC interaction).
The fix makes it possible to call PyObject_GC_UnTrack() more than once on the same object, and then move the PyObject_GC_UnTrack() call to *before* the trashcan code is invoked. BUGFIX CANDIDATE!
1 parent 31f8483 commit ff413af

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

Modules/gcmodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,9 @@ _PyObject_GC_Track(PyObject *op)
819819
void
820820
_PyObject_GC_UnTrack(PyObject *op)
821821
{
822-
_PyObject_GC_UNTRACK(op);
822+
PyGC_Head *gc = AS_GC(op);
823+
if (gc->gc.gc_next != NULL)
824+
_PyObject_GC_UNTRACK(op);
823825
}
824826

825827
PyObject *

Objects/dictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,8 @@ dict_dealloc(register dictobject *mp)
694694
{
695695
register dictentry *ep;
696696
int fill = mp->ma_fill;
697+
PyObject_GC_UnTrack(mp);
697698
Py_TRASHCAN_SAFE_BEGIN(mp)
698-
_PyObject_GC_UNTRACK(mp);
699699
for (ep = mp->ma_table; fill > 0; ep++) {
700700
if (ep->me_key) {
701701
--fill;

Objects/frameobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ frame_dealloc(PyFrameObject *f)
6767
PyObject **fastlocals;
6868
PyObject **p;
6969

70+
PyObject_GC_UnTrack(f);
7071
Py_TRASHCAN_SAFE_BEGIN(f)
71-
_PyObject_GC_UNTRACK(f);
7272
/* Kill all local variables */
7373
slots = f->f_nlocals + f->f_ncells + f->f_nfreevars;
7474
fastlocals = f->f_localsplus;

Objects/listobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ static void
195195
list_dealloc(PyListObject *op)
196196
{
197197
int i;
198+
PyObject_GC_UnTrack(op);
198199
Py_TRASHCAN_SAFE_BEGIN(op)
199-
_PyObject_GC_UNTRACK(op);
200200
if (op->ob_item != NULL) {
201201
/* Do it backwards, for Christian Tismer.
202202
There's a simple test case where somehow this reduces

Objects/tupleobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ tupledealloc(register PyTupleObject *op)
139139
{
140140
register int i;
141141
register int len = op->ob_size;
142+
PyObject_GC_UnTrack(op);
142143
Py_TRASHCAN_SAFE_BEGIN(op)
143-
_PyObject_GC_UNTRACK(op);
144144
if (len > 0) {
145145
i = len;
146146
while (--i >= 0)

0 commit comments

Comments
 (0)