segfault in extension module

Nathaniel Echols echols at OCF.Berkeley.EDU
Mon Dec 1 05:43:51 EST 2003


> > I've written a function in C to perform protein sequence alignment.  This
> > works fine in a standalone C program.  I've added the necessary packaging
> > to use it in Python;
> Which one? Are you using the C API?

Yup - I'm reading right out of the manual.

> Looks like refcount problems, check out
> http://www.python.org/doc/current/ext/refcounts.html .

I read this before and couldn't figure out what it meant.  This does seem
like it would relate, but I can't figure out what I'm doing incorrectly.
I just have one function which calls a pure C function and returns a
tuple of strings from it.  I'm guessing I need to add a Py_INCREF()
somewhere but so far this just makes it segfault sooner.  (I'm
not sure what argument to use for Py_INCREF(), either.)

I've looked at several other pages, and they all seem to involve setups
more complicated than what I'm doing.  I'm already using Py_BuildValue()
to generate the returned tuple, and my understanding is that this should
avoid major problems. . .

> IMO just avoid all this stuff and use SWIG/Boost.Python/Pyrex.

I'll look at these, but I only have a tiny little bit of code I need to do
this with - I coded it from scratch with the intention of using it this
way, and could have written it in Python if I didn't care about speed.
Would I really benefit from using one of the other methods?  The goal here
is explicitly to put only the very time-dependent code in C; everything
else stays in Python.

thanks,
Nat




More information about the Python-list mailing list