C Extension

Martin v. Loewis martin at v.loewis.de
Wed Apr 3 02:09:22 EST 2002


Eric Merritt <cyberlync at yahoo.com> writes:

> I hope you guys dont mind another stupid question. I
> have created a new C extension to python (Its my first
> one so I expect issues). This extension contains two
> types. In general these types seem to work just fine.
> However when I enter a value of one of these types on
> a line by itself python segfaults. 

I recommend to run Python in a (C) debugger. This will give you much
clearer information as to why it crashes than guessing.

Notice that the crash does not necessarily come from Python printing
something. It could also come from Python deallocating your object.
Even more involved, it could come from Python doing something
completely different, you your extension managed to corrupt central
data structures (such as the malloc heap) somehow.

> At first I thought it was the repr function, or perhaps there string
> function. But I stuck a couple of print strings there to verify that
> and those dont seem to be getting called.

Then something is clearly wrong - either tp_repr or tp_str will be
called, unless you've implemented tp_print (which you don't need to).
If those *aren't* called, this is an indication that it either crashes
before getting that far, or that you managed to get out of synch in
your type object - double-check that every function is in the right
slot (for this, it really helps if you don't need to cast the function
pointers).

Regards,
Martin



More information about the Python-list mailing list