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.

http://www.cs.bham.ac.uk/resources/ums/PythonDoc/ext/callingPython.html

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 http://redhat.com/
> veillard redhat com | libxml GNOME XML XSLT toolkit
> http://xmlsoft.org/
> http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml


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]