horribly slimy segault c-extension

Tim Peters tim_one at email.msn.com
Sat May 31 17:56:04 EDT 2003


[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>.






More information about the Python-list mailing list