[Pyrex] pyrex and g++

Lenard Lindstrom len-l at telus.net
Sat Sep 24 03:57:40 CEST 2005


It can be done, but only if Pyrex generates C++ code to catch exceptions as does 
Boost and Swig. So now Pyrex will have two output modes, C and C++. 
Furthermore, Boost and Swig have special syntax to allow users to provide custom 
mapping of C++ to Python exceptions. Pyrex lacks this. So now we are looking at 
new statements for Pyrex:

cdef try:
    SomeCppFunction();
except int, i:
    raise SomeException, "It threw and integer at me: %d" % i

?

Lenard Lindstrom
<len-l at telus.net>

On 23 Sep 2005 at 14:24, Josiah Carlson wrote:

> 
> "Lenard Lindstrom" <len-l at telus.net> wrote:
> > 
> > I don't think the problem is making Pyrex generate code that can compile as C++. I 
> > think the problem is that the module will be used by an interpreter written and 
> > compiled in pure C. What happens if a C++ exception is thrown and not caught 
> > before returning to interpreter's call on a module function. Will the C stack continue 
> > to unwind and cause the interpreter to crash? Does declaring a C++ function 'extern 
> > "C"' ensure that any unhandled C++ exceptions are stopped in their tracks before 
> > they can do harm in C code? ( A quick test using MinGW 3.2.3 shows an exception 
> > thrown by a C++ function in a dynamic library causes an abnormal termination in a 
> > C program calling it.)
> 
> I'm pretty sure it can be done, otherwise the Boost::Python guys (who
> wrap C++ stuff for Python) would be SOL.  I don't know how to do it
> myself (never having had the occasion to check), but I'm sure that
> someone out there has done it, and could explain how it happens.
> 




More information about the Pyrex mailing list