mirror of https://github.com/python/cpython
gh-116714: Handle errors correctly in `PyFloat_GetInfo` (#116715)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
aa7bcf284f
commit
fcd49b4f47
|
@ -98,10 +98,18 @@ PyFloat_GetInfo(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SetIntFlag(flag) \
|
#define SetFlag(CALL) \
|
||||||
PyStructSequence_SET_ITEM(floatinfo, pos++, PyLong_FromLong(flag))
|
do { \
|
||||||
#define SetDblFlag(flag) \
|
PyObject *flag = (CALL); \
|
||||||
PyStructSequence_SET_ITEM(floatinfo, pos++, PyFloat_FromDouble(flag))
|
if (flag == NULL) { \
|
||||||
|
Py_CLEAR(floatinfo); \
|
||||||
|
return NULL; \
|
||||||
|
} \
|
||||||
|
PyStructSequence_SET_ITEM(floatinfo, pos++, flag); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define SetIntFlag(FLAG) SetFlag(PyLong_FromLong((FLAG)))
|
||||||
|
#define SetDblFlag(FLAG) SetFlag(PyFloat_FromDouble((FLAG)))
|
||||||
|
|
||||||
SetDblFlag(DBL_MAX);
|
SetDblFlag(DBL_MAX);
|
||||||
SetIntFlag(DBL_MAX_EXP);
|
SetIntFlag(DBL_MAX_EXP);
|
||||||
|
@ -116,11 +124,8 @@ PyFloat_GetInfo(void)
|
||||||
SetIntFlag(FLT_ROUNDS);
|
SetIntFlag(FLT_ROUNDS);
|
||||||
#undef SetIntFlag
|
#undef SetIntFlag
|
||||||
#undef SetDblFlag
|
#undef SetDblFlag
|
||||||
|
#undef SetFlag
|
||||||
|
|
||||||
if (PyErr_Occurred()) {
|
|
||||||
Py_CLEAR(floatinfo);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return floatinfo;
|
return floatinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue