From 271403abe36069797ac332e1c6eae3473878db20 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 17 Jan 2017 01:29:01 +0100 Subject: Rename _PyArg_ParseStack to _PyArg_ParseStackAndKeywords Issue #29286. --- Tools/clinic/clinic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Tools/clinic/clinic.py') diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 75ac673737..4d84d4918e 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -856,7 +856,7 @@ class CLanguage(Language): parser_prototype = parser_prototype_fastcall body = normalize_snippet(""" - if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, + if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, {parse_arguments})) {{ goto exit; }} -- cgit v1.2.1 From aeb36518375e829b3f84f58775c6991bf4f92514 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 17 Jan 2017 01:42:54 +0100 Subject: Argument Clinic: Use METH_FASTCALL for positionals Issue #29286. Use METH_FASTCALL calling convention instead of METH_VARARGS to parse position arguments. METH_FASTCALL is faster since it avoids the creation of a temporary tuple to pass positional arguments. --- Tools/clinic/clinic.py | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'Tools/clinic/clinic.py') diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 4d84d4918e..7c4b388efe 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -705,14 +705,14 @@ class CLanguage(Language): {c_basename}({self_type}{self_name}, PyObject *args, PyObject *kwargs) """) - parser_prototype_fastcall = normalize_snippet(""" + parser_prototype_varargs = normalize_snippet(""" static PyObject * - {c_basename}({self_type}{self_name}, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) + {c_basename}({self_type}{self_name}, PyObject *args) """) - parser_prototype_varargs = normalize_snippet(""" + parser_prototype_fastcall = normalize_snippet(""" static PyObject * - {c_basename}({self_type}{self_name}, PyObject *args) + {c_basename}({self_type}{self_name}, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) """) # parser_body_fields remembers the fields passed in to the @@ -837,18 +837,36 @@ class CLanguage(Language): """, indent=4)) elif positional: - # positional-only, but no option groups - # we only need one call to PyArg_ParseTuple + if not new_or_init: + # positional-only, but no option groups + # we only need one call to _PyArg_ParseStack - flags = "METH_VARARGS" - parser_prototype = parser_prototype_varargs + flags = "METH_FASTCALL" + parser_prototype = parser_prototype_fastcall - parser_definition = parser_body(parser_prototype, normalize_snippet(""" - if (!PyArg_ParseTuple(args, "{format_units}:{name}", - {parse_arguments})) {{ - goto exit; - }} - """, indent=4)) + parser_definition = parser_body(parser_prototype, normalize_snippet(""" + if (!_PyArg_ParseStack(args, nargs, "{format_units}:{name}", + {parse_arguments})) {{ + goto exit; + }} + + if ({self_type_check}!_PyArg_NoStackKeywords("{name}", kwnames)) {{ + goto exit; + }} + """, indent=4)) + else: + # positional-only, but no option groups + # we only need one call to PyArg_ParseTuple + + flags = "METH_VARARGS" + parser_prototype = parser_prototype_varargs + + parser_definition = parser_body(parser_prototype, normalize_snippet(""" + if (!PyArg_ParseTuple(args, "{format_units}:{name}", + {parse_arguments})) {{ + goto exit; + }} + """, indent=4)) elif not new_or_init: flags = "METH_FASTCALL" -- cgit v1.2.1 From fb6c0453c94178df82be764dd66a8957e3b8b2b9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 17 Jan 2017 02:35:41 +0100 Subject: Argument Clinic: Use METH_FASTCALL for boring positionals Issue #29286. Use METH_FASTCALL calling convention instead of METH_VARARGS to parse "boring" position arguments. METH_FASTCALL is faster since it avoids the creation of a temporary tuple to pass positional arguments. Replace PyArg_UnpackTuple() with _PyArg_UnpackStack()+_PyArg_NoStackKeywords(). --- Tools/clinic/clinic.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'Tools/clinic/clinic.py') diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 7c4b388efe..894d1c5d99 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -825,16 +825,32 @@ class CLanguage(Language): # and nothing but normal objects: # PyArg_UnpackTuple! - flags = "METH_VARARGS" - parser_prototype = parser_prototype_varargs + if not new_or_init: + flags = "METH_FASTCALL" + parser_prototype = parser_prototype_fastcall - parser_definition = parser_body(parser_prototype, normalize_snippet(""" - if (!PyArg_UnpackTuple(args, "{name}", - {unpack_min}, {unpack_max}, - {parse_arguments})) {{ - goto exit; - }} - """, indent=4)) + parser_definition = parser_body(parser_prototype, normalize_snippet(""" + if (!_PyArg_UnpackStack(args, nargs, "{name}", + {unpack_min}, {unpack_max}, + {parse_arguments})) {{ + goto exit; + }} + + if ({self_type_check}!_PyArg_NoStackKeywords("{name}", kwnames)) {{ + goto exit; + }} + """, indent=4)) + else: + flags = "METH_VARARGS" + parser_prototype = parser_prototype_varargs + + parser_definition = parser_body(parser_prototype, normalize_snippet(""" + if (!PyArg_UnpackTuple(args, "{name}", + {unpack_min}, {unpack_max}, + {parse_arguments})) {{ + goto exit; + }} + """, indent=4)) elif positional: if not new_or_init: -- cgit v1.2.1