horribly slimy segault c-extension

Hunter Peress dsada at asd.com
Sat May 31 18:38:13 EDT 2003


On Sat, 31 May 2003 17:56:04 +0000, Tim Peters wrote:

> [John Does]
>> There should be no need for me to show all my code for this issue.
>>
>> First off: i run a program and it sefaults normally, but when i run it
>> through gdb it does not.
> 
> Try a debug build of Python too; it often helps; also try Python 2.3b1,
> which contains more memory-problem detection code in a debug build than
> older Pythons have.
> 
> BTW, doesn't a failing run leave behind a coredump file you can point gdb at
> for a postmortem debug session?
> 
>> Here are the relevant lines of code:
>>
>>         printf("q:%i \n",Q->ob_refcnt);
>>         Py_DECREF(Q);
>>         printf("qa:%i \n",Q->ob_refcnt);
>>         Q = newQ ;
>>         printf("qaa:%i \n",Q->ob_refcnt);
>>
>> And the output:
>>
>> q:1
>> Segmentation fault
> 
> So the refcount fell to 0, and it's dying in the deallocation routine for
> objects of Q's type.  A common cause for that is:  Q is of an extension
> type, Q's type's tp_dealloc function does some Py_DECREFs of its own, and
> Q's type's allocate-a-new-object function leaves some of the memory
> uninitialized.  Another cause is when Q's type's alloc and dealloc routines
> disagree about whether the type participates in cyclic gc.
> 
>> Without asking me for any more code, can someone give me some precise
>> steps that I could take to begin resolving/exposing this issue.
> 
> Tbat would be quite a trick <wink>.

Wow tim, thanks so much. indeed, i was using 2.2, but i tried 2.3 and the
error went away (just a little info there). I obviously have to make it
work in 2.2.

So back to 2.2 for now:
First, I modified the example to make it even more clear now its running:
        
        printf("q:%i \n",Q->ob_refcnt);
        Py_DECREF(Q);
        printf("hi \n");
        printf("nq:%i \n",newQ->ob_refcnt);
        Q = newQ ;
        printf("qaa:%i \n",Q->ob_refcnt);

output:
   q:1
   Segmentation fault

So i did the core file, but im not sure that its working right...
in this image: http://24.175.34.45/~hperes/t.png  on the left we see a bug
that i purposefully made and the stack trace. the name of my C function is
test and you can clearly see that its being called.

On the right we see the results of "gdb python core"  

since i dont see "test" anywhere, and since theres "??"  im lead to
believe that maybe i didnt load the core file correctly? or maybe i have
not set some name properly in the C? 

Heres all parts to my code that might be responible for
the "??"
http://24.175.34.45/~hperes/gogo.txt




More information about the Python-list mailing list