Skip to content

Commit

Permalink
fixup! pythongh-124872: Mark the thread's default context as entered
Browse files Browse the repository at this point in the history
  • Loading branch information
rhansen committed Nov 10, 2024
1 parent 748f3eb commit 756d837
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Modules/_testcapi/watchers.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ clear_context_stack(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
static PyObject *
context_enter(PyObject *self, PyObject *ctx)
{
if (PyContext_Enter(ctx)) {
if (PyContext_Enter(ctx) < 0) {
return NULL;
}
Py_RETURN_NONE;
Expand Down
9 changes: 5 additions & 4 deletions Python/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ notify_context_watchers(PyThreadState *ts, PyContextEvent event, PyObject *ctx)
// The callbacks are registered on the interpreter, not on the thread, so
// the only way callbacks can know which thread changed is by calling the
// callbacks from the affected thread.
assert(ts != NULL);
assert(ts == _PyThreadState_GET());
if (ctx == NULL) {
// This will happen after exiting the last context in the stack, which
Expand Down Expand Up @@ -221,7 +222,7 @@ PyContext_Enter(PyObject *octx)
{
PyThreadState *ts = _PyThreadState_GET();
assert(ts != NULL);
if (_PyContext_Enter(ts, octx)) {
if (_PyContext_Enter(ts, octx) < 0) {
return -1;
}
context_switched(ts);
Expand Down Expand Up @@ -263,7 +264,7 @@ PyContext_Exit(PyObject *octx)
{
PyThreadState *ts = _PyThreadState_GET();
assert(ts != NULL);
if (_PyContext_Exit(ts, octx)) {
if (_PyContext_Exit(ts, octx) < 0) {
return -1;
}
context_switched(ts);
Expand All @@ -278,7 +279,7 @@ _PyContext_ExitThreadOwned(PyThreadState *ts)
while (ts->context != NULL
&& PyContext_CheckExact(ts->context)
&& ((PyContext *)ts->context)->ctx_owned_by_thread) {
if (_PyContext_Exit(ts, ts->context)) {
if (_PyContext_Exit(ts, ts->context) < 0) {
// Exiting a context that is already known to be at the top of the
// stack cannot fail.
Py_UNREACHABLE();
Expand Down Expand Up @@ -533,7 +534,7 @@ context_get(void)
assert(ts != NULL);
if (ts->context == NULL) {
PyContext *ctx = context_new_empty();
if (ctx == NULL || _PyContext_Enter(ts, (PyObject *)ctx)) {
if (ctx == NULL || _PyContext_Enter(ts, (PyObject *)ctx) < 0) {
return NULL;
}
ctx->ctx_owned_by_thread = 1;
Expand Down

0 comments on commit 756d837

Please sign in to comment.