From: Guido van Rossum Date: Thu, 28 Mar 2002 20:41:02 +0000 (+0000) Subject: Sort-of backport to 2.1.3 (if we ever release it) of the following. X-Git-Tag: v2.1.3~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c44d823daac35b8f1f9a62ae54ae15dc81e03d3c;p=thirdparty%2FPython%2Fcpython.git Sort-of backport to 2.1.3 (if we ever release it) of the following. (The fix looks different, but does the same thing to the 2.1 GC code that Neil's patch does to the 2.2 GC code.) 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! --- diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index e781bdf9e786..011bb1461a9c 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -87,12 +87,14 @@ gc_list_append(PyGC_Head *node, PyGC_Head *list) static void gc_list_remove(PyGC_Head *node) { + if (node->gc_next == NULL) + return; node->gc_prev->gc_next = node->gc_next; node->gc_next->gc_prev = node->gc_prev; #ifdef Py_DEBUG node->gc_prev = NULL; - node->gc_next = NULL; #endif + node->gc_next = NULL; } static void diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 8ad44c181cd1..bac0edfc2de0 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -619,8 +619,8 @@ dict_dealloc(register dictobject *mp) { register int i; register dictentry *ep; - Py_TRASHCAN_SAFE_BEGIN(mp) PyObject_GC_Fini(mp); + Py_TRASHCAN_SAFE_BEGIN(mp) for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) { if (ep->me_key != NULL) { Py_DECREF(ep->me_key); diff --git a/Objects/listobject.c b/Objects/listobject.c index 7044edeea4f6..6868504ab323 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -176,8 +176,8 @@ static void list_dealloc(PyListObject *op) { int i; - Py_TRASHCAN_SAFE_BEGIN(op) PyObject_GC_Fini(op); + Py_TRASHCAN_SAFE_BEGIN(op) if (op->ob_item != NULL) { /* Do it backwards, for Christian Tismer. There's a simple test case where somehow this reduces diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index ca76bb5923ff..000856d5f6f5 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -143,8 +143,8 @@ tupledealloc(register PyTupleObject *op) { register int i; register int len = op->ob_size; - Py_TRASHCAN_SAFE_BEGIN(op) PyObject_GC_Fini(op); + Py_TRASHCAN_SAFE_BEGIN(op) if (len > 0) { i = len; while (--i >= 0)