Fixed gcc warning with list comprehensions
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Fri, 29 Aug 2008 20:44:11 +0000 (22:44 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Fri, 29 Aug 2008 20:44:11 +0000 (22:44 +0200)
Ticket 65

Cython/Compiler/ExprNodes.py
tests/run/listcomp.pyx [new file with mode: 0644]

index 1fd34af675c51cf511b03c771471517d63e4046a..703e1980c5cfe6e7de63024bad0d635f719dc8b9 100644 (file)
@@ -2619,7 +2619,7 @@ class ListComprehensionAppendNode(ExprNode):
         self.is_temp = 1
     
     def generate_result_code(self, code):
-        code.putln("%s = PyList_Append(%s, %s); %s" %
+        code.putln("%s = PyList_Append(%s, (PyObject*)%s); %s" %
             (self.result_code,
             self.target.result_code,
             self.expr.result_code,
diff --git a/tests/run/listcomp.pyx b/tests/run/listcomp.pyx
new file mode 100644 (file)
index 0000000..a63521f
--- /dev/null
@@ -0,0 +1,16 @@
+u"""
+>>> smoketest()
+[0, 4, 8]
+>>> typed()
+[A, A, A]
+"""
+
+def smoketest():
+    print [x*2 for x in range(5) if x % 2 == 0]
+
+cdef class A:
+    def __repr__(self): return "A"
+
+def typed():
+    cdef A obj
+    print [obj for obj in [A(), A(), A()]]
\ No newline at end of file