Fused types problems with class inheritance

141 views
Skip to first unread message

Javier Baez

unread,
Oct 10, 2012, 11:57:29 PM10/10/12
to cython...@googlegroups.com
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

Marc-Alexandre Côté

unread,
Aug 11, 2014, 4:47:39 PM8/11/14
to cython...@googlegroups.com
I have the same problem. Have you found a solution?

Marc-Alexandre Côté

unread,
Aug 13, 2014, 9:38:39 AM8/13/14
to cython...@googlegroups.com
I am using Cython 0.20.2 on LinuxMint 17 x64.

I created a basic example to reproduce the error:

Does someone encounter this problem before?

Javier Baez

unread,
Sep 9, 2014, 5:26:12 PM9/9/14
to cython...@googlegroups.com
Hi Marc,

I never fix the error because currently, I am not using Cython in my project.

Best regards

--

---
You received this message because you are subscribed to a topic in the Google Groups "cython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cython-users/HPgmlIMabz0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cython-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stefan Behnel

unread,
Sep 10, 2014, 12:08:48 AM9/10/14
to cython...@googlegroups.com
> I am using Cython 0.20.2 on LinuxMint 17 x64.
>
> I created a basic example to reproduce the error:
> https://gist.github.com/MarcCote/8ea8bb5d31bea8d5da66

This is now

http://trac.cython.org/cython_trac/ticket/833

Sorry it took so long to have anyone respond. Let's try to get this fixed
for 0.21.1.

Stefan

Marc-Alexandre Côté

unread,
Sep 10, 2014, 9:35:44 AM9/10/14
to cython...@googlegroups.com
Great, thanks

Marc

Marc-Alexandre Côté

unread,
Jun 21, 2015, 1:52:41 PM6/21/15
to cython...@googlegroups.com
Any development on this issue? I can confirm it is still there in Cython
0.23dev.

Marc

On 14-09-10 12:08 AM, Stefan Behnel wrote:

Stefan Behnel

unread,
Jun 21, 2015, 1:54:57 PM6/21/15
to cython...@googlegroups.com
> Any development on this issue? I can confirm it is still there in Cython
> 0.23dev.

No-one is working on it AFAICT.

Stefan

arjangi...@gmail.com

unread,
Mar 17, 2016, 8:14:06 AM3/17/16
to cython-users, stef...@behnel.de
Hi,

I ran into this bug as well and believe I traced back the problem. In Symtab.py, CClassScope.declare_inherited_c_attributes() forces the base class to be fully specialized early on in the parsing pipeline (i.e., fused types are specialized to all possible types). Later on, FusedCFuncDefNode.copy_cdef() visits the base class again and attempts a time to specialize the methods containing fused types. So this is why we end up with duplicate entries in the vtable of the base class.

I managed to compile the example by adding a check for duplicate entries when FusedCFuncDefNode.copy_cdef() specializes the fused types (i.e., simply removing the earlier entry from env.cfunc_entries when there is a cname collision). However, this is just a minimal workaround and not a real fix, plus that I still hit a redeclaration problem when adding a third level of inheritance.

Would there be a way to get some attention to this bug from more seasoned cython contributors?

Cheers,

Arjan

Julien Jerphanion

unread,
Jul 6, 2021, 1:38:26 PM7/6/21
to cython-users
Just for future readers' information: I've been able to compile both reproducers with Cython 0.29.23.
Reply all
Reply to author
Forward
0 new messages