I have searched online for a while, but what is the correct way to pass bytes to and fro between Python and C? I have leveraged the example from SWIG documentation:
C Code:
char* foo(char *buff, int size)
{
return buff;
}
Wrapper code:
%include <pybuffer.i>
%pybuffer_binary(char *buff, int size);
char* foo(char *buff, int size);
Error:
example_wrap.c: In function ‘_wrap_foo’:
example_wrap.c:3385:19: error: ‘size’ undeclared (first use in this function)
arg2 = (int) (size / sizeof(char));
example_wrap.c:3385:19: note: each undeclared identifier is reported only once for each function it appears in
example_wrap.c:3387:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
result = (char *)foo(arg1,arg2);
EDIT: the Include pybuffer.i: https://github.com/swig/swig/blob/master/Lib/python/pybuffer.i