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 /Modules/clinic/cmathmodule.c.h | |
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 'Modules/clinic/cmathmodule.c.h')
-rw-r--r-- | Modules/clinic/cmathmodule.c.h | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/Modules/clinic/cmathmodule.c.h b/Modules/clinic/cmathmodule.c.h index 83c498c..3350987 100644 --- a/Modules/clinic/cmathmodule.c.h +++ b/Modules/clinic/cmathmodule.c.h @@ -766,13 +766,25 @@ cmath_rect(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("rect", nargs, 2, 2)) { goto exit; } - r = PyFloat_AsDouble(args[0]); - if (PyErr_Occurred()) { - goto exit; + if (PyFloat_CheckExact(args[0])) { + r = PyFloat_AS_DOUBLE(args[0]); } - phi = PyFloat_AsDouble(args[1]); - if (PyErr_Occurred()) { - goto exit; + else + { + r = PyFloat_AsDouble(args[0]); + if (r == -1.0 && PyErr_Occurred()) { + goto exit; + } + } + if (PyFloat_CheckExact(args[1])) { + phi = PyFloat_AS_DOUBLE(args[1]); + } + else + { + phi = PyFloat_AsDouble(args[1]); + if (phi == -1.0 && PyErr_Occurred()) { + goto exit; + } } return_value = cmath_rect_impl(module, r, phi); @@ -922,17 +934,29 @@ cmath_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec goto skip_optional_kwonly; } if (args[2]) { - rel_tol = PyFloat_AsDouble(args[2]); - if (PyErr_Occurred()) { - goto exit; + if (PyFloat_CheckExact(args[2])) { + rel_tol = PyFloat_AS_DOUBLE(args[2]); + } + else + { + rel_tol = PyFloat_AsDouble(args[2]); + if (rel_tol == -1.0 && PyErr_Occurred()) { + goto exit; + } } if (!--noptargs) { goto skip_optional_kwonly; } } - abs_tol = PyFloat_AsDouble(args[3]); - if (PyErr_Occurred()) { - goto exit; + if (PyFloat_CheckExact(args[3])) { + abs_tol = PyFloat_AS_DOUBLE(args[3]); + } + else + { + abs_tol = PyFloat_AsDouble(args[3]); + if (abs_tol == -1.0 && PyErr_Occurred()) { + goto exit; + } } skip_optional_kwonly: _return_value = cmath_isclose_impl(module, a, b, rel_tol, abs_tol); @@ -944,4 +968,4 @@ skip_optional_kwonly: exit: return return_value; } -/*[clinic end generated code: output=c7afb866e593fa45 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3ab228947d1709cc input=a9049054013a1b77]*/ |