question with embeding python in C
b_lamy at club-internet.fr
Wed Sep 12 08:10:57 CEST 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
but I have made 2 other C functions that return new PyObject and that
- 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
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