%module odirectcmodule %begin %{ #define SWIG_PYTHON_STRICT_BYTE_CHAR %} %{ #include "odirect.h" /* For 2.x, we'd want PyString_FromStringAndSize. ** For 3.x, we want PyBytes_FromStringAndSize, or perhaps PyUnicode_FromStringAndSize. ** ** In the swig doc, the 2nd parameter of PyString_FromStringAndSize is not a long, it's an "lint", whatever that is. ** http://www.swig.org/Doc1.3/Python.html#Python_python3support ** ** But we don't need PyString_FromStringAndSize for 3.x. We do for 2.x. */ %} %typemap(out) struct binary_data { $result = PyBytes_FromStringAndSize($1.data, $1.size); } %init %{ %} %include "odirect.h"