From: Robert Bradshaw Date: Fri, 7 Sep 2007 09:49:43 +0000 (-0700) Subject: Check return values before PyErr_Occurred() for coercion nodes. X-Git-Tag: 0.9.6.14~29^2~148 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4e91e8fa2cbf9d09f271a477df6a9cb40d0c6b85;p=cython.git Check return values before PyErr_Occurred() for coercion nodes. --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index dfdaf6f2..f4e59964 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -3177,7 +3177,18 @@ class CoerceFromPyTypeNode(CoercionNode): code.putln('%s = %s; %s' % ( self.result_code, rhs, - code.error_goto_if_PyErr(self.pos))) + code.error_goto_if(self.error_cond(), self.pos))) + + def error_cond(self): + conds = [] + if self.type.exception_value is not None: + conds.append("(%s == %s)" % (self.result_code, self.type.exception_value)) + if self.type.exception_check: + conds.append("PyErr_Occurred()") + if len(conds) > 0: + return " && ".join(conds) + else: + return 0 class CoerceToBooleanNode(CoercionNode): diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 594f8836..b4ac6ed9 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -260,6 +260,8 @@ class CType(PyrexType): to_py_function = None from_py_function = None + exception_value = None + exception_check = 1 #class CSimpleType(CType): @@ -332,6 +334,7 @@ class CIntType(CNumericType): typedef_flag = 0 to_py_function = "PyInt_FromLong" from_py_function = "PyInt_AsLong" + exception_value = -1 def __init__(self, rank, signed, pymemberdef_typecode = None, is_returncode = 0): CNumericType.__init__(self, rank, signed, pymemberdef_typecode) @@ -347,33 +350,35 @@ class CBIntType(CIntType): # and no error checking should be needed (just an incref). to_py_function = "__Pyx_PyBool_FromLong" from_py_function = "__Pyx_PyObject_IsTrue" + exception_check = 0 class CPySSizeTType(CIntType): to_py_function = "PyInt_FromSsize_t" from_py_function = "__pyx_PyIndex_AsSsize_t" - + exception_value = None class CUIntType(CIntType): to_py_function = "PyLong_FromUnsignedLong" from_py_function = "PyInt_AsUnsignedLongMask" + exception_value = None -class CULongType(CIntType): +class CULongType(CUIntType): to_py_function = "PyLong_FromUnsignedLong" from_py_function = "PyInt_AsUnsignedLongMask" -class CLongLongType(CIntType): +class CLongLongType(CUIntType): to_py_function = "PyLong_FromLongLong" from_py_function = "PyInt_AsUnsignedLongLongMask" -class CULongLongType(CIntType): +class CULongLongType(CUIntType): to_py_function = "PyLong_FromUnsignedLongLong" from_py_function = "PyInt_AsUnsignedLongLongMask" @@ -703,6 +708,7 @@ class CStringType: to_py_function = "PyString_FromString" from_py_function = "PyString_AsString" + exception_value = "NULL" def literal_code(self, value): return '"%s"' % value