diff --git a/Rename-recursion-limits-to-add-compatibility-with-Py.patch b/Rename-recursion-limits-to-add-compatibility-with-Py.patch new file mode 100644 index 0000000..ab4e736 --- /dev/null +++ b/Rename-recursion-limits-to-add-compatibility-with-Py.patch @@ -0,0 +1,75 @@ +From 75925bfb4988cb37332d58fc895e29da1c122cd1 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hrn=C4=8Diar?= +Date: Mon, 13 Mar 2023 16:26:07 +0100 +Subject: [PATCH] Rename recursion limits to add compatibility with Python 3.12 + +--- + src/greenlet/greenlet.c | 19 ++++++++++++++++--- + src/greenlet/greenlet.h | 7 ++++++- + 2 files changed, 22 insertions(+), 4 deletions(-) + +diff --git a/src/greenlet/greenlet.c b/src/greenlet/greenlet.c +index 2f3ad6e..6165064 100644 +--- a/src/greenlet/greenlet.c ++++ b/src/greenlet/greenlet.c +@@ -527,7 +527,10 @@ g_switchstack(void) + { /* save state */ + PyGreenlet* current = ts_current; + PyThreadState* tstate = PyThreadState_GET(); +-#if GREENLET_PY311 ++#if GREENLET_PY312 ++ current->recursion_depth = (tstate->py_recursion_limit ++ - tstate->py_recursion_remaining); ++#elif GREENLET_PY311 + current->recursion_depth = (tstate->recursion_limit + - tstate->recursion_remaining); + #else +@@ -620,7 +623,14 @@ g_switchstack(void) + */ + tstate->cframe->use_tracing = ts__g_switchstack_use_tracing; + #endif +-#if GREENLET_PY311 ++#if GREENLET_PY312 ++ tstate->py_recursion_remaining = (tstate->py_recursion_limit ++ - target->recursion_depth); ++ tstate->cframe->current_frame = target->current_frame; ++ tstate->datastack_chunk = target->datastack_chunk; ++ tstate->datastack_top = target->datastack_top; ++ tstate->datastack_limit = target->datastack_limit; ++#elif GREENLET_PY311 + tstate->recursion_remaining = (tstate->recursion_limit + - target->recursion_depth); + tstate->cframe->current_frame = target->current_frame; +@@ -899,7 +909,10 @@ static int GREENLET_NOINLINE(g_initialstub)(void* mark) + } + self->top_frame = NULL; + green_clear_exc(self); +-#if GREENLET_PY311 ++#if GREENLET_PY312 ++ self->recursion_depth = (PyThreadState_GET()->py_recursion_limit ++ - PyThreadState_GET()->py_recursion_remaining); ++#elif GREENLET_PY311 + self->recursion_depth = (PyThreadState_GET()->recursion_limit + - PyThreadState_GET()->recursion_remaining); + #else +diff --git a/src/greenlet/greenlet.h b/src/greenlet/greenlet.h +index c788b2f..9e1caab 100644 +--- a/src/greenlet/greenlet.h ++++ b/src/greenlet/greenlet.h +@@ -20,7 +20,12 @@ extern "C" { + # include + #else + # define GREENLET_PY311 0 +-# define _PyCFrame CFrame ++#endif ++ ++#if PY_VERSION_HEX >= 0x30C00A6 ++# define GREENLET_PY312 1 ++#else ++# define GREENLET_PY312 0 + #endif + + typedef struct _greenlet { +-- +2.38.1 + diff --git a/python-greenlet.spec b/python-greenlet.spec index a6430ff..25cf287 100644 --- a/python-greenlet.spec +++ b/python-greenlet.spec @@ -8,6 +8,10 @@ License: MIT URL: https://github.com/python-greenlet/greenlet Source0: %{url}/archive/%{version}/%{modname}-%{version}.tar.gz +# Patch needed for compatibility with Python 3.12 +# Inspired by: https://github.com/python-greenlet/greenlet/issues/323#issue-1428384781 +Patch: Rename-recursion-limits-to-add-compatibility-with-Py.patch + BuildRequires: gcc-c++ %global _description \