Re: [xml] using "raise" in Python error handler callbacks



Daniel Veillard wrote:

The 'PyErr_Occurred()' function will return 1 since the (python) error
callback raised an exception that was not yet dealt with.
With the above hack, the example of the OP indeed generates a stack trace
(a TypeError as the string in the 'raise' expression is malformed).

However, things are more complex than that, since xmlTextReaderRead will
potentially call the (python) callback multiple times, erasing the exception
state from former calls.
Right now libxml2 seems to assume that (error) callbacks can't fail themselfs.
I'm not sure whether there is anything to do here.


  So PyErr_Occurred() check should be done when C call python at the,
return point, right ? I think this occurs only in a few places within python/libxml.c which is
not autogenerated. So hacking this might be possible.

Fine ! Though I would use some kind of polymorphism to provide this
functionality to any language binding, not just python. What about
setting up some global (but protected) variable (akin to an internal 'errno')
that callback wrappers may use to indicate failure ?
Make this a 'void *' normally set to 'NULL', and then abort the normal
processing if it is != NULL. Wrapper code may then tunnel any data through it.

Regards,
                Stefan



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]