summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-08-25 02:10:39 (GMT)
committerGitHub <noreply@github.com>2019-08-25 02:10:39 (GMT)
commitaef9ad82f7f667cd001a7112d3bc636e918626f7 (patch)
tree71bc842de3236a77c6084e951ecf6061693705c0 /Tools
parent805f8f9afea116c5d4d000570e3d02ae84502f43 (diff)
downloadcpython-aef9ad82f7f667cd001a7112d3bc636e918626f7.zip
cpython-aef9ad82f7f667cd001a7112d3bc636e918626f7.tar.gz
cpython-aef9ad82f7f667cd001a7112d3bc636e918626f7.tar.bz2
bpo-37942: Improve argument clinic float converter (GH-15470)
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/clinic/clinic.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 9880b39..d5863a3 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -3106,9 +3106,15 @@ class float_converter(CConverter):
def parse_arg(self, argname, argnum):
if self.format_unit == 'f':
return """
- {paramname} = (float) PyFloat_AsDouble({argname});
- if (PyErr_Occurred()) {{{{
- goto exit;
+ if (PyFloat_CheckExact({argname})) {{{{
+ {paramname} = (float) (PyFloat_AS_DOUBLE({argname}));
+ }}}}
+ else
+ {{{{
+ {paramname} = (float) PyFloat_AsDouble({argname});
+ if ({paramname} == -1.0 && PyErr_Occurred()) {{{{
+ goto exit;
+ }}}}
}}}}
""".format(argname=argname, paramname=self.name)
return super().parse_arg(argname, argnum)
@@ -3122,9 +3128,15 @@ class double_converter(CConverter):
def parse_arg(self, argname, argnum):
if self.format_unit == 'd':
return """
- {paramname} = PyFloat_AsDouble({argname});
- if (PyErr_Occurred()) {{{{
- goto exit;
+ if (PyFloat_CheckExact({argname})) {{{{
+ {paramname} = PyFloat_AS_DOUBLE({argname});
+ }}}}
+ else
+ {{{{
+ {paramname} = PyFloat_AsDouble({argname});
+ if ({paramname} == -1.0 && PyErr_Occurred()) {{{{
+ goto exit;
+ }}}}
}}}}
""".format(argname=argname, paramname=self.name)
return super().parse_arg(argname, argnum)