I am writing a function that builds an malloc'd unsigned char * array, and then reconfigures the pointer. In pure Keaton or C it is easy. All you have to do is set the return type to the function and return a pointer to the array. Done. However, I have reached the point where I need to return a pointer to an array created in Cython in Python. I know that a pointer is just a memory address. Is there a way that I can return a Cython pointer to Python as a python object (e.g. int or hex, since the memory address is essentially a number), so I can then basically control pointers in python?
I tried to return the pointer value as follows:
cdef unsigned char array[8] def return_pointer(): return &array
This, of course, does not work, because it is impossible to perform the conversion. Keaton complains about Cannot convert 'unsigned char (*)[8]' to Python object . Any suggestions?
EDIT:
I do not need to access the value in the memory address pointed to by the pointer in Python, but only pass the pointer. Then I plan to use a pointer to a Python object and call c functions with it as an argument.
source share