From 145a587329425b7016e7c752d19a22b6e422bc0a Mon Sep 17 00:00:00 2001 From: Conor McCarthy Date: Tue, 24 Oct 2023 10:50:18 +0100 Subject: [PATCH] Addition of missing file --- src/pykx/.gitignore | 1 + src/pykx/_pykx_helpers.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/pykx/_pykx_helpers.c diff --git a/src/pykx/.gitignore b/src/pykx/.gitignore index 078a728..9d85b4c 100644 --- a/src/pykx/.gitignore +++ b/src/pykx/.gitignore @@ -1,5 +1,6 @@ # Auto-generated files *.c +!_pykx_helpers.c !_numpy.c !python.c !pykx.c diff --git a/src/pykx/_pykx_helpers.c b/src/pykx/_pykx_helpers.c new file mode 100644 index 0000000..5da9bf1 --- /dev/null +++ b/src/pykx/_pykx_helpers.c @@ -0,0 +1,35 @@ +#define PY_SSIZE_T_CLEAN +#include +#include +#include +#include + + +static PyObject* clear_all_errors(PyObject* self, PyObject* args) { + PyErr_Clear(); + Py_RETURN_NONE; +} + + +static PyMethodDef _HelperMethods[] = { + {"clean_errors", clear_all_errors, METH_NOARGS, "Clean the python error state."}, + {NULL, NULL, 0, NULL} // Sentinel +}; + + +static struct PyModuleDef _helpermodule = { + PyModuleDef_HEAD_INIT, + "_pykx_helpers",// Module name. + NULL, // Module documentation; may be NULL. + -1, // Size of per-interpreter state of the module, or -1 if the module keeps state in global variables. + _HelperMethods, // Module methods. + NULL, // Module slots. + NULL, // A traversal function to call during GC traversal of the module object. + NULL, // A clear function to call during GC clearing of the module object. + NULL // A function to call during deallocation of the module object. +}; + + +PyMODINIT_FUNC PyInit__pykx_helpers(void) { + return PyModule_Create(&_helpermodule); +}