467,894 Members | 1,748 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

seg. fault with Py_BuildValue?

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
  • viewed: 1783
Share:
5 Replies
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
What happens if you get rid of the ()?
Can't see any difference.
Jun 27 '08 #3
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
Check if either x or y are NULL.
They aren't. Just did an explicit check.
Jun 27 '08 #5
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.

Similar topics

1 post views Thread by Helmut Jarausch | last post: by
2 posts views Thread by Christian Vogel | last post: by
2 posts views Thread by Torsten Mohr | last post: by
2 posts views Thread by ashtonn | last post: by
4 posts views Thread by Luke Miller | last post: by
2 posts views Thread by Martin Kulas | last post: by
2 posts views Thread by Sheldon | last post: by
3 posts views Thread by Christian Meesters | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.