8000 gh-90370: Avoid temporary `varargs` tuple creation in argument passing by colorfulappl · Pull Request #30312 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-90370: Avoid temporary varargs tuple creation in argument passing #30312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b68176d
Avoid temporary `varargs` tuple creation in argument passing
colorfulappl Dec 31, 2021
43b9410
Optimize argument passing of builtin print() with modified Argument C…
colorfulappl Dec 31, 2021
9b37a77
Revert modification of PyAPI_FUNC _PyArg_UnpackKeywordsWithVararg to …
colorfulappl Jan 4, 2022
46e4472
📜🤖 Added by blurb_it.
blurb-it[bot] Jan 4, 2022
e06f343
Revert _PyArg_UnpackKeywordsWithVararg and add _PyArg_UnpackKeywordsW…
colorfulappl Jan 4, 2022
d35410b
Fix a bug which allows more than one varargs
colorfulappl Feb 22, 2022
0a9fe91
Do not copy posargs and vararg during argument parsing
colorfulappl Mar 22, 2022
9188052
Rename _PyArg_UnpackKeywordsWithVarargFast, it returns kwargs only now
colorfulappl Mar 23, 2022
d245ec0
Check type of varargs when generating argument parser
colorfulappl Mar 23, 2022
8d16685
Fix varargssize calculation in class init and add test cases
colorfulappl Mar 23, 2022
f4213ea
Merge branch 'main' into opt_ac
colorfulappl Mar 23, 2022
156f8d6
Rerun make clinic
colorfulappl Mar 23, 2022
c32aed4
Edit documentation
colorfulappl Mar 23, 2022
7ef5623
Merge branch 'main' into opt_ac
colorfulappl Feb 3, 2023
3ac2821
Fix errors introduced by merging and rerun make clinic
colorfulappl Feb 3, 2023
f63a704
Update news
colorfulappl Feb 3, 2023
8f61f5e
Fix varargssize in new_or_init
colorfulappl Feb 6, 2023
1eff215
Simplify the code a bit
colorfulappl Feb 6, 2023
5baf0f5
Optimize generated varargssize assignment
colorfulappl Feb 6, 2023
30c0606
Fix argument passing in new_or_init
colorfulappl Feb 7, 2023
d9e7408
Add tests for class method `__new__`
colorfulappl Feb 7, 2023
0f04a95
Merge branch 'main' into opt_ac
colorfulappl Feb 7, 2023
85a8ac5
Correct test function name
colorfulappl Feb 8, 2023
a9d1424
Fix vararg parsing when its name is not `args`
colorfulappl Feb 8, 2023
d6ff01a
Merge branch 'main' into opt_ac
colorfulappl Feb 8, 2023
597152e
Add testcases for undeclared keyword arguments
colorfulappl Feb 8, 2023
3119fa6
Merge branch 'main' into opt_ac
erlend-aasland Apr 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify the code a bit
  • Loading branch information
colorfulappl committed Feb 6, 2023
commit 1eff215c27941fab3cc7dfb54b57cb6ee41e15da
16 changes: 8 additions & 8 deletions Lib/test/clinic.test
Original file line number Diff line number Diff line change
Expand Up @@ -3845,8 +3845,8 @@ test_vararg(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
};
#undef KWTUPLE
PyObject *argsbuf[0];
Py_ssize_t varargssize = Py_MAX(nargs - 1, 0);
PyObject *const *fastargs;
Py_ssize_t varargssize = Py_MAX(nargs - 1, 0);
PyObject *a;
PyObject *const *__clinic_args;

Expand All @@ -3865,7 +3865,7 @@ exit:
static PyObject *
test_vararg_impl(PyObject *module, PyObject *a, Py_ssize_t varargssize,
PyObject *const *args)
/*[clinic end generated code: output=fb100afa02682813 input=81d33815ad1bae6e]*/
/*[clinic end generated code: output=2f4921abd6707648 input=81d33815ad1bae6e]*/

/*[clinic input]
test_vararg_with_default
Expand Down Expand Up @@ -3920,9 +3920,9 @@ test_vararg_with_default(PyObject *module, PyObject *const *args, Py_ssize_t nar
};
#undef KWTUPLE
PyObject *argsbuf[1];
Py_ssize_t varargssize = Py_MAX(nargs - 1, 0);
PyObject *const *fastargs;
Py_ssize_t noptargs = Py_MIN(nargs, 1) + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Py_ssize_t varargssize = Py_MAX(nargs - 1, 0);
PyObject *a;
PyObject *const *__clinic_args;
int b = 0;
Expand Down Expand Up @@ -3951,7 +3951,7 @@ static PyObject *
test_vararg_with_default_impl(PyObject *module, PyObject *a,
Py_ssize_t varargssize, PyObject *const *args,
int b)
/*[clinic end generated code: output=c724b7a1b327f798 input=6e110b54acd9b22d]*/
/*[clinic end generated code: output=60a4333c34883cc3 input=6e110b54acd9b22d]*/

