Commit 4e91e8fa authored by Robert Bradshaw's avatar Robert Bradshaw

Check return values before PyErr_Occurred() for coercion nodes.

parent c1609002
...@@ -3177,7 +3177,18 @@ class CoerceFromPyTypeNode(CoercionNode): ...@@ -3177,7 +3177,18 @@ class CoerceFromPyTypeNode(CoercionNode):
code.putln('%s = %s; %s' % ( code.putln('%s = %s; %s' % (
self.result_code, self.result_code,
rhs, 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): class CoerceToBooleanNode(CoercionNode):
......
...@@ -260,6 +260,8 @@ class CType(PyrexType): ...@@ -260,6 +260,8 @@ class CType(PyrexType):
to_py_function = None to_py_function = None
from_py_function = None from_py_function = None
exception_value = None
exception_check = 1
#class CSimpleType(CType): #class CSimpleType(CType):
...@@ -332,6 +334,7 @@ class CIntType(CNumericType): ...@@ -332,6 +334,7 @@ class CIntType(CNumericType):
typedef_flag = 0 typedef_flag = 0
to_py_function = "PyInt_FromLong" to_py_function = "PyInt_FromLong"
from_py_function = "PyInt_AsLong" from_py_function = "PyInt_AsLong"
exception_value = -1
def __init__(self, rank, signed, pymemberdef_typecode = None, is_returncode = 0): def __init__(self, rank, signed, pymemberdef_typecode = None, is_returncode = 0):
CNumericType.__init__(self, rank, signed, pymemberdef_typecode) CNumericType.__init__(self, rank, signed, pymemberdef_typecode)
...@@ -347,33 +350,35 @@ class CBIntType(CIntType): ...@@ -347,33 +350,35 @@ class CBIntType(CIntType):
# and no error checking should be needed (just an incref). # and no error checking should be needed (just an incref).
to_py_function = "__Pyx_PyBool_FromLong" to_py_function = "__Pyx_PyBool_FromLong"
from_py_function = "__Pyx_PyObject_IsTrue" from_py_function = "__Pyx_PyObject_IsTrue"
exception_check = 0
class CPySSizeTType(CIntType): class CPySSizeTType(CIntType):
to_py_function = "PyInt_FromSsize_t" to_py_function = "PyInt_FromSsize_t"
from_py_function = "__pyx_PyIndex_AsSsize_t" from_py_function = "__pyx_PyIndex_AsSsize_t"
exception_value = None
class CUIntType(CIntType): class CUIntType(CIntType):
to_py_function = "PyLong_FromUnsignedLong" to_py_function = "PyLong_FromUnsignedLong"
from_py_function = "PyInt_AsUnsignedLongMask" from_py_function = "PyInt_AsUnsignedLongMask"
exception_value = None
class CULongType(CIntType): class CULongType(CUIntType):
to_py_function = "PyLong_FromUnsignedLong" to_py_function = "PyLong_FromUnsignedLong"
from_py_function = "PyInt_AsUnsignedLongMask" from_py_function = "PyInt_AsUnsignedLongMask"
class CLongLongType(CIntType): class CLongLongType(CUIntType):
to_py_function = "PyLong_FromLongLong" to_py_function = "PyLong_FromLongLong"
from_py_function = "PyInt_AsUnsignedLongLongMask" from_py_function = "PyInt_AsUnsignedLongLongMask"
class CULongLongType(CIntType): class CULongLongType(CUIntType):
to_py_function = "PyLong_FromUnsignedLongLong" to_py_function = "PyLong_FromUnsignedLongLong"
from_py_function = "PyInt_AsUnsignedLongLongMask" from_py_function = "PyInt_AsUnsignedLongLongMask"
...@@ -703,6 +708,7 @@ class CStringType: ...@@ -703,6 +708,7 @@ class CStringType:
to_py_function = "PyString_FromString" to_py_function = "PyString_FromString"
from_py_function = "PyString_AsString" from_py_function = "PyString_AsString"
exception_value = "NULL"
def literal_code(self, value): def literal_code(self, value):
return '"%s"' % value return '"%s"' % value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment