Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fixup! gh-124872: Mark the thread's default context as entered
  • Loading branch information
rhansen committed Nov 10, 2024
commit 756d837ee5c667a2d87ba78e0c752d930717b56d
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());
Comment thread
rhansen marked this conversation as resolved.
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