source: swig/python/chunk.i @ fc9548a

abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change on this file since fc9548a was b099964, checked in by Mike Ryan <mikeryan@…>, 14 years ago

compile error in python swig

  • Property mode set to 100644
File size: 779 bytes
RevLine 
[a5a8234]1// bytearrays are new as of 2.6
2%{
3#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 6) || PY_MAJOR_VERSION > 2
4#define MODERN_PYTHON
5#endif
6%}
7
8// abac_chunk_t is a bytearray or a string
9%typemap(in) abac_chunk_t %{
[bc62c32]10    if (PyString_Check($input))
11        PyString_AsStringAndSize(
12            $input,
13            (char **)&$1.ptr,
[b099964]14            (Py_ssize_t *)&$1.len
[bc62c32]15        );
[a5a8234]16#ifdef MODERN_PYTHON
[bc62c32]17    else if (PyByteArray_Check($input)) {
18        $1.ptr = (unsigned char *)PyByteArray_AS_STRING($input);
19        $1.len = PyByteArray_GET_SIZE($input);
20    }
[a5a8234]21#endif
[bc62c32]22    else
23        SWIG_exception(SWIG_TypeError, "Expected string or byte array");
[a5a8234]24%}
25
26%typemap(out) abac_chunk_t %{
27    $result = PyString_FromStringAndSize(
28        (const char *)$1.ptr,
29        $1.len
30    );
31%}
Note: See TracBrowser for help on using the repository browser.