Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aef9ad8

Browse files
authored
bpo-37942: Improve argument clinic float converter (GH-15470)
1 parent 805f8f9 commit aef9ad8

File tree

10 files changed

+317
-112
lines changed

10 files changed

+317
-112
lines changed

Lib/test/clinic.test

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,9 +1587,15 @@ test_float_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
15871587
if (nargs < 1) {
15881588
goto skip_optional;
15891589
}
1590-
a = (float) PyFloat_AsDouble(args[0]);
1591-
if (PyErr_Occurred()) {
1592-
goto exit;
1590+
if (PyFloat_CheckExact(args[0])) {
1591+
a = (float) (PyFloat_AS_DOUBLE(args[0]));
1592+
}
1593+
else
1594+
{
1595+
a = (float) PyFloat_AsDouble(args[0]);
1596+
if (a == -1.0 && PyErr_Occurred()) {
1597+
goto exit;
1598+
}
15931599
}
15941600
skip_optional:
15951601
return_value = test_float_converter_impl(module, a);
@@ -1600,7 +1606,7 @@ exit:
16001606

16011607
static PyObject *
16021608
test_float_converter_impl(PyObject *module, float a)
1603-
/*[clinic end generated code: output=8293566b2ec1fc52 input=259c0d98eca35034]*/
1609+
/*[clinic end generated code: output=6b9c7443d2601cea input=259c0d98eca35034]*/
16041610

16051611

16061612
/*[clinic input]
@@ -1634,9 +1640,15 @@ test_double_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
16341640
if (nargs < 1) {
16351641
goto skip_optional;
16361642
}
1637-
a = PyFloat_AsDouble(args[0]);
1638-
if (PyErr_Occurred()) {
1639-
goto exit;
1643+
if (PyFloat_CheckExact(args[0])) {
1644+
a = PyFloat_AS_DOUBLE(args[0]);
1645+
}
1646+
else
1647+
{
1648+
a = PyFloat_AsDouble(args[0]);
1649+
if (a == -1.0 && PyErr_Occurred()) {
1650+
goto exit;
1651+
}
16401652
}
16411653
skip_optional:
16421654
return_value = test_double_converter_impl(module, a);
@@ -1647,7 +1659,7 @@ exit:
16471659

16481660
static PyObject *
16491661
test_double_converter_impl(PyObject *module, double a)
1650-
/*[clinic end generated code: output=487081a9b8da67ab input=c6a9945706a41c27]*/
1662+
/*[clinic end generated code: output=5b7b9a0f0791b2cc input=c6a9945706a41c27]*/
16511663

16521664

16531665
/*[clinic input]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve ArgumentClinic converter for floats.

Modules/clinic/_ssl.c.h

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/_statisticsmodule.c.h

Lines changed: 28 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/audioop.c.h

Lines changed: 46 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/cmathmodule.c.h

Lines changed: 37 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)