Skip to content

Commit

Permalink
WIP plugins/python: handle cframe removal from CPython thread state
Browse files Browse the repository at this point in the history
Use current_frame instead
  • Loading branch information
xrmx committed Jul 21, 2024
1 parent 3d25055 commit c1519d7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions plugins/python/python_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions plugins/python/uwsgi_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -185,14 +189,22 @@ 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;
_PyCFrame *current_main_frame;
#elif defined UWSGI_PY311
int *current_recursion_remaining;
#ifdef UWSGI_PY313
struct _PyInterpreterFrame **current_frame;
#else
_PyCFrame **current_frame;
#endif

int current_main_recursion_remaining;
_PyCFrame *current_main_frame;
Expand Down

0 comments on commit c1519d7

Please sign in to comment.