/*[clinic input]
test_vararg_with_only_defaults
Expand Down Expand Up @@ -4006,9 +4006,9 @@ test_vararg_with_only_defaults(PyObject *module, PyObject *const *args, Py_ssize
};
#undef KWTUPLE
PyObject *argsbuf[2];
Py_ssize_t varargssize = Py_MAX(nargs - 0, 0);
PyObject *const *fastargs;
Py_ssize_t noptargs = 0 + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Py_ssize_t varargssize = Py_MAX(nargs - 0, 0);
PyObject *const *__clinic_args;
int b = 0;
PyObject *c = " ";
Expand Down Expand Up @@ -4042,7 +4042,7 @@ static PyObject *
test_vararg_with_only_defaults_impl(PyObject *module, Py_ssize_t varargssize,
PyObject *const *args, int b,
PyObject *c)
/*[clinic end generated code: output=bdc061cc11a3abde input=fa56a709a035666e]*/
/*[clinic end generated code: output=e68965b94622fbfc input=fa56a709a035666e]*/

/*[clinic input]
test_paramname_module
Expand Down Expand Up @@ -4205,8 +4205,8 @@ TestModule_TestClass1___init__(PyObject *self, PyObject *args, PyObject *kwargs)
PyObject *argsbuf[1];
PyObject * const *fastargs;
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
Py_ssize_t varargssize = Py_MAX(nargs - 1, 0);
Py_ssize_t noptargs = Py_MIN(nargs, 1) + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
Py_ssize_t varargssize = Py_MAX(nargs - 1, 0);
PyObject *pos;
PyObject *const *__clinic_args;
PyObject *kw = Py_None;
Expand All @@ -4232,4 +4232,4 @@ static int
TestModule_TestClass1___init___impl(TestClassObject *self, PyObject *pos,
Py_ssize_t varargssize,
PyObject *const *args, PyObject *kw)
/*[clinic end generated code: output=b7e8fba5e3e6e531 input=da8e0daa18983316]*/
/*[clinic end generated code: output=2cfcce182118ec62 input=da8e0daa18983316]*/
14 changes: 7 additions & 7 deletions Modules/clinic/_testclinic.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Python/clinic/bltinmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ def parser_body(prototype, *fields, declarations=''):
)
nargs = "nargs"
argsbuf_size = len(converters)
varargssize = ""
else:
args_declaration = "_PyArg_UnpackKeywordsWithVarargKwonly", "%s, %s, %s, %s" % (
min_pos,
Expand All @@ -1031,13 +1032,13 @@ def parser_body(prototype, *fields, declarations=''):
)
nargs = f"Py AB11 _MIN(nargs, {max_pos})" if max_pos else "0"
argsbuf_size = len(converters) - vararg - 1
varargssize = "\nPy_ssize_t varargssize = Py_MAX(nargs - %d, 0);" % (max_pos)
declarations = declare_parser(f)
declarations += "\nPyObject *argsbuf[%s];" % argsbuf_size
if not new_or_init:
flags = "METH_FASTCALL|METH_KEYWORDS"
parser_prototype = parser_prototype_fastcall_keywords
declarations = declare_parser(f)
declarations += "\nPyObject *argsbuf[%s];" % argsbuf_size
if vararg != NO_VARARG:
declarations += "\nPy_ssize_t varargssize = Py_MAX(nargs - %d, 0);" % (max_pos)
declarations += "\nPyObject *const *fastargs;"
parsed_argname = "fastargs"
else:
Expand All @@ -1055,13 +1056,8 @@ def parser_body(prototype, *fields, declarations=''):
# positional-or-keyword arguments
flags = "METH_VARARGS|METH_KEYWORDS"
parser_prototype = parser_prototype_keyword
argname_fmt = 'fastargs[%d]'
declarations = declare_parser(f)
declarations += "\nPyObject *argsbuf[%s];" % argsbuf_size
declarations += "\nPyObject * const *fastargs;"
declarations += "\nPy_ssize_t nargs = PyTuple_GET_SIZE(args);"
if vararg != NO_VARARG:
declarations += "\nPy_ssize_t varargssize = Py_MAX(nargs - %d, 0);" % (max_pos)
if has_optional_kw:
declarations += "\nPy_ssize_t noptargs = %s + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - %d;" % (nargs, min_pos + min_kw_only)
parser_code = [normalize_snippet("""
Expand All @@ -1070,6 +1066,8 @@ def parser_body(prototype, *fields, declarations=''):
goto exit;
}}
""" % args_declaration, indent=4)]
argname_fmt = 'fastargs[%d]'
declarations += varargssize

if requires_defining_class:
flags = 'METH_METHOD|' + flags
Expand Down
0