seg. fault with Py_BuildValue?

C

Christian Meesters

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
 
D

Diez B. Roggisch

Christian said:
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?

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
 
C

Christian Heimes

Christian said:
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
 
C

Christian Meesters

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top