Skip to content

Commit e872c19

Browse files
authored
gh-148171: Convert variadic argument opcodes to leave their arguments on the stack (CALL_BUILTIN_FAST_WITH_KEYWORDS) (#148366)
1 parent 2b439da commit e872c19

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
@@ -439,7 +439,7 @@ _Py_BuiltinCallFast_StackRef(
439439
int total_args);
440440

441441
PyAPI_FUNC(PyObject *)
442-
_Py_BuiltinCallFastWithKeywords_StackRefSteal(
442+
_Py_BuiltinCallFastWithKeywords_StackRef(
443443
_PyStackRef callable,
444444
_PyStackRef *arguments,
445445
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
@@ -4692,7 +4692,7 @@ dummy_func(
46924692
EXIT_IF(PyCFunction_GET_FLAGS(callable_o) != (METH_FASTCALL | METH_KEYWORDS));
46934693
}
46944694

4695-
op(_CALL_BUILTIN_FAST_WITH_KEYWORDS, (callable, self_or_null, args[oparg] -- res)) {
4695+
op(_CALL_BUILTIN_FAST_WITH_KEYWORDS, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
46964696
/* Builtin METH_FASTCALL | METH_KEYWORDS functions */
46974697
int total_args = oparg;
46984698
_PyStackRef *arguments = args;
@@ -4701,12 +4701,13 @@ dummy_func(
47014701
total_args++;
47024702
}
47034703
STAT_INC(CALL, hit);
4704-
PyObject *res_o = _Py_BuiltinCallFastWithKeywords_StackRefSteal(callable, arguments, total_args);
4705-
DEAD(args);
4706-
DEAD(self_or_null);
4707-
DEAD(callable);
4708-
ERROR_IF(res_o == NULL);
4709-
res = PyStackRef_FromPyObjectSteal(res_o);
4704+
PyObject *res_o = _Py_BuiltinCallFastWithKeywords_StackRef(callable, arguments, total_args);
4705+
if (res_o == NULL) {
4706+
ERROR_NO_POP();
4707+
}
4708+
_PyStackRef temp = callable;
4709+
callable = PyStackRef_FromPyObjectSteal(res_o);
4710+
PyStackRef_CLOSE(temp);
47104711
}
47114712

47124713
macro(CALL_BUILTIN_FAST_WITH_KEYWORDS) =
@@ -4715,6 +4716,8 @@ dummy_func(
47154716
unused/2 +
47164717
_GUARD_CALLABLE_BUILTIN_FAST_WITH_KEYWORDS +
47174718
_CALL_BUILTIN_FAST_WITH_KEYWORDS +
4719+
_POP_TOP_OPARG +
4720+
POP_TOP +
47184721
_CHECK_PERIODIC_AT_END;
47194722

47204723
macro(CALL_LEN) =

Python/ceval.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -832,32 +832,22 @@ _Py_BuiltinCallFast_StackRef(
832832
}
833833

834834
PyObject *
835-
_Py_BuiltinCallFastWithKeywords_StackRefSteal(
835+
_Py_BuiltinCallFastWithKeywords_StackRef(
836836
_PyStackRef callable,
837837
_PyStackRef *arguments,
838838
int total_args)
839839
{
840840
PyObject *res;
841841
STACKREFS_TO_PYOBJECTS(arguments, total_args, args_o);
842842
if (CONVERSION_FAILED(args_o)) {
843-
res = NULL;
844-
goto cleanup;
843+
return NULL;
845844
}
846845
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
847846
PyCFunctionFastWithKeywords cfunc =
848847
_PyCFunctionFastWithKeywords_CAST(PyCFunction_GET_FUNCTION(callable_o));
849848
res = cfunc(PyCFunction_GET_SELF(callable_o), args_o, total_args, NULL);
850849
STACKREFS_TO_PYOBJECTS_CLEANUP(args_o);
851850
assert((res != NULL) ^ (PyErr_Occurred() != NULL));
852-
cleanup:
853-
// arguments is a pointer into the GC visible stack,
854-
// so we must NULL out values as we clear them.
855-
for (int i = total_args-1; i >= 0; i--) {
856-
_PyStackRef tmp = arguments[i];
857-
arguments[i] = PyStackRef_NULL;
858-
PyStackRef_CLOSE(tmp);
859-
}
860-
PyStackRef_CLOSE(callable);
861851
return res;
862852
}
863853

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
@@ -1338,6 +1338,10 @@ dummy_func(void) {
13381338
}
13391339
}
13401340

1341+
op(_CALL_BUILTIN_FAST_WITH_KEYWORDS, (callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
1342+
callable = sym_new_not_null(ctx);
1343+
}
1344+
13411345
op(_CALL_BUILTIN_O, (callable, self_or_null, args[oparg] -- res, c, s)) {
13421346
res = sym_new_not_null(ctx);
13431347
c = callable;

0 commit comments

Comments
 (0)