Cython and C++ exceptions
author"Felix Wu" <fsw534@gmail.com>
Mon, 31 Mar 2008 17:57:40 +0000 (10:57 -0700)
committer"Felix Wu" <fsw534@gmail.com>
Mon, 31 Mar 2008 17:57:40 +0000 (10:57 -0700)
Cython/Compiler/ExprNodes.py
Cython/Compiler/Parsing.py
Cython/Compiler/PyrexTypes.py

index 25e3a53a8e0fb8e513d82e2fef548b6bed9b39cc..f10853c5c8a22ac726693006ebfe8d201a84bad5 100644 (file)
@@ -1678,6 +1678,14 @@ class SimpleCallNode(ExprNode):
                         rhs = typecast(py_object_type, self.type, rhs)
                 else:
                     lhs = ""
+                # <fsw> added for generating C++ try/catch block
+                if func_type.exception_check == '+':
+                    code.putln(
+                    "try {%s%s;} catch(...) {CppExn2PyErr(); %s}" % (
+                        lhs,
+                        rhs,
+                        code.error_goto(self.pos)))
+                    return
                 code.putln(
                     "%s%s; %s" % (
                         lhs,
index 273536b771cf1bd5453518cc1f4eafb9bae73e81..da25abd9270dbcea1bf3c5c7c832e19446d248c6 100644 (file)
@@ -1645,6 +1645,9 @@ def p_exception_value_clause(s):
         if s.sy == '*':
             exc_check = 1
             s.next()
+        elif s.sy == '+':
+            exc_check = '+'
+            s.next()
         else:
             if s.sy == '?':
                 exc_check = 1
index 6ea568476ba14fc3bfc29a2a7d55198b651ef6e4..bf3e6f9f8a3a9d4d26faf65a90687f980112a95f 100644 (file)
@@ -747,8 +747,10 @@ class CFuncType(CType):
                 exc_clause = " except? %s" % self.exception_value
             elif self.exception_value:
                 exc_clause = " except %s" % self.exception_value
-            elif self.exception_check:
-                exc_clause = " except *"
+            elif self.exception_check == '+':
+                exc_clause = " except +"
+            else:
+                " except *"
         cc = self.calling_convention_prefix()
         if (not entity_code and cc) or entity_code.startswith("*"):
             entity_code = "(%s%s)" % (cc, entity_code)