473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
5 2018
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Helmut Jarausch | last post by:
Hi, is there a format code to return an unsigned int to Python via Py_BuildValue? Just using code 'i' gives negative values for values greater than 2**31. I've tried the code 'I' (with python...
2
by: Christian Vogel | last post by:
Hi comp.lang.python readers, are there routines to create a Python integer from unsigned C-integers? I only could find Py_BuildValue and PyInt_FromLong which both only use signed c-integers....
2
by: Torsten Mohr | last post by:
Hi, when i write an extension module in C and return a Py_Object* that i've built with Py_BuildValue, do i need to use Py_INCREF on that before i return it to python from my extension module or...
2
by: ashtonn | last post by:
Hello, How do i print values returned by Py_BuildValue in Linux? PyObject *obj = Py_BuildValue("{s:i}", "Status", status); I need to print the Status value here -Thanks, Ashton
4
by: Luke Miller | last post by:
Hello, I am working on my first python module based on a c program. The module builds and installs OK using dist-utils, and imports fine into python. However, when I try and use the one wrapper...
2
by: Martin Kulas | last post by:
Hallo! I have a problem with Py_BuildValue: I want to convert an unsigned int to a PyObject *. http://docs.python.org/api/arg-parsing.html says that I can use "I" as a format string. But it...
2
by: Sheldon | last post by:
Hi, I have a function that creates python objects out of C arrays and returns them to Python. Below is a working example that I later want to expand to return 12 arrays back to Python. The...
4
by: spectrumdt | last post by:
Hello. I am trying to extend Python with some C code. I made a trivial "Hello World" program in C that I am trying to wrap in "boilerplate" for inclusion in a Python program. But I can't compile...
3
by: Christian Meesters | last post by:
Hi, currently I have a problem understanding Py_BuildValue. I have this code: static PyObject *function(PyObject *self, PyObject *args) { PyObject * python_return_value = NULL; PyObject *...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.