I am trying to get a python c extension to work. The extension is used in a package which registers a python callback with the extension and then the extension calls it to communicate with the python code.
The extension has a struct variable which I would like to have available in the python code. I have been successfull in passing the C struct as a PyCapsule and I can indeed get it in my python. However now I need to actually access the data inside that PyCapsule, which of course has not idea of what it is holding (all it knows is it has a void*). I was wondering if I could somehow use the void pointer inside the capsule to create a memory-compatible ctype.
I know this is not the best way to go about it. I tried creating a new PythonType as it is explained here https://docs.python.org/3/extending/newtypes.html#generic-attribute-management But for the life of me I can't get it to compile, I keep getting a meaningless error saying
expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pybison’
The error line points to the first line of this struct instantiation:
static PyModuleDef noddy2module = {
PyModuleDef_HEAD_INIT,
"noddy2",
"Example module that creates an extension type.",
-1,
NULL, NULL, NULL, NULL, NULL
};