Skip to content

Commit

Permalink
bpo-37942: Improve argument clinic float converter (pythonGH-15470)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettinger authored Aug 25, 2019
1 parent 805f8f9 commit aef9ad8
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 112 deletions.
28 changes: 20 additions & 8 deletions Lib/test/clinic.test
Original file line number Diff line number Diff line change
Expand Up @@ -1587,9 +1587,15 @@ test_float_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
if (nargs < 1) {
goto skip_optional;
}
a = (float) PyFloat_AsDouble(args[0]);
if (PyErr_Occurred()) {
goto exit;
if (PyFloat_CheckExact(args[0])) {
a = (float) (PyFloat_AS_DOUBLE(args[0]));
}
else
{
a = (float) PyFloat_AsDouble(args[0]);
if (a == -1.0 && PyErr_Occurred()) {
goto exit;
}
}
skip_optional:
return_value = test_float_converter_impl(module, a);
Expand All @@ -1600,7 +1606,7 @@ exit:

static PyObject *
test_float_converter_impl(PyObject *module, float a)
/*[clinic end generated code: output=8293566b2ec1fc52 input=259c0d98eca35034]*/
/*[clinic end generated code: output=6b9c7443d2601cea input=259c0d98eca35034]*/


/*[clinic input]
Expand Down Expand Up @@ -1634,9 +1640,15 @@ test_double_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
if (nargs < 1) {
goto skip_optional;
}
a = PyFloat_AsDouble(args[0]);
if (PyErr_Occurred()) {
goto exit;
if (PyFloat_CheckExact(args[0])) {
a = PyFloat_AS_DOUBLE(args[0]);
}
else
{
a = PyFloat_AsDouble(args[0]);
if (a == -1.0 && PyErr_Occurred()) {
goto exit;
}
}
skip_optional:
return_value = test_double_converter_impl(module, a);
Expand All @@ -1647,7 +1659,7 @@ exit:

static PyObject *
test_double_converter_impl(PyObject *module, double a)
/*[clinic end generated code: output=487081a9b8da67ab input=c6a9945706a41c27]*/
/*[clinic end generated code: output=5b7b9a0f0791b2cc input=c6a9945706a41c27]*/


/*[clinic input]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve ArgumentClinic converter for floats.
14 changes: 10 additions & 4 deletions Modules/clinic/_ssl.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 28 additions & 10 deletions Modules/clinic/_statisticsmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 46 additions & 16 deletions Modules/clinic/audioop.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 37 additions & 13 deletions Modules/clinic/cmathmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit aef9ad8

Please sign in to comment.