[Cython] Cannot assign type 'set<size_t> &' to 'set<size_t>'
Dimitri Tcaciuc
dtcaciuc at gmail.com
Mon Dec 19 05:17:31 CET 2011
Hello everyone,
Here's a small test case I'm trying to compile. I'm trying to pass a
STL set reference to a method in a template class.
x.pyx:
from libcpp.set cimport set as cpp_set
cdef extern from "x.hh":
cdef cppclass Foo [T]:
Foo()
void set_x(cpp_set[size_t] & x)
cpdef func():
cdef Foo[int] foo
cdef cpp_set[size_t] x
cdef cpp_set[size_t] & xref = x
foo.set_x(xref)
x.hh:
#include <set>
template <typename T>
struct Foo {
void set_x(const std::set<size_t> & x) { /* do nothing */ }
};
To compile,
bash $ cython --cplus x.pyx
Which results in
foo.set_x(xref)
^
------------------------------------------------------------
x.pyx:15:18: Cannot assign type 'set<size_t> &' to 'set<size_t>'
However, if I remove the template parameter from Foo, everything works.
y.pyx:
from libcpp.set cimport set as cpp_set
cdef extern from "y.hh":
cdef cppclass Foo:
Foo()
void set_x(cpp_set[size_t] & x)
cpdef func():
cdef Foo foo
cdef cpp_set[size_t] x
cdef cpp_set[size_t] & xref = x
foo.set_x(xref)
y.hh:
#include <set>
struct Foo {
void set_x(const std::set<size_t> & x) { /* do nothing */ }
};
>From what I can tell, the CppClassType instance the CReferenceType is
pointing to has the correct name "set<size_t>", however it's a
different class instance. The particular failing expression is in
`ExprNode.coerce_to`
if not (str(src.type) == str(dst_type) or
dst_type.assignable_from(src_type))
I wish I could suggest a patch, but unfortunately I'm a complete
newbie to Cython internals. Perhaps someone could give a few pointers
as to what should be done to fix this?
Thanks,
Dimitri
More information about the cython-devel
mailing list