question with embeding python in C
LAMY Bertrand
b_lamy at club-internet.fr
Wed Sep 12 02:10:57 EDT 2001
here is my question :
when I create a Python object in a C function with PyObject_New and the
C function return that object to python, do I have to Py_INCREF the
object before ?
In the help examples, for all 'new' functions that create in C an
instance of a new type, the object is returned without Py_INCREF. that
works.
but I have made 2 other C functions that return new PyObject and that
bugs :
- the first is a getattrfunc that return each time it is called a new
object. printing many time this object (that is a C object I created) in
python, I see that the values stored in it change for each print.
- the second function is a load function used when I unpickle the object
: it return a new object of my type given the tuple of data. I got a
segfault.
the 2 bugs were corrected by Py_INCREF the object before returning it.
Does that right ? Well, I have other functions that do the same and
works, a clone function for example. I do not Py_INCREF the returned
object, and it seems it doesn't matter.
Can someone help me ?
- Blam (currently working on Py3D)
More information about the Python-list
mailing list