Skip to content

[3.10] bpo-43760: Ensure that older Cython generated code compiles under 3.10. #28474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ struct _ts {
uint64_t id;

CFrame root_cframe;
int use_tracing;

/* XXX signal handlers should also be here */

Expand Down
25 changes: 14 additions & 11 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -5476,7 +5476,7 @@ call_trace(Py_tracefunc func, PyObject *obj,
if (tstate->tracing)
return 0;
tstate->tracing++;
tstate->cframe->use_tracing = 0;
tstate->use_tracing = tstate->cframe->use_tracing = 0;
if (frame->f_lasti < 0) {
frame->f_lineno = frame->f_code->co_firstlineno;
}
Expand All @@ -5486,8 +5486,8 @@ call_trace(Py_tracefunc func, PyObject *obj,
}
result = func(obj, frame, what, arg);
frame->f_lineno = 0;
tstate->cframe->use_tracing = ((tstate->c_tracefunc != NULL)
|| (tstate->c_profilefunc != NULL));
tstate->use_tracing = tstate->cframe->use_tracing =
((tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL));
tstate->tracing--;
return result;
}
Expand All @@ -5501,11 +5501,11 @@ _PyEval_CallTracing(PyObject *func, PyObject *args)
PyObject *result;

tstate->tracing = 0;
tstate->cframe->use_tracing = ((tstate->c_tracefunc != NULL)
|| (tstate->c_profilefunc != NULL));
tstate->use_tracing = tstate->cframe->use_tracing =
((tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL));
result = PyObject_Call(func, args, NULL);
tstate->tracing = save_tracing;
tstate->cframe->use_tracing = save_use_tracing;
tstate->use_tracing = tstate->cframe->use_tracing = save_use_tracing;
return result;
}

Expand Down Expand Up @@ -5556,15 +5556,17 @@ _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
tstate->c_profilefunc = NULL;
tstate->c_profileobj = NULL;
/* Must make sure that tracing is not ignored if 'profileobj' is freed */
tstate->cframe->use_tracing = tstate->c_tracefunc != NULL;
tstate->use_tracing = tstate->cframe->use_tracing =
tstate->c_tracefunc != NULL;
Py_XDECREF(profileobj);

Py_XINCREF(arg);
tstate->c_profileobj = arg;
tstate->c_profilefunc = func;

/* Flag that tracing or profiling is turned on */
tstate->cframe->use_tracing = (func != NULL) || (tstate->c_tracefunc != NULL);
tstate->use_tracing = tstate->cframe->use_tracing =
(func != NULL) || (tstate->c_tracefunc != NULL);
return 0;
}

Expand Down Expand Up @@ -5597,16 +5599,17 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
tstate->c_tracefunc = NULL;
tstate->c_traceobj = NULL;
/* Must make sure that profiling is not ignored if 'traceobj' is freed */
tstate->cframe->use_tracing = (tstate->c_profilefunc != NULL);
tstate->use_tracing = tstate->cframe->use_tracing =
(tstate->c_profilefunc != NULL);
Py_XDECREF(traceobj);

Py_XINCREF(arg);
tstate->c_traceobj = arg;
tstate->c_tracefunc = func;

/* Flag that tracing or profiling is turned on */
tstate->cframe->use_tracing = ((func != NULL)
|| (tstate->c_profilefunc != NULL));
tstate->use_tracing = tstate->cframe->use_tracing =
((func != NULL) || (tstate->c_profilefunc != NULL));

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ new_threadstate(PyInterpreterState *interp, int init)
tstate->recursion_headroom = 0;
tstate->stackcheck_counter = 0;
tstate->tracing = 0;
tstate->use_tracing = 0;
tstate->root_cframe.use_tracing = 0;
tstate->cframe = &tstate->root_cframe;
tstate->gilstate_counter = 0;
Expand Down
10 changes: 6 additions & 4 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event,

/* Disallow tracing in hooks unless explicitly enabled */
ts->tracing++;
ts->cframe->use_tracing = 0;
ts->use_tracing = ts->cframe->use_tracing = 0;
while ((hook = PyIter_Next(hooks)) != NULL) {
_Py_IDENTIFIER(__cantrace__);
PyObject *o;
Expand All @@ -266,22 +266,24 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
break;
}
if (canTrace) {
ts->cframe->use_tracing = (ts->c_tracefunc || ts->c_profilefunc);
ts->use_tracing = ts->cframe->use_tracing =
(ts->c_tracefunc || ts->c_profilefunc);
ts->tracing--;
}
PyObject* args[2] = {eventName, eventArgs};
o = _PyObject_FastCallTstate(ts, hook, args, 2);
if (canTrace) {
ts->tracing++;
ts->cframe->use_tracing = 0;
ts->use_tracing = ts->cframe->use_tracing = 0;
}
if (!o) {
break;
}
Py_DECREF(o);
Py_CLEAR(hook);
}
ts->cframe->use_tracing = (ts->c_tracefunc || ts->c_profilefunc);
ts->use_tracing = ts->cframe->use_tracing =
(ts->c_tracefunc || ts->c_profilefunc);
ts->tracing--;
if (_PyErr_Occurred(ts)) {
goto exit;
Expand Down