PyObject_CallObject, execptions and ref counts
Patrick Down
pdown at bigfoot.com
Thu Apr 19 22:38:29 EDT 2001
I have a python object that has a method that I use as a callback function
from C.
I pass the method a couple of objects as parameters. When the callback code
executes correctly and returns, all the reference counts on the objects I
passed
as parameters are decremented correctly and they are deleted. ( The callback
doesn't hold a reference to them. ) When there is an error in the callback
code
I test for it with PyErr_Occurred() and call PyErr_Print() and PyErr_Clear()
but the reference counts on the objects I passed in are not decremented.
It's as
if the stack was not being unwound correctly and the local variables
dereferenced.
As an experiment I put a try: except: block in the callback code. This
fixed the
reference count problem. However I would like to be able to handle errors
gracefully
from the C code without expecting the callback writer to put in exception
handling.
Anyone have an idea what I might be doing wrong or how I can fix this?
Patrick Down
pdown at codemoon.com
More information about the Python-list
mailing list