kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 8235759bca283efe1e787813f18d709b8367e977
parent e38c6e5d30ace6ace03dba70ea0428aca5eb8d82
Author: Joris Vink <joris@coders.se>
Date:   Sun,  5 Jul 2020 21:47:22 +0200

Python: Add kore.app().

This method allows you to set a Python object and obtain it
by calling the method again without any arguments.

eg:

foo = SomeClass()

kore.app(foo)

foo = kore.app()

Diffstat:
include/kore/python_methods.h | 2++
src/python.c | 24++++++++++++++++++++++++
2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/include/kore/python_methods.h b/include/kore/python_methods.h @@ -34,6 +34,7 @@ struct python_coro { TAILQ_HEAD(coro_list, python_coro); +static PyObject *python_kore_app(PyObject *, PyObject *); static PyObject *python_kore_log(PyObject *, PyObject *); static PyObject *python_kore_time(PyObject *, PyObject *); static PyObject *python_kore_lock(PyObject *, PyObject *); @@ -80,6 +81,7 @@ static PyObject *python_websocket_broadcast(PyObject *, PyObject *); #define GETSET(n, g, s) { n, (getter)g, (setter)s, NULL, NULL } static struct PyMethodDef pykore_methods[] = { + METHOD("app", python_kore_app, METH_VARARGS), METHOD("log", python_kore_log, METH_VARARGS), METHOD("time", python_kore_time, METH_NOARGS), METHOD("lock", python_kore_lock, METH_NOARGS), diff --git a/src/python.c b/src/python.c @@ -266,6 +266,7 @@ static struct coro_list coro_suspended; extern const char *__progname; static PyObject *pickle = NULL; +static PyObject *kore_app = NULL; static PyObject *pickle_dumps = NULL; static PyObject *pickle_loads = NULL; static PyObject *python_tracer = NULL; @@ -1642,6 +1643,29 @@ python_kore_pgsql_register(PyObject *self, PyObject *args) #endif static PyObject * +python_kore_app(PyObject *self, PyObject *args) +{ + PyObject *obj; + + if (!PyArg_ParseTuple(args, "O", &obj)) { + PyErr_Clear(); + + if (kore_app == NULL) + Py_RETURN_NONE; + + Py_INCREF(kore_app); + return (kore_app); + } + + Py_XDECREF(kore_app); + + kore_app = obj; + Py_INCREF(kore_app); + + Py_RETURN_TRUE; +} + +static PyObject * python_kore_log(PyObject *self, PyObject *args) { int prio;