reverted last commit, cast must happen to the value, not its pointer
authorStefan Behnel <scoder@users.berlios.de>
Sun, 2 May 2010 16:10:39 +0000 (18:10 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 2 May 2010 16:10:39 +0000 (18:10 +0200)
Cython/Compiler/ExprNodes.py

index 8fa34fcf1728834ad88c4d31b628f18d8aeb0e6d..eb164973603bba1e176e769c589868251f9ed614 100755 (executable)
@@ -6252,10 +6252,17 @@ class CoerceIntToBytesNode(CoerceToPyTypeNode):
                        '"value too large to pack into a byte"); %s' % (
                            code.error_goto(self.pos)))
             code.putln('}')
-        code.putln('%s = PyBytes_FromStringAndSize((const char*)&%s, 1); %s' % (
+        temp = None
+        if arg.type is not PyrexTypes.c_char_type:
+            temp = code.funcstate.allocate_temp(PyrexTypes.c_char_type, manage_ref=False)
+            code.putln("%s = (char)%s;" % (temp, arg_result))
+            arg_result = temp
+        code.putln('%s = PyBytes_FromStringAndSize(&%s, 1); %s' % (
             self.result(),
             arg_result,
             code.error_goto_if_null(self.result(), self.pos)))
+        if temp is not None:
+            code.funcstate.release_temp(temp)
         code.put_gotref(self.py_result())