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

I like cheese

Andrew McDermott <andymcd mac com> wrote:
On 31 Mar 2005, at 22:43, Daniel Veillard wrote:

> On Thu, Mar 31, 2005 at 10:25:41PM +0100, Andrew McDermott wrote:
>> Whilst experimenting with the Python bindings I noticed that
>> exceptions
>> are not propagated when using registerErrorHandler(). If I run the
>> following I get the error message:
>> /etc/passwd : failed to parse.
>> However, there is no Traceback for the "raise". Is this correct?
>> import libxml2
>> import sys
> You have
> Python calling C calling Python.
> the internal exception in the callback does not cross the C boundary
> I don't see how this could work without disastrous side effects like
> memory leaks or general instability in the program.

I was reading a section from the link below wh ich gave me the
impression this was possible.

The return value of PyEval_CallObject() is ``new'': either it is a
brand new object, or it is an existing object whose reference count
has been incremented. So, unless you want to save it in a global
variable, you should somehow Py_DECREF() the result, even (especially!)
if you are not interested in its value.

Before you do this, however, it is important to check that the return
value isn't NULL. If it is, the Python function terminated by raising
an exception. If the C code that called PyEval_CallObject() is called
from Python, it should now return an error indication to its Python
caller, so the interpreter can print a stack trace, or the calling
Python code can handle the exception. If this is not possible or
desirable, the exception should be cleared by calling PyErr_Clear().
For example:

Isn't it the case that the calling sequence starts within Python so it
should be possible to return an error indication?

> Daniel
> --
> Daniel Veillard | Red Hat Desktop team
> veillard redhat com | libxml GNOME XML XSLT toolkit
> | Rpmfind RPM search engine

xml mailing list, project page
xml gnome org

Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!

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