By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

seg. fault with Py_BuildValue?

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Christian Meesters wrote:
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
Jun 27 '08 #2

P: n/a
What happens if you get rid of the ()?
Can't see any difference.
Jun 27 '08 #3

P: n/a
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

Jun 27 '08 #4

P: n/a
Check if either x or y are NULL.
They aren't. Just did an explicit check.
Jun 27 '08 #5

P: n/a
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
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.