I'm creating a cython wrapper around the lirc library. I've had to wrap up the lirc_config struct as described by the tutorial but I need to pass a struct lirc_config *
to a function in the library.
So, the struct in question is (from /usr/include/lirc/lirc_client.h):
struct lirc_config {
char *current_mode;
struct lirc_config_entry *next;
struct lirc_config_entry *first;
int sockfd;
};
and the function I need to call is:
int lirc_code2char(struct lirc_config *config, char *code, char **string);
Here is my cython wrapper around struct lirc_config
:
cdef class LircConfig:
cdef lirc_client.lirc_config * _c_lirc_config
def __cinit__(self, config_file):
lirc_client.lirc_readconfig(config_file, &self._c_lirc_config, NULL)
if self._c_lirc_config is NULL:
raise MemoryError()
def __dealloc__(self):
if self._c_lirc_config is not NULL:
lirc_client.lirc_freeconfig(self._c_lirc_config)
and the problematic line:
config = LircConfig(configname)
lirc_client.lirc_code2char(config, code, &character)
config
needs to be a pointer to the struct. This:
lirc_client.lirc_code2char(&config, code, &character)
gives me the error:
cylirc.pyx:76:39: Cannot take address of Python variable
which makes sense because the &
is trying to access the address of LircConfig.
This:
lirc_client.lirc_code2char(config._c_lirc_config, code, &character)
gives me the error:
cylirc.pyx:76:45: Cannot convert Python object to 'lirc_config *'
Hm, I thought I defined config._c_lirc_config
as cdef lirc_client.lirc_config *
. I can't seem to access the value of the struct lirc_config *
.
I've tried casting and also adding the public tag to _c_lirc_config (as mentioned at the bottom of the Extension types document).
I have no idea how to call the lirc_code2char
function, because cython won't let me access the struct lirc_config pointer. Any Cython experts out there?