[Python-Dev] Re: [Python-Help] Bug in PyTuple_Resize

Martin von Loewis help@python.org
Thu, 14 Sep 2000 19:28:54 +0200 (MET DST)

> Thank you for the response.  Unfortunately, I do not have the know-how at
> this time to solve this problem!  I did submit my original query and
> your response to the sourceforge bug tracking mechanism this morning.

I spent some time with this bug, and found that it is in some
unrelated code: the tuple resizing mechanism is is buggy if cyclic gc
is enabled. A patch is included below. [and in SF patch 101509]

It just happens that this code is rarely used: in _tkinter, when
filtering tuples, and when converting sequences to tuples. And even
then, the bug triggers on most systems only for _tkinter: the tuple
gets smaller in filter, so realloc(3C) returns the same adress;
tuple() normally succeeds in knowing the size in advance, so no resize
is necessary.


Index: tupleobject.c
RCS file: /cvsroot/python/python/dist/src/Objects/tupleobject.c,v
retrieving revision 2.44
diff -u -r2.44 tupleobject.c
--- tupleobject.c	2000/09/01 23:29:27	2.44
+++ tupleobject.c	2000/09/14 17:12:07
@@ -510,7 +510,7 @@
 		if (g == NULL) {
 			sv = NULL;
 		} else {
-			sv = (PyTupleObject *)PyObject_FROM_GC(g);
+			sv = (PyTupleObject *)PyObject_FROM_GC(sv);
 		sv = (PyTupleObject *)