@@ -143,7 +143,12 @@ namespace greenlet
143
143
_PyCFrame* cframe;
144
144
int use_tracing;
145
145
#endif
146
+ #if GREENLET_PY312
147
+ int py_recursion_depth;
148
+ int c_recursion_depth;
149
+ #else
146
150
int recursion_depth;
151
+ #endif
147
152
int trash_delete_nesting;
148
153
#if GREENLET_PY311
149
154
_PyInterpreterFrame* current_frame;
@@ -748,7 +753,12 @@ PythonState::PythonState()
748
753
,cframe(nullptr )
749
754
,use_tracing(0 )
750
755
#endif
756
+ #if GREENLET_PY312
757
+ ,py_recursion_depth(0 )
758
+ ,c_recursion_depth(0 )
759
+ #else
751
760
,recursion_depth(0 )
761
+ #endif
752
762
,trash_delete_nesting(0 )
753
763
#if GREENLET_PY311
754
764
,current_frame(nullptr )
@@ -828,24 +838,34 @@ void PythonState::operator<<(const PyThreadState *const tstate) G_NOEXCEPT
828
838
the switch, use `will_switch_from`.
829
839
*/
830
840
this ->cframe = tstate->cframe ;
841
+ #if !GREENLET_PY312
831
842
this ->use_tracing = tstate->cframe ->use_tracing ;
843
+ #endif
832
844
#endif
833
845
#if GREENLET_PY311
846
+ #if GREENLET_PY312
847
+ this ->py_recursion_depth = tstate->py_recursion_limit - tstate->py_recursion_remaining ;
848
+ this ->c_recursion_depth = C_RECURSION_LIMIT - tstate->c_recursion_remaining ;
849
+ #else
834
850
this ->recursion_depth = tstate->recursion_limit - tstate->recursion_remaining ;
851
+ #endif
835
852
this ->current_frame = tstate->cframe ->current_frame ;
836
853
this ->datastack_chunk = tstate->datastack_chunk ;
837
854
this ->datastack_top = tstate->datastack_top ;
838
855
this ->datastack_limit = tstate->datastack_limit ;
839
856
PyFrameObject *frame = PyThreadState_GetFrame ((PyThreadState *)tstate);
840
857
Py_XDECREF (frame); // PyThreadState_GetFrame gives us a new reference.
841
858
this ->_top_frame .steal (frame);
859
+ #if GREENLET_PY312
860
+ this ->trash_delete_nesting = tstate->trash .delete_nesting ;
861
+ #else
862
+ this ->trash_delete_nesting = tstate->trash_delete_nesting ;
863
+ #endif
842
864
#else
843
865
this ->recursion_depth = tstate->recursion_depth ;
844
866
this ->_top_frame .steal (tstate->frame );
845
- #endif
846
-
847
- // All versions of Python.
848
867
this ->trash_delete_nesting = tstate->trash_delete_nesting ;
868
+ #endif
849
869
}
850
870
851
871
void PythonState::operator >>(PyThreadState *const tstate) G_NOEXCEPT
@@ -864,26 +884,37 @@ void PythonState::operator>>(PyThreadState *const tstate) G_NOEXCEPT
864
884
root_cframe here. See note above about why we can't
865
885
just copy this from ``origin->cframe->use_tracing``.
866
886
*/
887
+ #if !GREENLET_PY312
867
888
tstate->cframe ->use_tracing = this ->use_tracing ;
889
+ #endif
868
890
#endif
869
891
#if GREENLET_PY311
892
+ #if GREENLET_PY312
893
+ tstate->py_recursion_remaining = tstate->py_recursion_limit - this ->py_recursion_depth ;
894
+ tstate->c_recursion_remaining = C_RECURSION_LIMIT - this ->c_recursion_depth ;
895
+ #else
870
896
tstate->recursion_remaining = tstate->recursion_limit - this ->recursion_depth ;
897
+ #endif
871
898
tstate->cframe ->current_frame = this ->current_frame ;
872
899
tstate->datastack_chunk = this ->datastack_chunk ;
873
900
tstate->datastack_top = this ->datastack_top ;
874
901
tstate->datastack_limit = this ->datastack_limit ;
875
902
this ->_top_frame .relinquish_ownership ();
903
+ #if GREENLET_PY312
904
+ tstate->trash .delete_nesting = this ->trash_delete_nesting ;
905
+ #else
906
+ tstate->trash_delete_nesting = this ->trash_delete_nesting ;
907
+ #endif
876
908
#else
877
909
tstate->frame = this ->_top_frame .relinquish_ownership ();
878
910
tstate->recursion_depth = this ->recursion_depth ;
879
- #endif
880
- // All versions of Python.
881
911
tstate->trash_delete_nesting = this ->trash_delete_nesting ;
912
+ #endif
882
913
}
883
914
884
915
void PythonState::will_switch_from (PyThreadState *const origin_tstate) G_NOEXCEPT
885
916
{
886
- #if GREENLET_USE_CFRAME
917
+ #if GREENLET_USE_CFRAME && !GREENLET_PY312
887
918
// The weird thing is, we don't actually save this for an
888
919
// effect on the current greenlet, it's saved for an
889
920
// effect on the target greenlet. That is, we want
@@ -895,7 +926,10 @@ void PythonState::will_switch_from(PyThreadState *const origin_tstate) G_NOEXCEP
895
926
void PythonState::set_initial_state (const PyThreadState* const tstate) G_NOEXCEPT
896
927
{
897
928
this ->_top_frame = nullptr ;
898
- #if GREENLET_PY311
929
+ #if GREENLET_PY312
930
+ this ->py_recursion_depth = tstate->py_recursion_limit - tstate->py_recursion_remaining ;
931
+ this ->c_recursion_depth = tstate->py_recursion_limit - tstate->py_recursion_remaining ;
932
+ #elif GREENLET_PY311
899
933
this ->recursion_depth = tstate->recursion_limit - tstate->recursion_remaining ;
900
934
#else
901
935
this ->recursion_depth = tstate->recursion_depth ;
0 commit comments