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 30c8652534dafcdef217259c64e8c642b3cd2704
parent f6c54042c50c48e939a698ef2146f11d29c2179a
Author: Joris Vink <joris@coders.se>
Date:   Thu, 14 Jul 2022 11:48:32 +0200

More Python 3.10.x changes.

Handle PYGEN_RETURN in case our prerequest handlers return actual
values instead of None.

Mimic PySendResult for older versions for now.

Diffstat:
src/python.c | 22+++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/python.c b/src/python.c @@ -55,6 +55,14 @@ #include <frameobject.h> +#if PY_VERSION_HEX < 0x030A0000 +typedef enum { + PYGEN_RETURN = 0, + PYGEN_ERROR = -1, + PYGEN_NEXT = 1, +} PySendResult; +#endif + struct reqcall { PyObject *f; TAILQ_ENTRY(reqcall) list; @@ -1075,6 +1083,7 @@ python_coro_create(PyObject *obj, struct http_request *req) static int python_coro_run(struct python_coro *coro) { + PySendResult res; PyObject *item; PyObject *type, *traceback; @@ -1087,7 +1096,8 @@ python_coro_run(struct python_coro *coro) python_coro_trace("running", coro); PyErr_Clear(); -#if PY_VERSION_HEX < 0x030a00a1 +#if PY_VERSION_HEX < 0x030A0000 + res = PYGEN_RETURN; item = _PyGen_Send((PyGenObject *)coro->obj, NULL); #else /* @@ -1096,10 +1106,10 @@ python_coro_run(struct python_coro *coro) * ends up being Py_None. This means the returned item is * NULL but no StopIteration exception has occurred. */ - (void)PyIter_Send(coro->obj, NULL, &item); + res = PyIter_Send(coro->obj, NULL, &item); #endif - if (item == NULL) { + if (item == NULL || res == PYGEN_ERROR) { if (coro->gatherop == NULL && PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) { PyErr_Fetch(&type, &coro->result, &traceback); @@ -1118,6 +1128,12 @@ python_coro_run(struct python_coro *coro) return (KORE_RESULT_OK); } + if (res == PYGEN_RETURN) { + Py_XDECREF(item); + coro_running = NULL; + return (KORE_RESULT_OK); + } + if (item == Py_None) { Py_DECREF(item); break;