%typemap(argout) bool &success { PyObject *o, *o2, *o3; o = PyBool_FromLong(*$1); if ((!$result) || ($result == Py_None)) { $result = o; } else { if (!PyTuple_Check($result)) { PyObject *o2 = $result; $result = PyTuple_New(1); PyTuple_SetItem($result,0,o2); } o3 = PyTuple_New(2); PyTuple_SetItem(o3,0,o); PyTuple_SetItem(o3,1,$result); $result = o3; } } %typemap(in,numinputs=0) bool &success(bool temp) { $1 = &temp; } // bytearrays are new as of 2.6 %{ #if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 6) || PY_MAJOR_VERSION > 2 #define MODERN_PYTHON #endif %} // abac_chunk_t is a bytearray or a string %typemap(in) abac_chunk_t %{ #ifdef MODERN_PYTHON $1.ptr = (unsigned char *)PyByteArray_AS_STRING($input); $1.len = PyByteArray_GET_SIZE($input); #else PyString_AsStringAndSize( $input, (char **)&$1.ptr, &$1.len ); #endif %} %typemap(out) abac_chunk_t %{ #ifdef MODERN_PYTHON $result = PyByteArray_FromStringAndSize( (const char *)$1.ptr, $1.len ); #else $result = PyString_FromStringAndSize( (const char *)$1.ptr, $1.len ); #endif %}