Skip to content

Commit

Permalink
typemap: switch list -> tuple
Browse files Browse the repository at this point in the history
list being mutable can't be used as dictionary keys
  • Loading branch information
singh-lokendra committed Aug 25, 2019
1 parent 548ef13 commit 8db04b0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions python/apertium_core.i
Expand Up @@ -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%{
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 8db04b0

Please sign in to comment.