File python313.patch of Package uwsgi
From 699dc20f8204ee18812951600b0221156d217530 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com> Date: Sun, 21 Jul 2024 16:32:31 +0200 Subject: [PATCH] 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(+) Index: uwsgi-2.0.31/plugins/python/python_plugin.c =================================================================== --- uwsgi-2.0.31.orig/plugins/python/python_plugin.c 2025-10-11 21:15:54.000000000 +0200 +++ uwsgi-2.0.31/plugins/python/python_plugin.c 2025-10-20 12:00:33.273803775 +0200 @@ -1620,7 +1620,11 @@ #elif defined 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; @@ -1640,7 +1644,11 @@ #elif defined 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; @@ -1887,7 +1895,11 @@ #elif defined 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->current_frame = 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]; @@ -1907,7 +1919,11 @@ #elif defined 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; Index: uwsgi-2.0.31/plugins/python/uwsgi_python.h =================================================================== --- uwsgi-2.0.31.orig/plugins/python/uwsgi_python.h 2025-10-11 21:15:54.000000000 +0200 +++ uwsgi-2.0.31/plugins/python/uwsgi_python.h 2025-10-20 12:00:33.274623229 +0200 @@ -33,6 +33,10 @@ # define UWSGI_PY314 #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 @@ -193,11 +197,19 @@ #elif defined 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_main_frame; +#else _PyCFrame *current_main_frame; +#endif #elif defined UWSGI_PY311 int *current_recursion_remaining; _PyCFrame **current_frame;