commit e1fcc7e4a88e9ba90465e8e2faa277dba80fecbf Author: vaydheesh Date: Sun Aug 25 18:41:31 2019 +0530 typemap: switch list -> tuple list being mutable can't be used as dictionary keys diff --git a/python/lex_tools.i b/python/lex_tools.i index 88897be..d390824 100644 --- a/python/lex_tools.i +++ b/python/lex_tools.i @@ -3,31 +3,31 @@ %include %include -%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%{ @@ -49,7 +49,7 @@ public: fclose(dictionary); } - void lrx_proc(char argc, char **argv, char *input_path, char *output_path) + void lrx_proc(int argc, char **argv, char *input_path, char *output_path) { bool useMaxEnt = false; FILE* input = fopen(input_path, "r"); @@ -84,7 +84,6 @@ public: break; } } - init(); if(useMaxEnt) { processME(input, output);