Skip to content

Commit

Permalink
wrapper: switch to %inline
Browse files Browse the repository at this point in the history
prevents multiple function prototyping
  • Loading branch information
singh-lokendra committed Jul 31, 2019
1 parent fedc754 commit a71bff2
Showing 1 changed file with 39 additions and 55 deletions.
94 changes: 39 additions & 55 deletions python/apertium_core.i
@@ -1,16 +1,51 @@
%module apertium_core

%{
%include <apertium/interchunk.h>
%include <apertium/pretransfer.h>
%include <apertium/postchunk.h>
%include <apertium/tagger.h>
%include <apertium/transfer.h>

// 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 <apertium/interchunk.h>
#include <apertium/pretransfer.h>
#include <apertium/postchunk.h>
#include <apertium/tagger.h>
#include <apertium/transfer.h>

class apertium: public Transfer, public Interchunk, public Postchunk
{
public:
public:
/**
* Imitates functionality of apertium-core binaries using file path
*/
Expand All @@ -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
Expand Down Expand Up @@ -83,54 +118,3 @@ apertium::postchunk_text(char arg, char *transferfile, char *datafile, char *inp
}

%}

%include <apertium/interchunk.h>
%include <apertium/pretransfer.h>
%include <apertium/postchunk.h>
%include <apertium/tagger.h>
%include <apertium/transfer.h>

// 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);
};

0 comments on commit a71bff2

Please sign in to comment.