From 9deaacce5f4e2a3230b5175fb4f4d7b03ec8b7e8 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Sun, 21 Jul 2024 16:32:31 +0200 Subject: [PATCH] WIP plugins/python: handle cframe removal from CPython thread state Use current_frame instead --- plugins/python/python_plugin.c | 16 ++++++++++++++++ plugins/python/uwsgi_python.h | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 066bde668..38beeaa70 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -1662,7 +1662,11 @@ void uwsgi_python_suspend(struct wsgi_request *wsgi_req) { #ifdef UWSGI_PY312 up.current_c_recursion_remaining[wsgi_req->async_id] = tstate->c_recursion_remaining; up.current_py_recursion_remaining[wsgi_req->async_id] = tstate->py_recursion_remaining; +#ifdef UWSGI_PY313 + up.current_frame[wsgi_req->async_id] = tstate->current_frame; +#else up.current_frame[wsgi_req->async_id] = tstate->cframe; +#endif #elif defined UWSGI_PY311 up.current_recursion_remaining[wsgi_req->async_id] = tstate->recursion_remaining; up.current_frame[wsgi_req->async_id] = tstate->cframe; @@ -1675,7 +1679,11 @@ void uwsgi_python_suspend(struct wsgi_request *wsgi_req) { #ifdef UWSGI_PY312 up.current_main_c_recursion_remaining = tstate->c_recursion_remaining; up.current_main_py_recursion_remaining = tstate->py_recursion_remaining; +#ifdef UWSGI_PY313 + up.current_main_frame = tstate->current_frame; +#else up.current_main_frame = tstate->cframe; +#endif #elif defined UWSGI_PY311 up.current_main_recursion_remaining = tstate->recursion_remaining; up.current_main_frame = tstate->cframe; @@ -1915,7 +1923,11 @@ void uwsgi_python_resume(struct wsgi_request *wsgi_req) { #ifdef UWSGI_PY312 tstate->c_recursion_remaining = up.current_c_recursion_remaining[wsgi_req->async_id]; tstate->py_recursion_remaining = up.current_py_recursion_remaining[wsgi_req->async_id]; +#ifdef UWSGI_PY313 + tstate->currentframe = up.current_frame[wsgi_req->async_id]; +#else tstate->cframe = up.current_frame[wsgi_req->async_id]; +#endif #elif defined UWSGI_PY311 tstate->recursion_remaining = up.current_recursion_remaining[wsgi_req->async_id]; tstate->cframe = up.current_frame[wsgi_req->async_id]; @@ -1928,7 +1940,11 @@ void uwsgi_python_resume(struct wsgi_request *wsgi_req) { #ifdef UWSGI_PY312 tstate->c_recursion_remaining = up.current_main_c_recursion_remaining; tstate->py_recursion_remaining = up.current_main_py_recursion_remaining; +#ifdef UWSGI_PY313 + tstate->current_frame = up.current_main_frame; +#else tstate->cframe = up.current_main_frame; +#endif #elif defined UWSGI_PY311 tstate->recursion_remaining = up.current_main_recursion_remaining; tstate->cframe = up.current_main_frame; diff --git a/plugins/python/uwsgi_python.h b/plugins/python/uwsgi_python.h index 538f3315b..530b10b77 100644 --- a/plugins/python/uwsgi_python.h +++ b/plugins/python/uwsgi_python.h @@ -25,6 +25,10 @@ # define UWSGI_PY312 #endif +#if (PY_VERSION_HEX >= 0x030d0000) +# define UWSGI_PY313 +#endif + #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7 #define HAS_NOT_PyMemoryView_FromBuffer #endif @@ -185,11 +189,19 @@ struct uwsgi_python { #ifdef UWSGI_PY312 int *current_c_recursion_remaining; int *current_py_recursion_remaining; +#ifdef UWSGI_PY313 + struct _PyInterpreterFrame **current_frame; +#else _PyCFrame **current_frame; +#endif int current_main_c_recursion_remaining; int current_main_py_recursion_remaining; +#ifdef UWSGI_PY313 + struct _PyInterpreterFrame **current_frame; +#else _PyCFrame *current_main_frame; +#endif #elif defined UWSGI_PY311 int *current_recursion_remaining; _PyCFrame **current_frame;