Re: Python C API and references

2009-11-13 Thread Gabriel Genellina
En Thu, 12 Nov 2009 06:23:54 -0300, lallous escribió: Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I don't need the reference to py_val I should decrement the reference after this call? If you own a reference to py_val, and you don't need it anymore, you must decremen

Re: Python C API and references

2009-11-12 Thread Mark Dickinson
On Nov 12, 9:23 am, "lallous" wrote: > Hello, > > Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I don't > need the reference to py_val I should decrement the reference after this > call? Not necessarily: it depends where py_val came from. I find the 'ownership' model descri

Re: Python C API and references

2009-11-12 Thread lallous
Hello Daniel, Thanks for the reply. Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I don't need the reference to py_val I should decrement the reference after this call? It really depends on /how/ the object is created. If the method used to create *py_val* increases t

Python C API and references

2009-11-12 Thread lallous
Hello, Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I don't need the reference to py_val I should decrement the reference after this call? So for example: PyObject *py_val = PyInt_FromLong(5) PyObject_SetAttrString(py_obj, "val", py_val); Py_DECREF(py_val) Right? If s