Added speedup project code.

This commit is contained in:
2025-09-12 18:07:37 +02:00
parent 348a288fa3
commit 96391138a4
6 changed files with 232 additions and 0 deletions

View File

@ -0,0 +1,56 @@
#include <Python.h>
PyObject* my_stat_counter(PyObject* self, PyObject* args) {
size_t to_add;
if (!PyArg_ParseTuple(args, "k", &to_add)) {
return (PyObject*)NULL;
}
// PyObject* state = Py_None;
auto mod_shit = (size_t*)PyModule_GetState(self);
if (*mod_shit == 0) {
*mod_shit = 1;
}
*mod_shit += to_add;
return PyLong_FromSize_t(*mod_shit);
}
static PyMethodDef MyStatMethods[] = {
{
"my_stat_counter",
my_stat_counter,
METH_VARARGS,
"Python interface for speedup",
},
{NULL, NULL, 0, NULL},
};
#ifdef Py_mod_exec
static struct PyModuleDef_Slot mod_slots[] = {
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
{0, NULL},
};
#endif
static struct PyModuleDef mod_def = {
PyModuleDef_HEAD_INIT, /* m_base */
"speedup", /* m_name */
"Python interface for speedup module", /* m_doc */
sizeof(size_t), /* m_size */
MyStatMethods, /* m_methods */
#ifdef Py_mod_exec
mod_slots, /* m_slots */
#else
NULL,
#endif
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
};
PyMODINIT_FUNC PyInit_libspeedup(void) {
return PyModuleDef_Init(&mod_def);
}