autowrap icon indicating copy to clipboard operation
autowrap copied to clipboard

[autowrap 0.6.1] instanced templated typedefs and "wrap-instance"-ed types can have name collisions

Open Eliasvan opened this issue 9 years ago • 2 comments

Tested with commit d0e9a5 (Feb 9, 2015). In some cases, a C++ header may define a typedef to a specific instantiation of a templated class, but it seems to be impossible to both create the typedef in the ".pxd"-file, and wrap that instantiation to Python (with the same name).

Test code (replaced variable names):

cdef extern from "eggs.hpp" namespace "bar":
    cdef cppclass Eggs:
        Eggs()

cdef extern from "foo.hpp" namespace "bar":
    cdef cppclass Foo[Spam]:
        # wrap-instances:
        #   Foo_Eggs := Foo[Eggs]
        Foo()
    ctypedef Foo[Eggs] Foo_Eggs

After autowrap has created the ".pyx"-file without warnings, but Cython fails to compile it:

Error compiling Cython file:
------------------------------------------------------------
...

cdef class Foo_Eggs:
    ^
------------------------------------------------------------

bar_ext.pyx:1178:5: 'Foo_Eggs' redeclared

Some extra name mangling in autowrap is needed to make it work, since Cython doesn't complain when the typedef is altered to, e.g.:

ctypedef Foo[Eggs] Foo_Eggs_

or:

ctypedef Foo[Eggs] Foo_Eggs_ "Foo_Eggs"

Eliasvan avatar May 09 '15 18:05 Eliasvan

I just tried this and ran into the same issue.

git log -n 1
commit d0f0fed094bee2caddbd15c5e8cc2d7b4c29b2e0
Merge: 98f4656 913de92
Author: Uwe Schmitt <[email protected]>
Date:   Wed Jan 25 20:09:49 2017 +0100

    Merge pull request #58 from hroest/support_36
    
    Python 3.6 support

weegreenblobbie avatar Feb 12 '17 07:02 weegreenblobbie

Do you need this typedef in the Python API ? I guess you can remove this.

The

# wrap-instances:
#   Foo_Eggs := Foo[Eggs]

will implement a Python class Foo_Eggs which wrapps Foo<Eggs> and the ctypedef Foo[Eggs] Foo_Eggs is not necessary for this..

uweschmitt avatar Feb 12 '17 09:02 uweschmitt