[Pyrex] Initialisation of cdef global arrays with constants [resend]

Yann Vernier yann at donkey.dyndns.org
Sat Jan 29 23:34:31 CET 2005


On Sun, Jan 30, 2005 at 09:28:03AM +1100, sjmachin at lexicon.net wrote:
> On 30 Jan 2005 at 9:58, Greg Ewing wrote:
> 
> > sjmachin at lexicon.net wrote:
> > > Where I'm coming from is (my belief/understanding) that a "Python function" hand 
> > > coded in C _should_ return NULL in this circumstance, so that the precise exception set 
> > > by the called function can be thrown, instead of a guess.
> > 
> > Oh, I see what you mean. Yes, that's what you would do
> > if you were writing an extension module in C by hand.
> > But in Pyrex you just use a "raise" statement, and
> > Pyrex takes care of returning the NULL.
> 
> Apparently not: as one might expect, it generates code to do what Python does with a 
> bare "raise" statement -- i.e. *RE*raise an already raised exception.
> 
> In my scenario, PyString_AsStringAndSize has *set* an exception, but it has not yet 
> been raised; we need to return NULL back down the call chain until the exception is 
> raised.

That's what the cdef function() except NULL form is for, isn't it? This
makes Pyrex check for exceptions when the function returns the indicated
value, if I understood the docs correctly.

http://nz.cosc.canterbury.ac.nz/~greg/python/Pyrex/version/Doc/overview.html#ExceptionValues



More information about the Pyrex mailing list