How Python can get binary data(char*) from C++ by SWIG?

后端 未结 3 821
忘掉有多难
忘掉有多难 2020-12-21 04:38

I am using C++ functions in Python by SWIG,and I met a problem now. When I pass a char * from C++ to Python, the char * is truncted by Python.

For example:

e

3条回答
  •  情话喂你
    2020-12-21 05:00

    See 8.3 C String Handling in the documentation.

    Also from the documentation:

    The char * datatype is handled as a NULL-terminated ASCII string. SWIG maps this into a 8-bit character string in the target scripting language. SWIG converts character strings in the target language to NULL terminated strings before passing them into C/C++. The default handling of these strings does not allow them to have embedded NULL bytes. Therefore, the char * datatype is not generally suitable for passing binary data. However, it is possible to change this behavior by defining a SWIG typemap. See the chapter on Typemaps for details about this.

提交回复
热议问题