Reputation: 41
I need to pass non NULL terminating buffer from Python to C++. I'm using parameter of signed char* type instead of char* since latter will be converted to NULL terminating string. The Python interface was generated using SWIG (2.0.1). No typemaps were applied so SWIG should use its default mapping. When I'm trying to use the method I get the following error:
NotImplementedError: Wrong number or type of arguments for overloaded function
As buffer I tried passing both string and bytearray objects. In both cases I get the mentioned error.
So if I have function like this in C++ what type of object should I pass to it in Python ?
void set_value(signed char *buffer, int size)
Upvotes: 1
Views: 323
Reputation: 29591
You might be able to inline a wrapper that accepts a C++ string (which are not null terminated), it would be something like this:
%include <std_string.i>
%inline %{
void set_value_str(const std::string& str) { set_value(str.c_str(), str.size()); }
%}
The std_string.i
defines typemaps that will allow you to call set_value_str
with a Python string as argument. However I don't know if the typemap uses the char array version of std::string
constructor, this could invalidate this approach if your buffer can contain null bytes.
Note: You can name your wrapper set_value
, doesn't have to be a different name.
Upvotes: 0