-
Notifications
You must be signed in to change notification settings - Fork 3
/
go-python.c
57 lines (42 loc) · 1.36 KB
/
go-python.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "go-python.h"
int
_gopy_PyRun_SimpleString(const char *command) {
return PyRun_SimpleString(command);
}
PyObject*
_gopy_PyObject_CallFunction(PyObject *o, int len, char* pyfmt, void *cargs) {
void ** args = (void**)cargs;
if (len > _gopy_max_varargs) {
PyErr_Format(
PyExc_RuntimeError,
"python: maximum number of varargs (%d) exceeded (%d)",
_gopy_max_varargs,
len
);
return NULL;
}
switch (len) {
case 0:
return PyObject_CallFunction(o, pyfmt);
case 1:
return PyObject_CallFunction(o, pyfmt, args[0]);
case 2:
return PyObject_CallFunction(o, pyfmt, args[0], args[1]);
case 3:
return PyObject_CallFunction(o, pyfmt, args[0], args[1], args[2]);
case 4:
return PyObject_CallFunction(o, pyfmt, args[0], args[1], args[2], args[3]);
case 5:
return PyObject_CallFunction(o, pyfmt, args[0], args[1], args[2], args[3], args[4]);
case 6:
return PyObject_CallFunction(o, pyfmt, args[0], args[1], args[2], args[3], args[4], args[5]);
case 7:
return PyObject_CallFunction(o, pyfmt, args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
case 8:
return PyObject_CallFunction(o, pyfmt, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
default:
PyErr_Format(PyExc_RuntimeError, "python: invalid number of arguments (%d)", len);
return NULL;
}
return NULL;
}