Skip to content

Commit bb03c8b

Browse files
authored
gh-145866: Convert _CALL_METHOD_DESCRIPTOR_NOARGS to leave its inputs on the stack to be cleaned up by _POP_TOP (GH-148227)
1 parent d2fa4b2 commit bb03c8b

File tree

10 files changed

+138
-72
lines changed

10 files changed

+138
-72
lines changed

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_uop_ids.h

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

Include/internal/pycore_uop_metadata.h

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

Lib/test/test_capi/test_opt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,9 +2780,12 @@ def testfunc(n):
27802780
self.assertEqual(res, TIER2_THRESHOLD * 5)
27812781
self.assertIsNotNone(ex)
27822782
uops = get_opnames(ex)
2783+
27832784
self.assertIn("_CALL_METHOD_DESCRIPTOR_NOARGS_INLINE", uops)
27842785
self.assertNotIn("_CALL_METHOD_DESCRIPTOR_NOARGS", uops)
27852786
self.assertNotIn("_GUARD_CALLABLE_METHOD_DESCRIPTOR_NOARGS", uops)
2787+
self.assertGreaterEqual(count_ops(ex, "_POP_TOP"), 5)
2788+
self.assertGreaterEqual(count_ops(ex, "_POP_TOP"), 3)
27862789

27872790
def test_call_method_descriptor_fast(self):
27882791
def testfunc(n):

Modules/_testinternalcapi/test_cases.c.h

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

Python/bytecodes.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4948,7 +4948,7 @@ dummy_func(
49484948
EXIT_IF(!Py_IS_TYPE(self, method->d_common.d_type));
49494949
}
49504950

4951-
op(_CALL_METHOD_DESCRIPTOR_NOARGS, (callable, self_or_null, args[oparg] -- res)) {
4951+
op(_CALL_METHOD_DESCRIPTOR_NOARGS, (callable, self_or_null, args[oparg] -- res, c, s)) {
49524952
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
49534953
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
49544954

@@ -4963,15 +4963,16 @@ dummy_func(
49634963
PyObject *res_o = _PyCFunction_TrampolineCall(cfunc, self, NULL);
49644964
_Py_LeaveRecursiveCallTstate(tstate);
49654965
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
4966-
PyStackRef_CLOSE(self_stackref);
4967-
DEAD(args);
4968-
DEAD(self_or_null);
4969-
PyStackRef_CLOSE(callable);
4970-
ERROR_IF(res_o == NULL);
4966+
if (res_o == NULL) {
4967+
ERROR_NO_POP();
4968+
}
4969+
c = callable;
4970+
s = args[0];
4971+
INPUTS_DEAD();
49714972
res = PyStackRef_FromPyObjectSteal(res_o);
49724973
}
49734974

4974-
tier2 op(_CALL_METHOD_DESCRIPTOR_NOARGS_INLINE, (callable, args[oparg], cfunc/4 -- res)) {
4975+
tier2 op(_CALL_METHOD_DESCRIPTOR_NOARGS_INLINE, (callable, args[oparg], cfunc/4 -- res, c, s)) {
49754976
assert(oparg == 1);
49764977
_PyStackRef self_stackref = args[0];
49774978
PyObject *self = PyStackRef_AsPyObjectBorrow(self_stackref);
@@ -4980,10 +4981,12 @@ dummy_func(
49804981
PyObject *res_o = _PyCFunction_TrampolineCall(cfunc_v, self, NULL);
49814982
_Py_LeaveRecursiveCallTstate(tstate);
49824983
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
4983-
PyStackRef_CLOSE(self_stackref);
4984-
DEAD(args);
4985-
PyStackRef_CLOSE(callable);
4986-
ERROR_IF(res_o == NULL);
4984+
if (res_o == NULL) {
4985+
ERROR_NO_POP();
4986+
}
4987+
c = callable;
4988+
s = args[0];
4989+
INPUTS_DEAD();
49874990
res = PyStackRef_FromPyObjectSteal(res_o);
49884991
}
49894992

@@ -4994,6 +4997,8 @@ dummy_func(
49944997
_GUARD_CALLABLE_METHOD_DESCRIPTOR_NOARGS +
49954998
_CHECK_RECURSION_LIMIT +
49964999
_CALL_METHOD_DESCRIPTOR_NOARGS +
5000+
POP_TOP +
5001+
POP_TOP +
49975002
_CHECK_PERIODIC_AT_END;
49985003

49995004
op(_GUARD_CALLABLE_METHOD_DESCRIPTOR_FAST, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {

Python/executor_cases.c.h

Lines changed: 20 additions & 24 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: 24 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)