-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-90370: Avoid temporary varargs
tuple creation in argument passing
#30312
base: main
Are you sure you want to change the base?
Changes from 5 commits
b68176d
43b9410
9b37a77
46e4472
e06f343
d35410b
0a9fe91
9188052
d245ec0
8d16685
f4213ea
156f8d6
c32aed4
7ef5623
3ac2821
f63a704
8f61f5e
1eff215
5baf0f5
30c0606
d9e7408
0f04a95
85a8ac5
a9d1424
d6ff01a
597152e
3119fa6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3324,14 +3324,15 @@ PyDoc_STRVAR(test_vararg_and_posonly__doc__, | |
{"test_vararg_and_posonly", (PyCFunction)(void(*)(void))test_vararg_and_posonly, METH_FASTCALL, test_vararg_and_posonly__doc__}, | ||
|
||
static PyObject * | ||
test_vararg_and_posonly_impl(PyObject *module, PyObject *a, PyObject *args); | ||
test_vararg_and_posonly_impl(PyObject *module, PyObject *a, | ||
Py_ssize_t varargssize, PyObject *const *args); | ||
|
||
static PyObject * | ||
test_vararg_and_posonly(PyObject *module, PyObject *const *args, Py_ssize_t nargs) | ||
{ | ||
PyObject *return_value = NULL; | ||
PyObject *a; | ||
PyObject *__clinic_args = NULL; | ||
PyObject *const *__clinic_args = NULL; | ||
|
||
if (!_PyArg_CheckPositional("test_vararg_and_posonly", nargs, 1, PY_SSIZE_T_MAX)) { | ||
goto exit; | ||
|
@@ -3341,16 +3342,16 @@ test_vararg_and_posonly(PyObject *module, PyObject *const *args, Py_ssize_t narg | |
for (Py_ssize_t i = 0; i < nargs - 1; ++i) { | ||
PyTuple_SET_ITEM(__clinic_args, i, args[1 + i]); | ||
} | ||
return_value = test_vararg_and_posonly_impl(module, a, __clinic_args); | ||
return_value = test_vararg_and_posonly_impl(module, a, varargssize, __clinic_args); | ||
|
||
exit: | ||
Py_XDECREF(__clinic_args); | ||
return return_value; | ||
} | ||
|
||
static PyObject * | ||
test_vararg_and_posonly_impl(PyObject *module, PyObject *a, PyObject *args) | ||
/*[clinic end generated code: output=ada613d2d87c9341 input=08dc2bf7afbf1613]*/ | ||
test_vararg_and_posonly_impl(PyObject *module, PyObject *a, | ||
Py_ssize_t varargssize, PyObject *const *args) | ||
/*[clinic end generated code: output=6a6c69c6ff7deb9b input=08dc2bf7afbf1613]*/ | ||
|
||
/*[clinic input] | ||
test_vararg | ||
|
@@ -3370,7 +3371,8 @@ PyDoc_STRVAR(test_vararg__doc__, | |
{"test_vararg", (PyCFunction)(void(*)(void))test_vararg, METH_FASTCALL|METH_KEYWORDS, test_vararg__doc__}, | ||
|
||
static PyObject * | ||
test_vararg_impl(PyObject *module, PyObject *a, PyObject *args); | ||
test_vararg_impl(PyObject *module, PyObject *a, Py_ssize_t varargssize, | ||
PyObject *const *args); | ||
|
||
static PyObject * | ||
test_vararg(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) | ||
|
@@ -3379,26 +3381,27 @@ test_vararg(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject | |
static const char * const _keywords[] = {"a", NULL}; | ||
static _PyArg_Parser _parser = {NULL, _keywords, "test_vararg", 0}; | ||
PyObject *argsbuf[2]; | ||
Py_ssize_t varargssize = Py_MAX(nargs - 1, 0); | ||
Py_ssize_t noptargs = 0 + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; | ||
PyObject *a; | ||
PyObject *__clinic_args = NULL; | ||
PyObject *const *__clinic_args = NULL; | ||
|
||
args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, 1, argsbuf); | ||
args = _PyArg_UnpackKeywordsWithVarargFast(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, 1, varargssize, argsbuf); | ||
if (!args) { | ||
goto exit; | ||
} | ||
a = args[0]; | ||
__clinic_args = args[1]; | ||
return_value = test_vararg_impl(module, a, __clinic_args); | ||
__clinic_args = (PyObject *const *)args[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to avoid such unsafe casts. Maybe passing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This copy and cast are unnecessary. |
||
return_value = test_vararg_impl(module, a, varargssize, __clinic_args); | ||
|
||
exit: | ||
Py_XDECREF(__clinic_args); | ||
return return_value; | ||
} | ||
|
||
static PyObject * | ||
test_vararg_impl(PyObject *module, PyObject *a, PyObject *args) | ||
/*[clinic end generated code: output=f721025731c3bfe8 input=81d33815ad1bae6e]*/ | ||
test_vararg_impl(PyObject *module, PyObject *a, Py_ssize_t varargssize, | ||
PyObject *const *args) | ||
/*[clinic end generated code: output=b9cb9484bd7303db input=81d33815ad1bae6e]*/ | ||
|
||
/*[clinic input] | ||
test_vararg_with_default | ||
|
@@ -3419,7 +3422,8 @@ PyDoc_STRVAR(test_vararg_with_default__doc__, | |
{"test_vararg_with_default", (PyCFunction)(void(*)(void))test_vararg_with_default, METH_FASTCALL|METH_KEYWORDS, test_vararg_with_default__doc__}, | ||
|
||
static PyObject * | ||
test_vararg_with_default_impl(PyObject *module, PyObject *a, PyObject *args, | ||
test_vararg_with_default_impl(PyObject *module, PyObject *a, | ||
Py_ssize_t varargssize, PyObject *const *args, | ||
int b); | ||
|
||
static PyObject * | ||
|
@@ -3429,17 +3433,18 @@ test_vararg_with_default(PyObject *module, PyObject *const *args, Py_ssize_t nar | |
static const char * const _keywords[] = {"a", "b", NULL}; | ||
static _PyArg_Parser _parser = {NULL, _keywords, "test_vararg_with_default", 0}; | ||
PyObject *argsbuf[3]; | ||
Py_ssize_t varargssize = Py_MAX(nargs - 1, 0); | ||
Py_ssize_t noptargs = 0 + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; | ||
PyObject *a; | ||
PyObject *__clinic_args = NULL; | ||
PyObject *const *__clinic_args = NULL; | ||
int b = 0; | ||
|
||
args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, 1, argsbuf); | ||
args = _PyArg_UnpackKeywordsWithVarargFast(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, 1, varargssize, argsbuf); | ||
if (!args) { | ||
goto exit; | ||
} | ||
a = args[0]; | ||
__clinic_args = args[1]; | ||
__clinic_args = (PyObject *const *)args[1]; | ||
if (!noptargs) { | ||
goto skip_optional_kwonly; | ||
} | ||
|
@@ -3448,17 +3453,17 @@ test_vararg_with_default(PyObject *module, PyObject *const *args, Py_ssize_t nar | |
goto exit; | ||
} | ||
skip_optional_kwonly: | ||
return_value = test_vararg_with_default_impl(module, a, __clinic_args, b); | ||
return_value = test_vararg_with_default_impl(module, a, varargssize, __clinic_args, b); | ||
|
||
exit: | ||
Py_XDECREF(__clinic_args); | ||
return return_value; | ||
} | ||
|
||
static PyObject * | ||
test_vararg_with_default_impl(PyObject *module, PyObject *a, PyObject *args, | ||
test_vararg_with_default_impl(PyObject *module, PyObject *a, | ||
Py_ssize_t varargssize, PyObject *const *args, | ||
int b) | ||
/*[clinic end generated code: output=63b34d3241c52fda input=6e110b54acd9b22d]*/ | ||
/*[clinic end generated code: output=d38066fd9fa9336f input=6e110b54acd9b22d]*/ | ||
|
||
/*[clinic input] | ||
test_vararg_with_only_defaults | ||
|
@@ -3479,7 +3484,8 @@ PyDoc_STRVAR(test_vararg_with_only_defaults__doc__, | |
{"test_vararg_with_only_defaults", (PyCFunction)(void(*)(void))test_vararg_with_only_defaults, METH_FASTCALL|METH_KEYWORDS, test_vararg_with_only_defaults__doc__}, | ||
|
||
static PyObject * | ||
test_vararg_with_only_defaults_impl(PyObject *module, PyObject *args, int b, | ||
test_vararg_with_only_defaults_impl(PyObject *module, Py_ssize_t varargssize, | ||
PyObject *const *args, int b, | ||
PyObject *c); | ||
|
||
static PyObject * | ||
|
@@ -3489,16 +3495,17 @@ test_vararg_with_only_defaults(PyObject *module, PyObject *const *args, Py_ssize | |
static const char * const _keywords[] = {"b", "c", NULL}; | ||
static _PyArg_Parser _parser = {NULL, _keywords, "test_vararg_with_only_defaults", 0}; | ||
PyObject *argsbuf[3]; | ||
Py_ssize_t varargssize = Py_MAX(nargs - 0, 0); | ||
Py_ssize_t noptargs = 0 + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; | ||
PyObject *__clinic_args = NULL; | ||
PyObject *const *__clinic_args = NULL; | ||
int b = 0; | ||
PyObject *c = " "; | ||
|
||
args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, 0, argsbuf); | ||
args = _PyArg_UnpackKeywordsWithVarargFast(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, 0, varargssize, argsbuf); | ||
if (!args) { | ||
goto exit; | ||
} | ||
__clinic_args = args[0]; | ||
__clinic_args = (PyObject *const *)args[0]; | ||
if (!noptargs) { | ||
goto skip_optional_kwonly; | ||
} | ||
|
@@ -3513,14 +3520,14 @@ test_vararg_with_only_defaults(PyObject *module, PyObject *const *args, Py_ssize | |
} | ||
c = args[2]; | ||
skip_optional_kwonly: | ||
return_value = test_vararg_with_only_defaults_impl(module, __clinic_args, b, c); | ||
return_value = test_vararg_with_only_defaults_impl(module, varargssize, __clinic_args, b, c); | ||
|
||
exit: | ||
Py_XDECREF(__clinic_args); | ||
return return_value; | ||
} | ||
|
||
static PyObject * | ||
test_vararg_with_only_defaults_impl(PyObject *module, PyObject *args, int b, | ||
test_vararg_with_only_defaults_impl(PyObject *module, Py_ssize_t varargssize, | ||
PyObject *const *args, int b, | ||
PyObject *c) | ||
/*[clinic end generated code: output=dc29ce6ebc2ec10c input=fa56a709a035666e]*/ | ||
/*[clinic end generated code: output=833c72a533c80a0e input=fa56a709a035666e]*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Avoid creating temporary varargs tuple in argument passing with "Argument Clinic generated code". |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems suspicious -- isn't __clinic_args a pointer-to-PyObject-pointer, not a pointer-to-tuple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My fault. The tuple doesn't need to be created.