Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

seg. fault with Py_BuildValue?

4 views
Skip to first unread message

Christian Meesters

unread,
May 29, 2008, 9:28:20 AM5/29/08
to
Hi

I'm having trouble with Py_BuildValue. I was able to pinpoint the following
statement as the one causing a seg. fault with my script:

static PyObject * funcname(PyObject *self, PyObject *args) {
...
return Py_BuildValue("(OO)", x, y);
}
where x & y are both of type PyObject.

Any suggestions here? Do I need to handle the output of Py_BuildValue
somehow before returning? How? Need to decref x & y before returning?

TIA
Christian

Diez B. Roggisch

unread,
May 29, 2008, 9:44:26 AM5/29/08
to
Christian Meesters wrote:

Just a guess - but according to the docs of Py_BuildValue it will return a
tuple already when given a format string of several format units.

What happens if you get rid of the ()?

Diez

Christian Meesters

unread,
May 29, 2008, 10:11:46 AM5/29/08
to
> What happens if you get rid of the ()?
Can't see any difference.


Christian Heimes

unread,
May 29, 2008, 10:31:03 AM5/29/08
to pytho...@python.org
Christian Meesters schrieb:

> Hi
>
> I'm having trouble with Py_BuildValue. I was able to pinpoint the following
> statement as the one causing a seg. fault with my script:
>
> static PyObject * funcname(PyObject *self, PyObject *args) {
> ....

> return Py_BuildValue("(OO)", x, y);
> }
> where x & y are both of type PyObject.
>
> Any suggestions here? Do I need to handle the output of Py_BuildValue
> somehow before returning? How? Need to decref x & y before returning?

Check if either x or y are NULL.

Christian

Christian Meesters

unread,
May 30, 2008, 4:17:33 AM5/30/08
to

> Check if either x or y are NULL.
They aren't. Just did an explicit check.

Christian Meesters

unread,
May 30, 2008, 9:05:47 AM5/30/08
to
Ok now, I know where the error is: "y" actually contained refcounts. This,
of course, is complete nonsense and causes the interpreter to crash at some
point.

Thanks to all of you: You helped at least to track down the problem.

Christian

0 new messages