Trouble with reference count with PyNumber_Coerce
2015-02-28 11:55:33 GMT
I am not sure I am right, but I did some experiments that confirm the behavior below. I want to use the PyNumber_Coerce(PyObject **, PyObject **) from the C-API. This function does increase the reference counts of the arguments. So if I write
def handmade_coerce(x, y):
PyObject * obj_x = x
PyObject * obj_y = y
return <object> obj_x, <object> obj_y
then the returned values get too much reference countings since the cast <object> also does increase the ob_refcnt. Is there a way to make it work? I first thought of
PyNumber_Coerce(&(<PyObject *> x), &(<PyObject *> y))
but cythonization just fails.
One other way would be to use directly coerce from Python but it does not seem to be cythonized properly. I might end up with fixing this but I would first like to understand if its possible to do a <object> cast without increasing the reference counting.
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.