Cyclic garbage collection and segfaults...
mailund at birc.dk
Thu Jan 15 15:59:39 CET 2004
On Thu, 15 Jan 2004 11:15:51 +0000, Michael Hudson wrote:
> "Thomas Mailund" <mailund at birc.dk> writes:
>> Hi group.
>> I have a problem with some C extensions I am working with and
>> hope that some of you can help.
>> static void
>> Simple_dealloc(SimpleObject *self)
>> fprintf(stderr,"Simple_dealloc %p\n", self);
>> self->ob_type->tp_free((PyObject*)self); /* <= segfault here */
> Well, you're calling tp_free from a tp_dealloc. That doesn't *sound*
> sensible to me.
I'm suprised to hear that; the documentation I was working from,
<URL:http://www.python.org/doc/current/ext/node22.html>, does exactly
that. Of course, this is from the section that uses reference counting,
not cyclic gc, but later on, when the garbage collector is introduced, the
deallocator still calls tp_free, it just calls clear first
If I shouldn't free self in this way, how should I do it?
>> Can anyone explain what I'm doing wrong? Or perhaps suggest a better
>> solution to my "real" problem, if I'm approaching the problem completely
>> wrong :-)
> There are docs on this sort of thing.
About the garbage collection? In that case, I thought I *was* following
the documentation ;-)
If about the general problem with accessing the whole and parts of a C
structure from python, if you have any specific references in mind, I
would be very grateful if you would post them. I know that I am not the
first to have this problem, and that very likely there are general
patterns for solving the problem, but my googling didn't find anything
(which probably means I wasn't asking the right questions, but never the
More information about the Python-list