Skip to content

Commit 0327b8b

Browse files
committed
Add _PyThreadState_PopCStackRefSteal as suggested by Sam
1 parent 6a85f95 commit 0327b8b

File tree

5 files changed

+18
-60
lines changed

5 files changed

+18
-60
lines changed

Include/internal/pycore_stackref.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,17 @@ _PyThreadState_PopCStackRef(PyThreadState *tstate, _PyCStackRef *ref)
827827
PyStackRef_XCLOSE(ref->ref);
828828
}
829829

830+
static inline _PyStackRef
831+
_PyThreadState_PopCStackRefSteal(PyThreadState *tstate, _PyCStackRef *ref)
832+
{
833+
#ifdef Py_GIL_DISABLED
834+
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
835+
assert(tstate_impl->c_stack_refs == ref);
836+
tstate_impl->c_stack_refs = ref->next;
837+
#endif
838+
return ref->ref;
839+
}
840+
830841
#ifdef Py_GIL_DISABLED
831842

832843
static inline int

Python/bytecodes.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,11 +2339,7 @@ dummy_func(
23392339
assert(!PyStackRef_IsNull(method.ref)); // No errors on this branch
23402340
self_or_null[0] = owner; // Transfer ownership
23412341
DEAD(owner);
2342-
attr = method.ref;
2343-
#ifdef Py_GIL_DISABLED
2344-
method.ref = PyStackRef_NULL;
2345-
_PyThreadState_PopCStackRef(tstate, &method);
2346-
#endif
2342+
attr = _PyThreadState_PopCStackRefSteal(tstate, &method);
23472343
}
23482344
else {
23492345
/* meth is not an unbound method (but a regular attr, or
@@ -2354,11 +2350,7 @@ dummy_func(
23542350
*/
23552351
PyStackRef_CLOSE(owner);
23562352
self_or_null[0] = PyStackRef_NULL;
2357-
attr = method.ref;
2358-
#ifdef Py_GIL_DISABLED
2359-
method.ref = PyStackRef_NULL;
2360-
_PyThreadState_PopCStackRef(tstate, &method);
2361-
#endif
2353+
attr = _PyThreadState_PopCStackRefSteal(tstate, &method);
23622354
ERROR_IF(PyStackRef_IsNull(attr));
23632355
}
23642356
}

Python/executor_cases.c.h

Lines changed: 2 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 2 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/cases_generator/analyzer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ def has_error_without_pop(op: parser.CodeDef) -> bool:
697697
"PyStackRef_Wrap",
698698
"PyStackRef_Unwrap",
699699
"_PyLong_CheckExactAndCompact",
700+
"_PyThreadState_PopCStackRefSteal",
700701
)
701702

702703

0 commit comments

Comments
 (0)