[Pyrex] Reraise not inside except clause
Robert Kern
robert.kern at gmail.com
Tue Oct 16 08:39:54 CEST 2007
Greg Ewing wrote:
> Robert Kern wrote:
>> It is valid in Python to have an empty "raise" statement anywhere, and it used
>> to be valid in Pyrex before 0.9.6.
>>
>> Can this restriction be reverted?
>
> Not without bringing back the behaviour whereby the exception
> you want to reraise can get clobbered by another exception
> before you get a chance to reraise it.
>
> Python's way of dealing with this is to save the current
> exception on entry to every function and restore it afterwards.
> That would be an unacceptable amount of overhead for Pyrex,
> given that the overwhelming majority of function calls do not
> need this to be done.
>
> My suggestion is to think of another way to achieve whatever
> it is that PyProtocols is trying to do. If you can provide
> some more details about that, I may be able to help.
The code is Phillip Eby's, not mine, but here it is:
http://svn.eby-sarna.com/PyProtocols/src/protocols/_speedups.pyx?rev=205&view=markup
It appears to be using the "raise" statement after checking for an error when
calling PyObject_GetAttr. Pyrex doesn't catch the error itself because Phillip
is declaring PyObject_GetAttr to return "void*" rather than "object". I'm not
entirely sure why; he does so for other functions, but he comments that this is
because they return borrowed references and Pyrex's increffing gets in the way.
It looks like every time he "raise"s, he's already grabbing the current
exception object. Most likely, that can be changed to "raise err".
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Pyrex
mailing list