Hi,
I am using cython 0.17 on Ubuntu 12.04 x64. I had found a problem when I use fused types and class inheritance
This is my example code:
from libcpp.string cimport string
from libc.stdint cimport uint64_t
ctypedef fused attribute_key_fused_type:
string
long
cdef class EntityBase:
cdef:
string _key
def __init__(self, key):
if isinstance(key, str):
self.setKey(<string>key)
elif type(key) is long:
self.setKey(<long>key)
cdef void setKey(self, attribute_key_fused_type key):
if attribute_key_fused_type is string:
self._key = key
elif attribute_key_fused_type is long:
pass
If you use only this code runs ok, but if you create a inherited class as for example:
cdef class Entity(EntityBase):
pass
Now I have problems with C++ code generated:
test.cpp:421:78: error: declaration of ‘void (* __pyx_vtabstruct_4test_EntityBase::__pyx_fuse_0setKey)(__pyx_obj_4test_EntityBase*, std::string)’
test.cpp:419:78: error: conflicts with previous declaration ‘void (* __pyx_vtabstruct_4test_EntityBase::__pyx_fuse_0setKey)(__pyx_obj_4test_EntityBase*, std::string)’
test.cpp:422:71: error: declaration of ‘void (* __pyx_vtabstruct_4test_EntityBase::__pyx_fuse_1setKey)(__pyx_obj_4test_EntityBase*, long int)’
test.cpp:420:71: error: conflicts with previous declaration ‘void (* __pyx_vtabstruct_4test_EntityBase::__pyx_fuse_1setKey)(__pyx_obj_4test_EntityBase*, long int)’
Going to test.cpp file I have this:
/* "test.pyx":42
* long
*
* cdef class EntityBase: # <<<<<<<<<<<<<<
* cdef:
* string _key
*/
struct __pyx_vtabstruct_4test_EntityBase {
void (*__pyx_fuse_0setKey)(struct __pyx_obj_4test_EntityBase *, std::string);
void (*__pyx_fuse_1setKey)(struct __pyx_obj_4test_EntityBase *, long);
void (*__pyx_fuse_0setKey)(struct __pyx_obj_4test_EntityBase *, std::string);
void (*__pyx_fuse_1setKey)(struct __pyx_obj_4test_EntityBase *, long);
};
The prototype functions for string and long is duplicated in the same class then g++ can not compile the source code
if anyone can solve this problem I would greatly appreciate
Best Regards
Javier