Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fc81b64

Browse filesBrowse files
miss-islingtonsobolevnserhiy-storchaka
authored
[3.12] gh-116714: Handle errors correctly in PyFloat_GetInfo (GH-116715) (#116722)
gh-116714: Handle errors correctly in `PyFloat_GetInfo` (GH-116715) (cherry picked from commit fcd49b4) Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 9caad1f commit fc81b64
Copy full SHA for fc81b64

File tree

Expand file treeCollapse file tree

1 file changed

+13
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-8
lines changed
Open diff view settings
Collapse file

‎Objects/floatobject.c‎

Copy file name to clipboardExpand all lines: Objects/floatobject.c
+13-8Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,18 @@ PyFloat_GetInfo(void)
101101
return NULL;
102102
}
103103

104-
#define SetIntFlag(flag) \
105-
PyStructSequence_SET_ITEM(floatinfo, pos++, PyLong_FromLong(flag))
106-
#define SetDblFlag(flag) \
107-
PyStructSequence_SET_ITEM(floatinfo, pos++, PyFloat_FromDouble(flag))
104+
#define SetFlag(CALL) \
105+
do { \
106+
PyObject *flag = (CALL); \
107+
if (flag == NULL) { \
108+
Py_CLEAR(floatinfo); \
109+
return NULL; \
110+
} \
111+
PyStructSequence_SET_ITEM(floatinfo, pos++, flag); \
112+
} while (0)
113+
114+
#define SetIntFlag(FLAG) SetFlag(PyLong_FromLong((FLAG)))
115+
#define SetDblFlag(FLAG) SetFlag(PyFloat_FromDouble((FLAG)))
108116

109117
SetDblFlag(DBL_MAX);
110118
SetIntFlag(DBL_MAX_EXP);
@@ -119,11 +127,8 @@ PyFloat_GetInfo(void)
119127
SetIntFlag(FLT_ROUNDS);
120128
#undef SetIntFlag
121129
#undef SetDblFlag
130+
#undef SetFlag
122131

123-
if (PyErr_Occurred()) {
124-
Py_CLEAR(floatinfo);
125-
return NULL;
126-
}
127132
return floatinfo;
128133
}
129134

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.