summaryrefslogtreecommitdiffstats
path: root/Python/optimizer_bytecodes.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2025-04-21 19:54:25 (GMT)
committerGitHub <noreply@github.com>2025-04-21 19:54:25 (GMT)
commitda53660f35db2dfb1e6181e603468dfe5758f3b8 (patch)
treecf641cfff0634552f7d84ae9b246fa17d5e04166 /Python/optimizer_bytecodes.c
parent8dfa840773d1d6bae1bf6e0dfa07618ea10c9d71 (diff)
downloadcpython-da53660f35db2dfb1e6181e603468dfe5758f3b8.zip
cpython-da53660f35db2dfb1e6181e603468dfe5758f3b8.tar.gz
cpython-da53660f35db2dfb1e6181e603468dfe5758f3b8.tar.bz2
gh-131586: Avoid refcount contention in context managers (gh-131851)
This avoid reference count contention in the free threading build when calling special methods like `__enter__` and `__exit__`.
Diffstat (limited to 'Python/optimizer_bytecodes.c')
-rw-r--r--Python/optimizer_bytecodes.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index 6f7f9b0..9f1e3f6 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -897,9 +897,14 @@ dummy_func(void) {
}
}
- op(_LOAD_SPECIAL, (owner -- attr, self_or_null)) {
- attr = sym_new_not_null(ctx);
- self_or_null = sym_new_unknown(ctx);
+ op(_INSERT_NULL, (self -- method_and_self[2])) {
+ method_and_self[0] = sym_new_null(ctx);
+ method_and_self[1] = self;
+ }
+
+ op(_LOAD_SPECIAL, (method_and_self[2] -- method_and_self[2])) {
+ method_and_self[0] = sym_new_not_null(ctx);
+ method_and_self[1] = sym_new_unknown(ctx);
}
op(_JUMP_TO_TOP, (--)) {