8000 gh-99633: _contextvars: Clarify that the ref is stolen, not borrowed · rhansen/cpython@11c500b · GitHub
[go: up one dir, main page]

Skip to content

Commit 11c500b

Browse files
committed
pythongh-99633: _contextvars: Clarify that the ref is stolen, not borrowed
Improve readability by moving destination assignment next to source reset, and comment that the ref is stolen.
1 parent 1e02793 commit 11c500b

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Python/context.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,8 @@ _PyContext_Enter(PyThreadState *ts, PyContext *ctx)
202202
return -1;
203203
}
204204

205-
ctx->ctx_prev = ts->context; /* borrow */
206205
ctx->ctx_entered = 1;
207-
206+
ctx->ctx_prev = ts->context; /* steal */
208207
ts->context = Py_NewRef(ctx);
209208
context_switched(ts);
210209
return 0;
@@ -238,8 +237,7 @@ _PyContext_Exit(PyThreadState *ts, PyContext *ctx)
238237
return -1;
239238
}
240239

241-
Py_SETREF(ts->context, ctx->ctx_prev);
242-
240+
Py_SETREF(ts->context, ctx->ctx_prev); /* steal */
243241
ctx->ctx_prev = NULL;
244242
ctx->ctx_entered = 0;
245243
context_switched(ts);

0 commit comments

Comments
 (0)
0