Skip to content

Commit a71b043

Browse files
authored
gh-148171: Convert CALL_BUILTIN_CLASS to leave arguments on the stack (gh-148381)
1 parent 9831dea commit a71b043

File tree

11 files changed

+85
-58
lines changed

11 files changed

+85
-58
lines changed

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ _PyCallMethodDescriptorFastWithKeywords_StackRef(
461461
int total_args);
462462

463463
PyAPI_FUNC(PyObject *)
464-
_Py_CallBuiltinClass_StackRefSteal(
464+
_Py_CallBuiltinClass_StackRef(
465465
_PyStackRef callable,
466466
_PyStackRef *arguments,
467467
int total_args);

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: 1 addition & 1 deletion
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: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_testinternalcapi/test_cases.c.h

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

Python/bytecodes.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4572,23 +4572,24 @@ dummy_func(
45724572
EXIT_IF(tp->tp_vectorcall == NULL);
45734573
}
45744574

4575-
op(_CALL_BUILTIN_CLASS, (callable, self_or_null, args[oparg] -- res)) {
4575+
op(_CALL_BUILTIN_CLASS, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
45764576
int total_args = oparg;
45774577
_PyStackRef *arguments = args;
45784578
if (!PyStackRef_IsNull(self_or_null)) {
45794579
arguments--;
45804580
total_args++;
45814581
}
45824582
STAT_INC(CALL, hit);
4583-
PyObject *res_o = _Py_CallBuiltinClass_StackRefSteal(
4583+
PyObject *res_o = _Py_CallBuiltinClass_StackRef(
45844584
callable,
45854585
arguments,
45864586
total_args);
4587-
DEAD(args);
4588-
DEAD(self_or_null);
4589-
DEAD(callable);
4590-
ERROR_IF(res_o == NULL);
4591-
res = PyStackRef_FromPyObjectSteal(res_o);
4587+
if (res_o == NULL) {
4588+
ERROR_NO_POP();
4589+
}
4590+
_PyStackRef temp = callable;
4591+
callable = PyStackRef_FromPyObjectSteal(res_o);
4592+
PyStackRef_CLOSE(temp);
45924593
}
45934594

45944595
macro(CALL_BUILTIN_CLASS) =
@@ -4597,6 +4598,8 @@ dummy_func(
45974598
unused/2 +
45984599
_GUARD_CALLABLE_BUILTIN_CLASS +
45994600
_CALL_BUILTIN_CLASS +
4601+
_POP_TOP_OPARG +
4602+
POP_TOP +
46004603
_CHECK_PERIODIC_AT_END;
46014604

46024605
op(_GUARD_CALLABLE_BUILTIN_O, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {

Python/ceval.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -894,30 +894,20 @@ _PyCallMethodDescriptorFastWithKeywords_StackRef(
894894
}
895895

896896
PyObject *
897-
_Py_CallBuiltinClass_StackRefSteal(
897+
_Py_CallBuiltinClass_StackRef(
898898
_PyStackRef callable,
899899
_PyStackRef *arguments,
900900
int total_args)
901901
{
902902
PyObject *res;
903903
STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
904904
if (CONVERSION_FAILED(args_o)) {
905-
res = NULL;
906-
goto cleanup;
905+
return NULL;
907906
}
908907
PyTypeObject *tp = (PyTypeObject *)PyStackRef_AsPyObjectBorrow(callable);
909908
res = tp->tp_vectorcall((PyObject *)tp, args_o, total_args | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
910909
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
911910
assert((res != NULL) ^ (PyErr_Occurred() != NULL));
912-
cleanup:
913-
// arguments is a pointer into the GC visible stack,
914-
// so we must NULL out values as we clear them.
915-
for (int i = total_args-1; i >= 0; i--) {
916-
_PyStackRef tmp = arguments[i];
917-
arguments[i] = PyStackRef_NULL;
918-
PyStackRef_CLOSE(tmp);
919-
}
920-
PyStackRef_CLOSE(callable);
921911
return res;
922912
}
923913

Python/executor_cases.c.h

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

Python/optimizer_bytecodes.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,10 @@ dummy_func(void) {
13641364
callable = sym_new_not_null(ctx);
13651365
}
13661366

1367+
op(_CALL_BUILTIN_CLASS, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
1368+
callable = sym_new_not_null(ctx);
1369+
}
1370+
13671371
op(_GUARD_CALLABLE_METHOD_DESCRIPTOR_O, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
13681372
PyObject *callable_o = sym_get_const(ctx, callable);
13691373
if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type) &&

0 commit comments

Comments
 (0)