Add casting to const
authorVolker Mische <volker.mische@gmail.com>
Wed, 3 Apr 2013 15:05:10 +0000 (17:05 +0200)
committerVolker Mische <volker.mische@gmail.com>
Wed, 3 Apr 2013 15:05:10 +0000 (17:05 +0200)
The included test is derived from a real world case
which would lead to warnings in GCC if the pointer
wouldn't be explicitly casted to const.

Cython/Compiler/Nodes.py
tests/compile/constcast.pyx [new file with mode: 0644]

index f4b3852..57ff09f 100644 (file)
@@ -1125,9 +1125,11 @@ class FusedTypeNode(CBaseTypeNode):
 
 
 class CConstTypeNode(CBaseTypeNode):
+    # name          string
     # base_type     CBaseTypeNode
 
     child_attrs = ["base_type"]
+    name = 'const'
 
     def analyse(self, env, could_be_name = False):
         base = self.base_type.analyse(env, could_be_name)
diff --git a/tests/compile/constcast.pyx b/tests/compile/constcast.pyx
new file mode 100644 (file)
index 0000000..3bbc0e3
--- /dev/null
@@ -0,0 +1,8 @@
+# mode: compile
+from libc.stdlib cimport malloc, free
+
+cdef void f():
+    cdef const int **allocated = <const int **>malloc(sizeof(int *))
+    free(allocated)
+
+f()