diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index b0c7e7ac37f529a82d8936c8fb0bb5299cdb7ae5..f6e2b7848bbc16479de00d91188fb1980a9a9b49 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -3939,7 +3939,7 @@ class TypecastNode(NewTempExprNode): if self.type.from_py_function: self.operand = self.operand.coerce_to(self.type, env) elif self.type.is_ptr and not (self.type.base_type.is_void or self.type.base_type.is_struct): - error(self.pos, "Python objects can only be cast to void*") + error(self.pos, "Python objects cannot be casted to pointers of primitive types") else: warning(self.pos, "No conversion from %s to %s, python object pointer used." % (self.type, self.operand.type)) elif from_py and to_py: diff --git a/tests/errors/e_tempcast.pyx b/tests/errors/e_tempcast.pyx index 7d80a1212220b850ff7f10aecd25da57902e6aca..4e59a41c9738d24adc81a8935b8b807be1149916 100644 --- a/tests/errors/e_tempcast.pyx +++ b/tests/errors/e_tempcast.pyx @@ -1,9 +1,10 @@ cdef object blarg def foo(obj): - cdef int *p - p = <int *>blarg # okay - p = <int *>(foo + blarg) # error - temporary + cdef void *p + p = <void *>blarg # ok + p = <void *>(obj + blarg) # error - temporary + _ERRORS = u""" 6:5: Casting temporary Python object to non-numeric non-Python type """ diff --git a/tests/errors/pyobjcastdisallow_T313.pyx b/tests/errors/pyobjcastdisallow_T313.pyx index 3d8ea1cea20ab3e4556ea12005f8537ccf08b300..18ca2b04ad8f80f55d56d3af602683d193d97ca6 100644 --- a/tests/errors/pyobjcastdisallow_T313.pyx +++ b/tests/errors/pyobjcastdisallow_T313.pyx @@ -5,5 +5,5 @@ cdef void* allowed = <void*>a cdef double* disallowed = <double*>a _ERRORS = u""" -5:26: Python objects can only be cast to void* +5:26: Python objects cannot be casted to pointers of primitive types """