summaryrefslogtreecommitdiffstats
path: root/Tools/clinic
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-03 21:12:11 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-03 21:12:11 (GMT)
commit92e8af67a89b204efedad3373c292c0b3c52072c (patch)
tree0e319cfdf2015aedc0e932c2a30ad71734aa0824 /Tools/clinic
parent1009bf18b38a8d36298575191dd8fdf43f8f9097 (diff)
downloadcpython-92e8af67a89b204efedad3373c292c0b3c52072c.zip
cpython-92e8af67a89b204efedad3373c292c0b3c52072c.tar.gz
cpython-92e8af67a89b204efedad3373c292c0b3c52072c.tar.bz2
Issue #23492: Argument Clinic now generates argument parsing code with
PyArg_Parse instead of PyArg_ParseTuple if possible.
Diffstat (limited to 'Tools/clinic')
-rwxr-xr-xTools/clinic/clinic.py50
1 files changed, 33 insertions, 17 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 7d81310..9623ab4 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -593,8 +593,6 @@ class CLanguage(Language):
meth_o = (len(parameters) == 1 and
parameters[0].kind == inspect.Parameter.POSITIONAL_ONLY and
not converters[0].is_optional() and
- isinstance(converters[0], object_converter) and
- converters[0].format_unit == 'O' and
not new_or_init)
# we have to set these things before we're done:
@@ -700,22 +698,40 @@ class CLanguage(Language):
elif meth_o:
flags = "METH_O"
- meth_o_prototype = normalize_snippet("""
- static PyObject *
- {c_basename}({impl_parameters})
- """)
+ if (isinstance(converters[0], object_converter) and
+ converters[0].format_unit == 'O'):
+ meth_o_prototype = normalize_snippet("""
+ static PyObject *
+ {c_basename}({impl_parameters})
+ """)
+
+ if default_return_converter:
+ # maps perfectly to METH_O, doesn't need a return converter.
+ # so we skip making a parse function
+ # and call directly into the impl function.
+ impl_prototype = parser_prototype = parser_definition = ''
+ impl_definition = meth_o_prototype
+ else:
+ # SLIGHT HACK
+ # use impl_parameters for the parser here!
+ parser_prototype = meth_o_prototype
+ parser_definition = parser_body(parser_prototype)
- if default_return_converter:
- # maps perfectly to METH_O, doesn't need a return converter.
- # so we skip making a parse function
- # and call directly into the impl function.
- impl_prototype = parser_prototype = parser_definition = ''
- impl_definition = meth_o_prototype
else:
- # SLIGHT HACK
- # use impl_parameters for the parser here!
- parser_prototype = meth_o_prototype
- parser_definition = parser_body(parser_prototype)
+ argname = 'arg'
+ if parameters[0].name == argname:
+ argname += '_'
+ parser_prototype = normalize_snippet("""
+ static PyObject *
+ {c_basename}({self_type}{self_name}, PyObject *%s)
+ """ % argname)
+
+ parser_definition = parser_body(parser_prototype, normalize_snippet("""
+ if (!PyArg_Parse(%s,
+ "{format_units}:{name}",
+ {parse_arguments}))
+ goto exit;
+ """ % argname, indent=4))
elif has_option_groups:
# positional parameters with option groups
@@ -1025,7 +1041,7 @@ class CLanguage(Language):
# METH_O, we have exactly one anyway, so we know exactly
# where it is.
if ("METH_O" in templates['methoddef_define'] and
- not default_return_converter):
+ '{impl_parameters}' in templates['parser_prototype']):
data.declarations.pop(0)
template_dict = {}