Skip to content

Commit 756d837

Browse files
committed
fixup! pythongh-124872: Mark the thread's default context as entered
1 parent 748f3eb commit 756d837

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Modules/_testcapi/watchers.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ clear_context_stack(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
727727
static PyObject *
728728
context_enter(PyObject *self, PyObject *ctx)
729729
{
730-
if (PyContext_Enter(ctx)) {
730+
if (PyContext_Enter(ctx) < 0) {
731731
return NULL;
732732
}
733733
Py_RETURN_NONE;

Python/context.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ notify_context_watchers(PyThreadState *ts, PyContextEvent event, PyObject *ctx)
116116
// The callbacks are registered on the interpreter, not on the thread, so
117117
// the only way callbacks can know which thread changed is by calling the
118118
// callbacks from the affected thread.
119+
assert(ts != NULL);
119120
assert(ts == _PyThreadState_GET());
120121
if (ctx == NULL) {
121122
// This will happen after exiting the last context in the stack, which
@@ -221,7 +222,7 @@ PyContext_Enter(PyObject *octx)
221222
{
222223
PyThreadState *ts = _PyThreadState_GET();
223224
assert(ts != NULL);
224-
if (_PyContext_Enter(ts, octx)) {
225+
if (_PyContext_Enter(ts, octx) < 0) {
225226
return -1;
226227
}
227228
context_switched(ts);
@@ -263,7 +264,7 @@ PyContext_Exit(PyObject *octx)
263264
{
264265
PyThreadState *ts = _PyThreadState_GET();
265266
assert(ts != NULL);
266-
if (_PyContext_Exit(ts, octx)) {
267+
if (_PyContext_Exit(ts, octx) < 0) {
267268
return -1;
268269
}
269270
context_switched(ts);
@@ -278,7 +279,7 @@ _PyContext_ExitThreadOwned(PyThreadState *ts)
278279
while (ts->context != NULL
279280
&& PyContext_CheckExact(ts->context)
280281
&& ((PyContext *)ts->context)->ctx_owned_by_thread) {
281-
if (_PyContext_Exit(ts, ts->context)) {
282+
if (_PyContext_Exit(ts, ts->context) < 0) {
282283
// Exiting a context that is already known to be at the top of the
283284
// stack cannot fail.
284285
Py_UNREACHABLE();
@@ -533,7 +534,7 @@ context_get(void)
533534
assert(ts != NULL);
534535
if (ts->context == NULL) {
535536
PyContext *ctx = context_new_empty();
536-
if (ctx == NULL || _PyContext_Enter(ts, (PyObject *)ctx)) {
537+
if (ctx == NULL || _PyContext_Enter(ts, (PyObject *)ctx) < 0) {
537538
return NULL;
538539
}
539540
ctx->ctx_owned_by_thread = 1;

0 commit comments

Comments
 (0)