[3.11] gh-116714: Handle errors correctly in `PyFloat_GetInfo` (GH-116715) (#116723)

gh-116714: Handle errors correctly in `PyFloat_GetInfo` (GH-116715)
(cherry picked from commit fcd49b4f47)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-03-13 14:40:30 +01:00 committed by GitHub
parent 1dcb46104f
commit bccd1f691f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 8 deletions

View File

@ -101,10 +101,18 @@ PyFloat_GetInfo(void)
return NULL;
}
#define SetIntFlag(flag) \
PyStructSequence_SET_ITEM(floatinfo, pos++, PyLong_FromLong(flag))
#define SetDblFlag(flag) \
PyStructSequence_SET_ITEM(floatinfo, pos++, PyFloat_FromDouble(flag))
#define SetFlag(CALL) \
do { \
PyObject *flag = (CALL); \
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);
SetIntFlag(DBL_MAX_EXP);
@ -119,11 +127,8 @@ PyFloat_GetInfo(void)
SetIntFlag(FLT_ROUNDS);
#undef SetIntFlag
#undef SetDblFlag
#undef SetFlag
if (PyErr_Occurred()) {
Py_CLEAR(floatinfo);
return NULL;
}
return floatinfo;
}