From 5f9adbf56b8dd9d2bc3c83b52eeb4073f7464455 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 7 Oct 2024 11:00:04 +0200 Subject: Initial commit --- sum_module.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 sum_module.c (limited to 'sum_module.c') 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 @@ +#include "sum.h" + +#define PY_SSIZE_T_CLEAN +#include + +static PyObject *csum(PyObject *self, PyObject *args) { + int a, b, result; + + if (!PyArg_ParseTuple(args, "ii", &a, &b)) + return NULL; + + result = sum(a, b); + return PyLong_FromLong(result); +} + +static PyMethodDef SumMethods[] = { + { "sum_from_c", csum, METH_VARARGS, "Sum two integers." }, + { NULL, NULL, 0, NULL } +}; + +static struct PyModuleDef summodule = { + PyModuleDef_HEAD_INIT, + "sum", + NULL, + -1, + SumMethods +}; + +PyMODINIT_FUNC PyInit_sum_module(void) { + return PyModule_Create(&summodule); +} -- cgit v1.3