aboutsummaryrefslogtreecommitdiff
path: root/sum_module.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sum_module.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/sum_module.c b/sum_module.c
new file mode 100644
index 0000000..5f55747
--- /dev/null
+++ b/sum_module.c
@@ -0,0 +1,31 @@
1#include "sum.h"
2
3#define PY_SSIZE_T_CLEAN
4#include <Python.h>
5
6static PyObject *csum(PyObject *self, PyObject *args) {
7 int a, b, result;
8
9 if (!PyArg_ParseTuple(args, "ii", &a, &b))
10 return NULL;
11
12 result = sum(a, b);
13 return PyLong_FromLong(result);
14}
15
16static PyMethodDef SumMethods[] = {
17 { "sum_from_c", csum, METH_VARARGS, "Sum two integers." },
18 { NULL, NULL, 0, NULL }
19};
20
21static struct PyModuleDef summodule = {
22 PyModuleDef_HEAD_INIT,
23 "sum",
24 NULL,
25 -1,
26 SumMethods
27};
28
29PyMODINIT_FUNC PyInit_sum_module(void) {
30 return PyModule_Create(&summodule);
31}

Generated with cgit - Back to sebastiano.tronto.net