source: swig/python/chunk.i @ 8164e70

abac0-leak
Last change on this file since 8164e70 was b099964, checked in by Mike Ryan <mikeryan@…>, 13 years ago

compile error in python swig

  • Property mode set to 100644
File size: 779 bytes
Line 
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 %{
10    if (PyString_Check($input))
11        PyString_AsStringAndSize(
12            $input,
13            (char **)&$1.ptr,
14            (Py_ssize_t *)&$1.len
15        );
16#ifdef MODERN_PYTHON
17    else if (PyByteArray_Check($input)) {
18        $1.ptr = (unsigned char *)PyByteArray_AS_STRING($input);
19        $1.len = PyByteArray_GET_SIZE($input);
20    }
21#endif
22    else
23        SWIG_exception(SWIG_TypeError, "Expected string or byte array");
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.