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

Hi Daniel,

Daniel Veillard wrote:
On Thu, Mar 31, 2005 at 07:57:04PM -0500, Stefan Seefeld wrote:

I don't think this is quite accurate. Think about python as a high-level
API to a C runtime. If the outer and the inner python runtimes are
the same, there is certainly a way to pass the necessary information through
(i.e. ultimately just preserve the exception state from the callback).

  If you know how to do it, I take patches. I don't know how to do it in
the general case, i.e. without changing all C APIs to have an extra argument
to carry those informations. And changing the public C APIs is not possible.
Again I take patches !

The information about the exception state is lost when the generated
'libxml_xmlTextReaderRead' function unconditionally returns an integer.
Here is a quick hack for libxml2-py.c:9017

    c_retval = xmlTextReaderRead(reader);
    if (PyErr_Occurred())
      return NULL;

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.


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