There was an error while loading. Please reload this page.
2 parents 37cf47a + f82bd1a commit 9b49da5Copy full SHA for 9b49da5
2 files changed
src/greenlet/greenlet.cpp
@@ -702,13 +702,9 @@ g_calltrace(PyObject* tracefunc, PyObject* event, PyGreenlet* origin,
702
PyThreadState* tstate;
703
PyErr_Fetch(&exc_type, &exc_val, &exc_tb);
704
tstate = PyThreadState_GET();
705
- tstate->tracing++;
706
- TSTATE_USE_TRACING(tstate) = 0;
+ PyThreadState_EnterTracing(tstate);
707
retval = PyObject_CallFunction(tracefunc, "O(OO)", event, origin, target);
708
- tstate->tracing--;
709
- TSTATE_USE_TRACING(tstate) =
710
- (tstate->tracing <= 0 &&
711
- ((tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL)));
+ PyThreadState_LeaveTracing(tstate);
712
if (retval == NULL) {
713
/* In case of exceptions trace function is removed */
714
GET_THREAD_STATE().state().del_tracefunc();
src/greenlet/greenlet_cpython_compat.hpp
@@ -20,10 +20,8 @@ Python 3.10 beta 1 changed tstate->use_tracing to a nested cframe member.
20
See https://github.com/python/cpython/pull/25276
21
We have to save and restore this as well.
22
*/
23
-# define TSTATE_USE_TRACING(tstate) (tstate->cframe->use_tracing)
24
# define GREENLET_USE_CFRAME 1
25
#else
26
-# define TSTATE_USE_TRACING(tstate) (tstate->use_tracing)
27
# define GREENLET_USE_CFRAME 0
28
#endif
29
@@ -95,4 +93,32 @@ PyObject* PyModule_Create(PyModuleDef* m)
95
93
}
96
94
97
+// bpo-43760 added PyThreadState_EnterTracing() to Python 3.11.0a2
+#if PY_VERSION_HEX < 0x030B00A2 && !defined(PYPY_VERSION)
98
+static inline void PyThreadState_EnterTracing(PyThreadState *tstate)
99
+{
100
+ tstate->tracing++;
101
+#if PY_VERSION_HEX >= 0x030A00A1
102
+ tstate->cframe->use_tracing = 0;
103
+#else
104
+ tstate->use_tracing = 0;
105
+#endif
106
+}
107
108
+
109
+// bpo-43760 added PyThreadState_LeaveTracing() to Python 3.11.0a2
110
111
+static inline void PyThreadState_LeaveTracing(PyThreadState *tstate)
112
113
+ tstate->tracing--;
114
+ int use_tracing = (tstate->c_tracefunc != NULL
115
+ || tstate->c_profilefunc != NULL);
116
117
+ tstate->cframe->use_tracing = use_tracing;
118
119
+ tstate->use_tracing = use_tracing;
120
121
122
123
124
#endif /* GREENLET_CPYTHON_COMPAT_H */
0 commit comments