-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstddef.i
44 lines (40 loc) · 1.16 KB
/
stddef.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// This tells SWIG to treat char ** as a special case
%typemap(in) char ** {
/* Check if is a list */
if (PyList_Check($input)) {
long long sz = PyList_Size($input);
long long i = 0;
$1 = (char **) malloc((sz+1)*sizeof(char *));
// $1 = new char *[sz+1];
for (i = 0; i < sz; i++) {
PyObject *o = PyList_GetItem($input, i);
if (PyString_Check(o)) {
$1[i] = PyString_AsString(o);
} else
if (PyUnicode_Check(o)) {
$1[i] = PyBytes_AS_STRING(PyUnicode_AsEncodedString(o, "utf-8", "Error ~"));
} else {
PyErr_SetString(PyExc_TypeError, "list must contain strings");
SWIG_fail;
}
}
$1[i] = 0;
} else {
PyErr_SetString(PyExc_TypeError, "not a list");
SWIG_fail;
}
}
// This cleans up the char ** array we malloc'd before the function call
%typemap(freearg) char ** {
free($1);
// delete [] $1;
}
%include "std_vector.i"
%include "std_string.i"
namespace std {
%template(vectori) vector<int>;
%template(vectorl) vector<long long>;
%template(vectord) vector<double>;
%template(vectori2d) vector<vector<int>>;
%template(vectori3d) vector<vector<vector<int>>>;
};