[Pyrex] Pyrex exception reraise behavior

Stefan Behnel stefan_ml at behnel.de
Sat Aug 16 21:54:27 CEST 2008


Hi,

Greg Ewing wrote:
> There are some differences, yes. Python makes the
> sys.exc_info() vars dynamically scoped by saving and
> restoring them in the Python stack frame every time
> a call occurs.
>
> That would be too expensive for Pyrex, so it uses
> a different approach -- it stores information about
> the caught exception in the C stack frame at the
> point where it's caught (i.e. in the except clause).
> The raise statement is required to be lexically
> enclosed in the except clause so that it can access
> this information.
>
> There may be some other differences as well. What
> you appear to be seeing is a leaking of the
> sys.exc_info() outside the scope where it would
> normally be available in Python.

Especially in Py3, where sys.exc_info() is reset when leaving the except block
that caught the exception. I have a patch ready that fixes this with
relatively little performance impact, although it requires remembering the
currently raised exception whenever we enter a try statement (that's just
three pointer copy operations). I think the OP's re-raising problem fits into
this, too, although it would require some more thoughts to fix.

There are some more issues with exception handling in Py3. Due to Python keeps
exceptions in frames, I currently get crashes with Cython's exception handling
(AFAICT unchanged from Pyrex) in Py3.0 beta2 (beta 1 works fine). I've been
trying to dig into this problem, but it's pretty far from obvious to me how
this can be fixed, or even what exactly goes wrong here. I attached the
(somewhat hackish) patch I'm currently working with. It also contains a couple
of test cases that show the behaviour I'm targeting, which is superficially
compatible with Python 3. One of them crashes reliably for me.

Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: exception-handling.patch
Type: text/x-patch
Size: 9051 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20080816/5a09ab6b/attachment-0001.bin 


More information about the Pyrex mailing list