commit 8db04b0ee22ae1123b77675f5806c470d224da48 Author: vaydheesh Date: Sun Aug 25 18:30:44 2019 +0530 typemap: switch list -> tuple list being mutable can't be used as dictionary keys diff --git a/python/apertium_core.i b/python/apertium_core.i index 39eed93..3f87b36 100644 --- a/python/apertium_core.i +++ b/python/apertium_core.i @@ -9,31 +9,31 @@ // Wrapper on char ** for char **argv // Modified for python 3 from http://www.swig.org/Doc1.3/Python.html#Python_nn59 -%typemap(in) char ** { - if (PyList_Check($input)) { - int size = PyList_Size($input); +%typemap(in) (int argc, char **argv) { + if (PyTuple_Check($input)) { int i = 0; - $1 = (char **) malloc((size+1)*sizeof(char *)); - for (i = 0; i < size; i++) { - PyObject *py_obj = PyList_GetItem($input, i); + $1 = PyTuple_Size($input); + $2 = (char **) malloc(($1 + 1)*sizeof(char *)); + for (i = 0; i < $1; i++) { + PyObject *py_obj = PyTuple_GetItem($input, i); if (PyUnicode_Check(py_obj)) { - $1[i] = strdup(PyUnicode_AsUTF8(py_obj)); + $2[i] = strdup(PyUnicode_AsUTF8(py_obj)); } else { - PyErr_SetString(PyExc_TypeError, "list must contain strings"); - free($1); + PyErr_SetString(PyExc_TypeError, "tuple must contain strings"); + free($2); return NULL; } } - $1[i] = 0; + $2[i] = 0; } else { - PyErr_SetString(PyExc_TypeError, "not a list"); + PyErr_SetString(PyExc_TypeError, "not a tuple"); return NULL; } } -%typemap(freearg) char ** { - free((char *) $1); +%typemap(freearg) (int argc, char **argv) { + free((char *) $2); } %inline%{ @@ -98,7 +98,7 @@ class ApertiumTransfer: public Transfer read(transferfile, datafile); } - void transfer_text(char argc, char **argv, char *input_path, char *output_path) + void transfer_text(int argc, char **argv, char *input_path, char *output_path) { FILE* input = fopen(input_path, "r"); FILE* output = fopen(output_path, "w");