Robert Bradshaw wrote:
Hi Robert, > I had an error like this and it turned out to be caused by a GC > error. Specifically, an object A was allocated, then erroneously > deallocated (but there was still stuff pointing to it). Object B was > then allocated, with memory overlapping that of object A. Object A > was then modified, and that modified the refcount field of object B. > That might be a variant of what's going on here. > > I tracked it down by using gdb's watch command on the object with the > weird ref count... > > - Robert As it turned out it was a bug in 2.8.9's Cython [and probably at least some of the earlier versions] which Carl tracked down after I isolated the cause: [02:30] <mabshoff> Ok, every time c=0 the refcount for int(0) goes up by one. [02:42] <cwitty> It's a Cython bug. [02:42] <mabshoff> Yep, for c in cols: [02:42] <mabshoff> increments the refcount on int(?) [02:42] <cwitty> I've been having a hard time debugging it because the bug doesn't occur any more in the current Cython (so it's gone in 2.8.10). [02:43] <mabshoff> Ok, let me upgrade and see if the problem goes away. [02:44] <mabshoff> Got any more technical details? [02:45] <cwitty> In 2.8.9's version of Cython, converting a Python object (like the int objects we're dealing with) to a Py_Ssize_t goes via this line of code: [02:45] <cwitty> #define __pyx_PyIndex_AsSsize_t(b) PyInt_AsSsize_t(PyNumber_Index(b)) [02:46] <cwitty> PyNumber_Index(b) returns a new object (although in this case it's actually the exact same int object), with its refcount incremented. [02:46] <mabshoff> Ok, that makes sense. [02:46] <cwitty> So the caller of PyNumber_Index() is supposed to decref the return value at some point. With 2.8.10 the refcount of int(0) doesn't increase by invoking dance(m) any more: sage: a=int(0) sage: sys.getrefcount(a) 5304 sage: dance(5) h^5 - 5*h^4 + 25*h^3 - 55*h^2 + 80*h - 46 sage: sys.getrefcount(a) 5304 sage: dance(6) h^6 - 9*h^5 + 60*h^4 - 225*h^3 + 555*h^2 - 774*h + 484 sage: sys.getrefcount(a) 5304 It used to be that sys.getrefcount(a) would end up around 48,000 after dance(5), so now I consider this issues closed. Cheers, Michael --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---