diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2019-08-25 02:10:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-25 02:10:39 (GMT) |
commit | aef9ad82f7f667cd001a7112d3bc636e918626f7 (patch) | |
tree | 71bc842de3236a77c6084e951ecf6061693705c0 /Tools | |
parent | 805f8f9afea116c5d4d000570e3d02ae84502f43 (diff) | |
download | cpython-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-x | Tools/clinic/clinic.py | 24 |
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) |