commit a71bff2e807e063f8c8b107fe84c1b5ee2c968e1 Author: vaydheesh Date: Thu Aug 1 00:37:02 2019 +0530 wrapper: switch to %inline prevents multiple function prototyping diff --git a/python/apertium_core.i b/python/apertium_core.i index 672eb68..83c840a 100644 --- a/python/apertium_core.i +++ b/python/apertium_core.i @@ -1,16 +1,51 @@ %module apertium_core -%{ +%include +%include +%include +%include +%include + +// 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); + int i = 0; + $1 = (char **) malloc((size+1)*sizeof(char *)); + for (i = 0; i < size; i++) { + PyObject *py_obj = PyList_GetItem($input, i); + if (PyUnicode_Check(py_obj)) { + $1[i] = strdup(PyUnicode_AsUTF8(py_obj)); + } + else { + PyErr_SetString(PyExc_TypeError, "list must contain strings"); + free($1); + return NULL; + } + } + $1[i] = 0; + } else { + PyErr_SetString(PyExc_TypeError, "not a list"); + return NULL; + } +} + +%typemap(freearg) char ** { + free((char *) $1); +} + +%inline%{ #define SWIG_FILE_WITH_INIT #include #include #include #include #include - class apertium: public Transfer, public Interchunk, public Postchunk { -public: + public: /** * Imitates functionality of apertium-core binaries using file path */ @@ -22,7 +57,7 @@ public: class tagger: public Apertium::apertium_tagger { -public: + public: /** * Imitates functionality of apertium-tagger * tagger::tagger() passes int and char** to apertium_tagger::apertium_tagger() int&, char**& respectively @@ -83,54 +118,3 @@ apertium::postchunk_text(char arg, char *transferfile, char *datafile, char *inp } %} - -%include -%include -%include -%include -%include - -// 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); - int i = 0; - $1 = (char **) malloc((size+1)*sizeof(char *)); - for (i = 0; i < size; i++) { - PyObject *py_obj = PyList_GetItem($input, i); - if (PyUnicode_Check(py_obj)) { - $1[i] = strdup(PyUnicode_AsUTF8(py_obj)); - } - else { - PyErr_SetString(PyExc_TypeError, "list must contain strings"); - free($1); - return NULL; - } - } - $1[i] = 0; - } else { - PyErr_SetString(PyExc_TypeError, "not a list"); - return NULL; - } -} - -%typemap(freearg) char ** { - free((char *) $1); -} - -class apertium: public Transfer, public Interchunk, public Postchunk -{ -public: - void interchunk_text(char arg, char *transferfile, char *datafile, char *input_path, char *output_path); - void pretransfer(char arg, char *input_path, char *output_path); - void postchunk_text(char arg, char *transferfile, char *datafile, char *input_path, char *output_path); - void transfer_text(char arg, char *transferfile, char *datafile, char *input_path, char *output_path); -}; - -class tagger: public Apertium::apertium_tagger -{ -public: - tagger(int argc, char **argv): apertium_tagger(argc, argv); -};