python - Passing a byte array to a C++ function that accepts a void pointer -
i'm using boost::python export c++ functions expect void*
. interpret raw memory (an array of bytes) internally. think read
, write
special purpose device.
how pass python bytearray
such function?
i have tried using ctypes.c_void_p.from_buffer(mybytearray)
doesn't match signature of function.
here's minimal example:
#include <boost/python.hpp> void fun_voidp(void*) {} boost_python_module(tryit) { using namespace boost::python; def("fun_voidp", fun_voidp); }
and @ 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
i'd fix function prototype take char*
, go last python line.
there's no reason use void*
in c++. understand if api does, shouldn't hard wrap own function.
Comments
Post a Comment