[Cython] Templated attributes in extensions classes in 0.17 Beta 2
Stefan Behnel
stefan_ml at behnel.de
Mon Aug 20 08:41:04 CEST 2012
Brett Calcott, 20.08.2012 08:23:
> I'm not sure if this is a bug in 0.17 beta or not. But something is not working.
>
> Default-constructed attributes in an extension definition appear to
> work (though I can't see where they are documented on the site…)
>
> So this works:
>
> ----test.h --------
> #include <vector>
>
> struct Attributes
> {
> std::vector<int> v;
> };
>
> -----test.pyx------
> from libcpp.vector cimport vector
>
> cdef extern from "test.h":
> cdef cppclass Attributes:
> vector[int] v
>
> cdef class Test:
> cdef Attributes a
> def __cinit__(self, list x):
> self.a.v = x
>
>
> However, if I try to put the templated attribute in directly:
>
> ----test2.pyx------
> from libcpp.vector cimport vector
>
> cdef class Test:
> cdef vector[int] v
> def __cinit__(self, list x):
> self.v = x
>
> cython compiles it fine, but I get an error in the cpp compilation:
> test2.cpp:722:23: error: expected a type
> new((void*)&(p->v)) std::vector();
>
> So it looks like it's doing the funky in place construction, but not
> getting the template parameters in there…
>
> Should this work?
Yes, although (IIRC) not in beta 2. There was a recent fix for this, but it
broke other stuff. I'm waiting for a fix for those before I release yet
another beta (which will then hopefully be a release candidate).
In any case, thanks for the report!
Stefan
More information about the cython-devel
mailing list