mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
bpo-37942: Improve argument clinic float converter (GH-15470)
This commit is contained in:
parent
805f8f9afe
commit
aef9ad82f7
10 changed files with 317 additions and 112 deletions
14
Python/clinic/sysmodule.c.h
generated
14
Python/clinic/sysmodule.c.h
generated
|
@ -306,9 +306,15 @@ sys_setswitchinterval(PyObject *module, PyObject *arg)
|
|||
PyObject *return_value = NULL;
|
||||
double interval;
|
||||
|
||||
interval = PyFloat_AsDouble(arg);
|
||||
if (PyErr_Occurred()) {
|
||||
goto exit;
|
||||
if (PyFloat_CheckExact(arg)) {
|
||||
interval = PyFloat_AS_DOUBLE(arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
interval = PyFloat_AsDouble(arg);
|
||||
if (interval == -1.0 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
return_value = sys_setswitchinterval_impl(module, interval);
|
||||
|
||||
|
@ -989,4 +995,4 @@ sys_getandroidapilevel(PyObject *module, PyObject *Py_UNUSED(ignored))
|
|||
#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
|
||||
#define SYS_GETANDROIDAPILEVEL_METHODDEF
|
||||
#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
|
||||
/*[clinic end generated code: output=acef77d2bb8f6da9 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=b26faa0abdd700da input=a9049054013a1b77]*/
|
||||
|
|
|
@ -887,7 +887,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
|||
case 'f': {/* float */
|
||||
float *p = va_arg(*p_va, float *);
|
||||
double dval = PyFloat_AsDouble(arg);
|
||||
if (PyErr_Occurred())
|
||||
if (dval == -1.0 && PyErr_Occurred())
|
||||
RETURN_ERR_OCCURRED;
|
||||
else
|
||||
*p = (float) dval;
|
||||
|
@ -897,7 +897,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
|||
case 'd': {/* double */
|
||||
double *p = va_arg(*p_va, double *);
|
||||
double dval = PyFloat_AsDouble(arg);
|
||||
if (PyErr_Occurred())
|
||||
if (dval == -1.0 && PyErr_Occurred())
|
||||
RETURN_ERR_OCCURRED;
|
||||
else
|
||||
*p = dval;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue