[Cython] Can't call functions with multi-token template arguments such as 'char *'

Michael Enßlin michael at ensslin.cc
Fri Jun 12 13:01:42 CEST 2015


Hi,

it seems to be impossible to use anything but a single word as a
template type for functions.

Classes don't suffer from this issue, as seen below.

As a workaround, complex types can be ctypedef-d to a single word (also
seen below).

$ cat t10.pyx

cdef extern from "nope.h":
    cdef cppclass bar[T]:
        void func(T arg)

    void foo[T](T arg)


ctypedef char * charptr


def test():
    # works
    cdef bar[char *] barobj
    barobj.func(NULL)

    # works
    foo[int](5)

    # works
    foo[charptr](NULL)

    # fails
    foo[char *](NULL)



$ cython --cplus t10.pyx

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

    # works
    foo[charptr](NULL)

    # fails
    foo[char *](NULL)
             ^
------------------------------------------------------------

t10.pyx:27:14: Expected an identifier or literal



Happy debugging,
	~ mic_e

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20150612/5bfddbfa/attachment.sig>


More information about the cython-devel mailing list