From 14ec6047844d736fb8efcf416f5ec773cf9235c3 Mon Sep 17 00:00:00 2001 From: "\"Felix Wu\"" Date: Mon, 31 Mar 2008 10:57:40 -0700 Subject: [PATCH] Cython and C++ exceptions --- Cython/Compiler/ExprNodes.py | 8 ++++++++ Cython/Compiler/Parsing.py | 3 +++ Cython/Compiler/PyrexTypes.py | 6 ++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 25e3a53a..f10853c5 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1678,6 +1678,14 @@ class SimpleCallNode(ExprNode): rhs = typecast(py_object_type, self.type, rhs) else: lhs = "" + # 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, diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 273536b7..da25abd9 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -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 diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 6ea56847..bf3e6f9f 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -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) -- 2.26.2