C++ failures / tests
authorDavid Barnett <daviebdawg@gmail.com>
Sat, 15 May 2010 20:47:40 +0000 (13:47 -0700)
committerDavid Barnett <daviebdawg@gmail.com>
Sat, 15 May 2010 20:47:40 +0000 (13:47 -0700)
I noticed two failures to compile that I think are bugs:
 - "ctypedef Foo[int] Bar" gives a syntax error (i.e., there doesn't seem to be any way to typedef a templated type).
 - Defining a struct in a namespace and trying to convert it to a Python dict doesn't work. Instead you get nasty "__pyx_convert__to_py_THENAMESPACE" errors from the C++ compiler (it doesn't mangle the cname properly and tries to define __pyx_convert__to_py_THENAMESPACE::THESTRUCT).

I made a patch to *add tests* for the two bugs (not fix them).

tests/compile/cpp_structs.pyx [new file with mode: 0644]
tests/compile/cpp_templated_ctypedef.pyx [new file with mode: 0644]
tests/compile/point.h [new file with mode: 0644]

diff --git a/tests/compile/cpp_structs.pyx b/tests/compile/cpp_structs.pyx
new file mode 100644 (file)
index 0000000..c7b8693
--- /dev/null
@@ -0,0 +1,9 @@
+cdef extern from "point.h" namespace "geometry":
+
+    cdef struct Point:
+        double x
+        double y
+        int color
+
+cdef Point p = Point(0.0, 0.0, 0)
+the_point = p
diff --git a/tests/compile/cpp_templated_ctypedef.pyx b/tests/compile/cpp_templated_ctypedef.pyx
new file mode 100644 (file)
index 0000000..634b46f
--- /dev/null
@@ -0,0 +1,4 @@
+cdef extern from *:
+    cdef cppclass Foo[T]:
+        pass
+    ctypedef Foo[int] IntFoo
diff --git a/tests/compile/point.h b/tests/compile/point.h
new file mode 100644 (file)
index 0000000..866807c
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef POINT_H
+#define POINT_H
+
+namespace geometry {
+    
+    struct Point
+    {
+        double x;
+        double y;
+        int color;
+    };
+}
+
+#endif