0
votes

I am trying to declare a Cython class in a pxd file but can't compile it when I try to assign a pointer.

The following pyx compiles fine :

cdef class Foo:
    cdef void *_void

    cdef set_ptr(self, void *ptr):
        self._void = ptr

But when I split it in 2 files according to the Cython documentation :
.pxd

cdef class Foo:
    cdef void *_void
    cdef set_ptr(self, void *ptr)

.pyx

cdef class Foo:
    cdef set_ptr(self, void *ptr):
        self._void = ptr

I get the following error:

Error compiling Cython file:
------------------------------------------------------------
...
# -*- coding: utf-8 -*-

cdef class Foo:
    cdef set_ptr(self, void *ptr):
        self._void = ptr
                    ^
------------------------------------------------------------

test/test.pyx:5:21: Cannot convert 'void *' to Python object

What can I do to make it compile ?

1
It works for me with the exact code you posted. Does the name of your pxd file match that of your pyx? - DavidW
@DavidW Thanks for your sugestion. The files had indeed the same name, but the problem came from the name of the lib in setup.py, which was different from the name of the files - Saelyos

1 Answers

0
votes

By making the name of the Extension in setup.py the same as the name of the pxd and pyx files, it solved the issue. It seems that Cyhton was not compiling the pxd file otherwise.