Rename recursion limits to add compatibility with Python 3.12

This commit is contained in:
Tomáš Hrnčiar 2023-03-14 14:20:27 +01:00
parent cf0073296e
commit 15e20161cf
2 changed files with 79 additions and 0 deletions

View File

@ -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?= <thrnciar@redhat.com>
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 <internal/pycore_frame.h>
#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

View File

@ -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 \