Skip to content

Commit 244faa6

Browse files
tacaswellmdboom
authored andcommitted
Fix #323: Support Python 3.12
1 parent 7389976 commit 244faa6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/greenlet/greenlet_cpython_compat.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ We have to save and restore this as well.
4848
# define GREENLET_USE_CFRAME 0
4949
#endif
5050

51+
#if PY_VERSION_HEX >= 0x30C0000
52+
# define GREENLET_PY312 1
53+
#else
54+
# define GREENLET_PY312 0
55+
#endif
56+
5157
#if PY_VERSION_HEX >= 0x30B00A4
5258
/*
5359
Greenlet won't compile on anything older than Python 3.11 alpha 4 (see

src/greenlet/greenlet_greenlet.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,11 @@ void PythonState::operator<<(const PyThreadState *const tstate) G_NOEXCEPT
826826
this->use_tracing = tstate->cframe->use_tracing;
827827
#endif
828828
#if GREENLET_PY311
829+
#if GREENLET_PY312
830+
this->recursion_depth = tstate->py_recursion_limit - tstate->py_recursion_remaining;
831+
#else
829832
this->recursion_depth = tstate->recursion_limit - tstate->recursion_remaining;
833+
#endif
830834
this->current_frame = tstate->cframe->current_frame;
831835
this->datastack_chunk = tstate->datastack_chunk;
832836
this->datastack_top = tstate->datastack_top;
@@ -862,7 +866,11 @@ void PythonState::operator>>(PyThreadState *const tstate) G_NOEXCEPT
862866
tstate->cframe->use_tracing = this->use_tracing;
863867
#endif
864868
#if GREENLET_PY311
869+
#if GREENLET_PY312
870+
tstate->py_recursion_remaining = tstate->py_recursion_limit - this->recursion_depth;
871+
#else
865872
tstate->recursion_remaining = tstate->recursion_limit - this->recursion_depth;
873+
#endif
866874
tstate->cframe->current_frame = this->current_frame;
867875
tstate->datastack_chunk = this->datastack_chunk;
868876
tstate->datastack_top = this->datastack_top;
@@ -890,7 +898,9 @@ void PythonState::will_switch_from(PyThreadState *const origin_tstate) G_NOEXCEP
890898
void PythonState::set_initial_state(const PyThreadState* const tstate) G_NOEXCEPT
891899
{
892900
this->_top_frame = nullptr;
893-
#if GREENLET_PY311
901+
#if GREENLET_PY312
902+
this->recursion_depth = tstate->py_recursion_limit - tstate->py_recursion_remaining;
903+
#elif GREENLET_PY311
894904
this->recursion_depth = tstate->recursion_limit - tstate->recursion_remaining;
895905
#else
896906
this->recursion_depth = tstate->recursion_depth;

0 commit comments

Comments
 (0)