Re: [xml] Raising exceptions in python bindings



On Mon, Mar 27, 2006 at 07:04:17PM +0200, Cesar Ortiz wrote:
Hi,

'Playing' with the pushSAXhtml example I have seen that the callback
excepcions does not propagate from the 'C parser' to the outer python code.

But... is it safe to leave the parser to consume an exception or I have to
put a 'except' in each callback method? I say this, because raising an
exception with the 'Memory debug specific code' makes a leak of 16353 bytes.
What surprise me more, is that if you raise more than one exception the leak
does not rise.

  Well there is no notion of exception in C. If you implement on on top of
it for example using setjmp/longjmp, and raise ot in the callback catching back
in an ancestor of the parsing routine, then yes sur you may loose all objects
allocated whithin the parser and expected to be freed for example when exiting
the routines being popped off. I don't see how you could avoid this. The parser
has no exception but if you call xmlStopParser from one of the callbacks and
return it will try to exit back as soon as possible and the parser will be
in an error state. Any other mechanism based on language specific constructs
be them Python C++ or whatever will leak in general.

Daniel

-- 
Daniel Veillard      | Red Hat http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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