prob. creating deeply nested structures in Py/c api


O

Ori Y

Hi , i'm having some difficulties regarding using the Python/c api.

I'm trying to bulid a deeply nested datastructure (i.e dict within a dict or list within a dict)
Building the data stracture seems ok on interperter, but after few calls to the method
returning the structure, and aft applying the Ctrl+D to exit interperter
i receive a 'segmentation fault'. ?#
Further more when calling the program from python i receive the dictionary as a string!
"{foo: {1:'blah, 2:'boo'}, bar:1}" (i have a feeling these problems are related).

I'm using python 2.3 on a RH9 Linux machine.
Advise would be very much appriciated.

Here is a shorter example of the consept i'm trying to do :

static *PyObject blah (something)
{
PyObject *dict1;
PyObject *dict2;
long x;

dict1 = PyDict_New();
dict2 = PyDict_New();
x = 1;

PyDict_SetItem(dict1, PyString_FromString("foo"),PyInt_FromLong(x)); //setting first dict

//setting dict1 in dict2 and returning dict2

PyDict_SetItem(dict2, PyString_FromString("blah"),dict1);
// expected {blah:{foo:1}}
 
Ad

Advertisements

B

Bob Ippolito

Hi , i'm having some difficulties regarding using the Python/c api.
I'm trying to bulid a deeply nested datastructure (i.e dict within a
dict or list within a dict)
Building the data stracture seems ok on interperter, but after few
calls to the method
returning the structure, and aft applying the Ctrl+D to exit interperter
i receive a 'segmentation fault'. ?#
Further more when calling the program from python i receive the
dictionary as a string!
"{foo: {1:'blah, 2:'boo'}, bar:1}" (i have a feeling these problems
are related).
I'm using python 2.3 on a RH9 Linux machine.
Advise would be very much appriciated.
Here is a shorter example of the consept i'm trying to do :
static *PyObject blah (something)
{
PyObject *dict1;
PyObject *dict2;
long x;
dict1 = PyDict_New();
dict2 = PyDict_New();
x = 1;
PyDict_SetItem(dict1, PyString_FromString("foo"),PyInt_FromLong(x));
//setting first dict
//setting dict1 in dict2 and returning dict2

PyDict_SetItem(dict2, PyString_FromString("blah"),dict1); // expected
{blah:{foo:1}}

You should try Pyrex:
http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

It would make this just as easy as it is in Python.

-bob
 

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

Top