I'm using boost::python to export some C++ functions that expect a void*. They interpret it as raw memory (an array of bytes) internally. Think read and write for some very special purpose device.
How do I pass a Python bytearray to such a function?
I have tried using ctypes.c_void_p.from_buffer(mybytearray) but this doesn't match the signature of the function.
Here's the minimal example:
#include <boost/python.hpp>
void fun_voidp(void*) {}
BOOST_PYTHON_MODULE(tryit) {
using namespace boost::python;
def("fun_voidp", fun_voidp);
}
And at the python side:
import tryit
import ctypes
b = bytearray(100)
tryit.fun_voidp(b) # fail
tryit.fun_voidp(ctypes.c_void_p.from_buffer(b)) # fail
tryit.fun_voidp(ctypes.c_void_p.from_buffer(b).value) # fail