[Using C API] Error: Cannot convert 'void *' to Python object.

359 views
Skip to first unread message

Sean

unread,
Jul 29, 2020, 1:47:58 AM7/29/20
to cython...@googlegroups.com

Hi all,

I am trying to write a wrapper for OpenAL.

This is the definition of the function I want to wrap in alc.h:
...
/ ** Returns information about the device, and error strings. * /
const ALCchar* alcGetString(ALCdevice * device, ALCenum param);
...

This is the definition in OpenAL.pxd: (I wrote):
...
const ALCchar* alcGetString(ALCdevice *device, ALCenum param)
...



The error returns when I want to use this function in any file.
Usage is as follows:

cpdef defaultDevice():
    return alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER)

I can't see any str. How can I see the char data returned by the function in Python.
How can I use the data sent by the function in print ().

So I want to do this:
print(defaultDevice())


Sean

👨‍🦯 I’m programmer. I coding often Python, sometimes Go and rarely C++.

_OpenAL.pxd
default.pyx

Stefan Behnel

unread,
Jul 29, 2020, 7:36:47 AM7/29/20
to cython...@googlegroups.com
Sean schrieb am 29.07.20 um 07:41:
> I am trying to write a wrapper for OpenAL.
>
> This is the definition of the function I want to wrap in alc.h:
> ...
> / ** Returns information about the device, and error strings. * /
> const ALCchar* alcGetString(ALCdevice * device, ALCenum param);
> ...
>
> This is the definition in OpenAL.pxd: (I wrote):
> ...
> const ALCchar* alcGetString(ALCdevice *device, ALCenum param)
> ...
>
>
>
> The error returns when I want to use this function in any file.
> Usage is as follows:
>
> cpdef defaultDevice():
>     return alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER)

The return type of this function is a Python object (by default), so Cython
will try to convert the "ALCchar*" to an object. How did you declare
"ALCchar"? Is that something like "char" or "unsigned char" or so?


> I can't see any str. How can I see the char data returned by the function
> in Python.

Depends on the semantics of the C character data: bytes or text, and if the
letter, with which encoding?

The docs might be helpful here:
https://cython.readthedocs.io/en/latest/src/tutorial/strings.html

Stefan
Reply all
Reply to author
Forward
0 new messages