Fix cpp exception catching.
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 22 Oct 2009 09:50:29 +0000 (02:50 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 22 Oct 2009 09:50:29 +0000 (02:50 -0700)
Cython/Compiler/Nodes.py

index 9144f2282c44940739fb5716a1add2af2b518951..29eb0b15f42ac52d9b28c65240ddc2eb89fb04c1 100644 (file)
@@ -547,17 +547,23 @@ class CFuncDeclaratorNode(CDeclaratorNode):
             if self.exception_value:
                 self.exception_value.analyse_const_expression(env)
                 if self.exception_check == '+':
+                    self.exception_value.analyse_types(env)
                     exc_val_type = self.exception_value.type
                     if not exc_val_type.is_error and \
                           not exc_val_type.is_pyobject and \
                           not (exc_val_type.is_cfunction and not exc_val_type.return_type.is_pyobject and len(exc_val_type.args)==0):
                         error(self.exception_value.pos,
                             "Exception value must be a Python exception or cdef function with no arguments.")
+                    exc_val = self.exception_value
                 else:
-                    exc_val = self.exception_value.get_constant_c_result_code()
-                    if not return_type.assignable_from(self.exception_value.type):
-                        error(self.exception_value.pos,
-                              "Exception value incompatible with function return type")
+                    if self.exception_value.analyse_const_expression(env):
+                        exc_val = self.exception_value.get_constant_c_result_code()
+                        if exc_val is None:
+                            raise InternalError("get_constant_c_result_code not implemented for %s" %
+                                self.exception_value.__class__.__name__)
+                        if not return_type.assignable_from(self.exception_value.type):
+                            error(self.exception_value.pos,
+                                  "Exception value incompatible with function return type")
             exc_check = self.exception_check
         if return_type.is_array:
             error(self.pos,