Commit fa5d2f5b authored by Stefan Behnel's avatar Stefan Behnel

Adapt tracing code to Py3.10 beta 1.

parent 019aebdf
...@@ -55,6 +55,25 @@ ...@@ -55,6 +55,25 @@
#define __Pyx_TraceFrameInit(codeobj) \ #define __Pyx_TraceFrameInit(codeobj) \
if (codeobj) $frame_code_cname = (PyCodeObject*) codeobj; if (codeobj) $frame_code_cname = (PyCodeObject*) codeobj;
#if PY_VERSION_HEX >= 0x030a00b1
#define __Pyx_IsTracing(tstate, check_tracing, check_funcs) \
(unlikely(tstate->cframe->use_tracing) && \
(!(check_tracing) || !tstate->tracing) && \
(!(check_funcs) || tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc)))
#define __Pyx_SetTracing(tstate, enable) \
(tstate)->cframe->use_tracing = (enable)
#else
#define __Pyx_IsTracing(tstate, check_tracing, check_funcs) \
(unlikely(tstate->use_tracing) && \
(!(check_tracing) || !tstate->tracing) && \
(!(check_funcs) || tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc)))
#define __Pyx_SetTracing(tstate, enable) \
(tstate)->use_tracing = (enable)
#endif
#ifdef WITH_THREAD #ifdef WITH_THREAD
#define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error) \ #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error) \
if (nogil) { \ if (nogil) { \
...@@ -62,8 +81,7 @@ ...@@ -62,8 +81,7 @@
PyThreadState *tstate; \ PyThreadState *tstate; \
PyGILState_STATE state = PyGILState_Ensure(); \ PyGILState_STATE state = PyGILState_Ensure(); \
tstate = __Pyx_PyThreadState_Current; \ tstate = __Pyx_PyThreadState_Current; \
if (unlikely(tstate->use_tracing) && !tstate->tracing && \ if (__Pyx_IsTracing(tstate, 1, 1)) { \
(tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \ __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \
} \ } \
PyGILState_Release(state); \ PyGILState_Release(state); \
...@@ -71,8 +89,7 @@ ...@@ -71,8 +89,7 @@
} \ } \
} else { \ } else { \
PyThreadState* tstate = PyThreadState_GET(); \ PyThreadState* tstate = PyThreadState_GET(); \
if (unlikely(tstate->use_tracing) && !tstate->tracing && \ if (__Pyx_IsTracing(tstate, 1, 1)) { \
(tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \ __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \
if (unlikely(__Pyx_use_tracing < 0)) goto_error; \ if (unlikely(__Pyx_use_tracing < 0)) goto_error; \
} \ } \
...@@ -80,8 +97,7 @@ ...@@ -80,8 +97,7 @@
#else #else
#define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error) \ #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error) \
{ PyThreadState* tstate = PyThreadState_GET(); \ { PyThreadState* tstate = PyThreadState_GET(); \
if (unlikely(tstate->use_tracing) && !tstate->tracing && \ if (__Pyx_IsTracing(tstate, 1, 1)) { \
(tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \ __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \
if (unlikely(__Pyx_use_tracing < 0)) goto_error; \ if (unlikely(__Pyx_use_tracing < 0)) goto_error; \
} \ } \
...@@ -91,10 +107,9 @@ ...@@ -91,10 +107,9 @@
#define __Pyx_TraceException() \ #define __Pyx_TraceException() \
if (likely(!__Pyx_use_tracing)); else { \ if (likely(!__Pyx_use_tracing)); else { \
PyThreadState* tstate = __Pyx_PyThreadState_Current; \ PyThreadState* tstate = __Pyx_PyThreadState_Current; \
if (tstate->use_tracing && \ if (__Pyx_IsTracing(tstate, 0, 1)) { \
(tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
tstate->tracing++; \ tstate->tracing++; \
tstate->use_tracing = 0; \ __Pyx_SetTracing(tstate, 0); \
PyObject *exc_info = __Pyx_GetExceptionTuple(tstate); \ PyObject *exc_info = __Pyx_GetExceptionTuple(tstate); \
if (exc_info) { \ if (exc_info) { \
if (CYTHON_TRACE && tstate->c_tracefunc) \ if (CYTHON_TRACE && tstate->c_tracefunc) \
...@@ -104,7 +119,7 @@ ...@@ -104,7 +119,7 @@
tstate->c_profileobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \ tstate->c_profileobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \
Py_DECREF(exc_info); \ Py_DECREF(exc_info); \
} \ } \
tstate->use_tracing = 1; \ __Pyx_SetTracing(tstate, 1); \
tstate->tracing--; \ tstate->tracing--; \
} \ } \
} }
...@@ -113,13 +128,13 @@ ...@@ -113,13 +128,13 @@
PyObject *type, *value, *traceback; PyObject *type, *value, *traceback;
__Pyx_ErrFetchInState(tstate, &type, &value, &traceback); __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
tstate->tracing++; tstate->tracing++;
tstate->use_tracing = 0; __Pyx_SetTracing(tstate, 0);
if (CYTHON_TRACE && tstate->c_tracefunc) if (CYTHON_TRACE && tstate->c_tracefunc)
tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_RETURN, result); tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_RETURN, result);
if (tstate->c_profilefunc) if (tstate->c_profilefunc)
tstate->c_profilefunc(tstate->c_profileobj, frame, PyTrace_RETURN, result); tstate->c_profilefunc(tstate->c_profileobj, frame, PyTrace_RETURN, result);
CYTHON_FRAME_DEL(frame); CYTHON_FRAME_DEL(frame);
tstate->use_tracing = 1; __Pyx_SetTracing(tstate, 1);
tstate->tracing--; tstate->tracing--;
__Pyx_ErrRestoreInState(tstate, type, value, traceback); __Pyx_ErrRestoreInState(tstate, type, value, traceback);
} }
...@@ -132,14 +147,14 @@ ...@@ -132,14 +147,14 @@
PyThreadState *tstate; \ PyThreadState *tstate; \
PyGILState_STATE state = PyGILState_Ensure(); \ PyGILState_STATE state = PyGILState_Ensure(); \
tstate = __Pyx_PyThreadState_Current; \ tstate = __Pyx_PyThreadState_Current; \
if (tstate->use_tracing) { \ if (__Pyx_IsTracing(tstate, 0, 0)) { \
__Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \ __Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \
} \ } \
PyGILState_Release(state); \ PyGILState_Release(state); \
} \ } \
} else { \ } else { \
PyThreadState* tstate = __Pyx_PyThreadState_Current; \ PyThreadState* tstate = __Pyx_PyThreadState_Current; \
if (tstate->use_tracing) { \ if (__Pyx_IsTracing(tstate, 0, 0)) { \
__Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \ __Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \
} \ } \
} \ } \
...@@ -148,7 +163,7 @@ ...@@ -148,7 +163,7 @@
#define __Pyx_TraceReturn(result, nogil) \ #define __Pyx_TraceReturn(result, nogil) \
if (likely(!__Pyx_use_tracing)); else { \ if (likely(!__Pyx_use_tracing)); else { \
PyThreadState* tstate = __Pyx_PyThreadState_Current; \ PyThreadState* tstate = __Pyx_PyThreadState_Current; \
if (tstate->use_tracing) { \ if (__Pyx_IsTracing(tstate, 0, 0)) { \
__Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \ __Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \
} \ } \
} }
...@@ -176,9 +191,11 @@ ...@@ -176,9 +191,11 @@
__Pyx_ErrFetchInState(tstate, &type, &value, &traceback); __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
__Pyx_PyFrame_SetLineNumber(frame, lineno); __Pyx_PyFrame_SetLineNumber(frame, lineno);
tstate->tracing++; tstate->tracing++;
tstate->use_tracing = 0; __Pyx_SetTracing(tstate, 0);
ret = tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_LINE, NULL); ret = tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_LINE, NULL);
tstate->use_tracing = 1;
__Pyx_SetTracing(tstate, 1);
tstate->tracing--; tstate->tracing--;
if (likely(!ret)) { if (likely(!ret)) {
__Pyx_ErrRestoreInState(tstate, type, value, traceback); __Pyx_ErrRestoreInState(tstate, type, value, traceback);
...@@ -199,7 +216,7 @@ ...@@ -199,7 +216,7 @@
PyThreadState *tstate; \ PyThreadState *tstate; \
PyGILState_STATE state = PyGILState_Ensure(); \ PyGILState_STATE state = PyGILState_Ensure(); \
tstate = __Pyx_PyThreadState_Current; \ tstate = __Pyx_PyThreadState_Current; \
if (unlikely(tstate->use_tracing && tstate->c_tracefunc && $frame_cname->f_trace)) { \ if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && $frame_cname->f_trace) { \
ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \ ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \
} \ } \
PyGILState_Release(state); \ PyGILState_Release(state); \
...@@ -207,7 +224,7 @@ ...@@ -207,7 +224,7 @@
} \ } \
} else { \ } else { \
PyThreadState* tstate = __Pyx_PyThreadState_Current; \ PyThreadState* tstate = __Pyx_PyThreadState_Current; \
if (unlikely(tstate->use_tracing && tstate->c_tracefunc && $frame_cname->f_trace)) { \ if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && $frame_cname->f_trace) { \
int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \ int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \
if (unlikely(ret)) goto_error; \ if (unlikely(ret)) goto_error; \
} \ } \
...@@ -217,7 +234,7 @@ ...@@ -217,7 +234,7 @@
#define __Pyx_TraceLine(lineno, nogil, goto_error) \ #define __Pyx_TraceLine(lineno, nogil, goto_error) \
if (likely(!__Pyx_use_tracing)); else { \ if (likely(!__Pyx_use_tracing)); else { \
PyThreadState* tstate = __Pyx_PyThreadState_Current; \ PyThreadState* tstate = __Pyx_PyThreadState_Current; \
if (unlikely(tstate->use_tracing && tstate->c_tracefunc && $frame_cname->f_trace)) { \ if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && $frame_cname->f_trace) { \
int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \ int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \
if (unlikely(ret)) goto_error; \ if (unlikely(ret)) goto_error; \
} \ } \
...@@ -264,18 +281,20 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code, ...@@ -264,18 +281,20 @@ static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
#endif #endif
} }
__Pyx_PyFrame_SetLineNumber(*frame, firstlineno); __Pyx_PyFrame_SetLineNumber(*frame, firstlineno);
retval = 1; retval = 1;
tstate->tracing++; tstate->tracing++;
tstate->use_tracing = 0; __Pyx_SetTracing(tstate, 0);
__Pyx_ErrFetchInState(tstate, &type, &value, &traceback); __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
#if CYTHON_TRACE #if CYTHON_TRACE
if (tstate->c_tracefunc) if (tstate->c_tracefunc)
retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0; retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0;
if (retval && tstate->c_profilefunc) if (retval && tstate->c_profilefunc)
#endif #endif
retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0; retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0;
tstate->use_tracing = (tstate->c_profilefunc ||
(CYTHON_TRACE && tstate->c_tracefunc)); __Pyx_SetTracing(tstate, (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc)));
tstate->tracing--; tstate->tracing--;
if (retval) { if (retval) {
__Pyx_ErrRestoreInState(tstate, type, value, traceback); __Pyx_ErrRestoreInState(tstate, type, value, traceback);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment