| 1 |
// This tells SWIG to treat char ** as a special case |
| 2 |
%typemap(in) char ** { |
| 3 |
// Check if is a list |
| 4 |
if (PyList_Check($input)) { |
| 5 |
Py_ssize_t size = PyList_Size($input); |
| 6 |
int i = 0; |
| 7 |
$1 = (char **) malloc((size+1)*sizeof(char *)); |
| 8 |
for (i = 0; i < size; i++) { |
| 9 |
PyObject *o = PyList_GetItem($input,i); |
| 10 |
%#if PY_VERSION_HEX>=0x03000000 |
| 11 |
if (PyUnicode_Check(o)) |
| 12 |
%#else |
| 13 |
if (PyString_Check(o)) |
| 14 |
%#endif |
| 15 |
//$1[i] = PyString_AsString(PyList_GetItem($input,i)); |
| 16 |
//$1[i] = SWIG_Python_str_AsChar(PyList_GetItem($input,i)); |
| 17 |
$1[i] = const_cast<char*>(PyUnicode_AsUTF8(PyList_GetItem($input,i))); |
| 18 |
else { |
| 19 |
PyErr_SetString(PyExc_TypeError,"list must contain strings"); |
| 20 |
free($1); |
| 21 |
return NULL; |
| 22 |
} |
| 23 |
} |
| 24 |
$1[i] = 0; |
| 25 |
} else { |
| 26 |
PyErr_SetString(PyExc_TypeError,"not a list"); |
| 27 |
return NULL; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
// This cleans up the char ** array we malloc'd before the function call |
| 32 |
%typemap(freearg) char ** { |
| 33 |
free((char *) $1); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
%define MACRO_WINDOW_SHOW |
| 38 |
void show(PyObject *count = 0, PyObject *data = 0) |
| 39 |
{ |
| 40 |
Py_XINCREF(count); |
| 41 |
Py_XINCREF(data); |
| 42 |
if (!count) |
| 43 |
self->show(); |
| 44 |
else if (!data) { |
| 45 |
if (PyList_Check(count)) { |
| 46 |
Py_ssize_t size = PyList_Size(count); |
| 47 |
int i = 0; |
| 48 |
char** tmp = (char **) malloc((size+1)*sizeof(char *)); |
| 49 |
for (i = 0; i < size; i++) { |
| 50 |
PyObject *o = PyList_GetItem(count,i); |
| 51 |
%#if PY_VERSION_HEX>=0x03000000 |
| 52 |
if (PyUnicode_Check(o)) |
| 53 |
%#else |
| 54 |
if (PyString_Check(o)) |
| 55 |
%#endif |
| 56 |
//tmp[i] = SWIG_Python_str_AsChar(PyList_GetItem(count,i)); |
| 57 |
tmp[i] = const_cast<char*>(PyUnicode_AsUTF8(PyList_GetItem(count,i))); |
| 58 |
//tmp[i] = PyString_AsString(PyList_GetItem(count,i)); |
| 59 |
else { |
| 60 |
PyErr_SetString(PyExc_TypeError,"list must contain strings"); |
| 61 |
free(tmp); |
| 62 |
return; |
| 63 |
} |
| 64 |
} |
| 65 |
tmp[i] = 0; |
| 66 |
self->show(static_cast<int>(size), tmp); |
| 67 |
free(tmp); |
| 68 |
} |
| 69 |
} |
| 70 |
else { |
| 71 |
if (PyList_Check(data)) { |
| 72 |
int size = PyInt_AsLong(count); |
| 73 |
int i = 0; |
| 74 |
char** tmp = (char **) malloc((size+1)*sizeof(char *)); |
| 75 |
for (i = 0; i < size; i++) { |
| 76 |
PyObject *o = PyList_GetItem(data,i); |
| 77 |
%#if PY_VERSION_HEX>=0x03000000 |
| 78 |
if (PyUnicode_Check(o)) |
| 79 |
%#else |
| 80 |
if (PyString_Check(o)) |
| 81 |
%#endif |
| 82 |
//tmp[i] = SWIG_Python_str_AsChar(PyList_GetItem(data,i)); |
| 83 |
tmp[i] = const_cast<char*>(PyUnicode_AsUTF8(PyList_GetItem(data,i))); |
| 84 |
//tmp[i] = PyString_AsString(PyList_GetItem(data,i)); |
| 85 |
else { |
| 86 |
PyErr_SetString(PyExc_TypeError,"list must contain strings"); |
| 87 |
free(tmp); |
| 88 |
return; |
| 89 |
} |
| 90 |
} |
| 91 |
tmp[i] = 0; |
| 92 |
self->show(static_cast<int>(size), tmp); |
| 93 |
free(tmp); |
| 94 |
} else { |
| 95 |
PyErr_SetString(PyExc_TypeError,"not a list"); |
| 96 |
self->show(); |
| 97 |
} |
| 98 |
|
| 99 |
} |
| 100 |
} |
| 101 |
%enddef |