8000 [3.11] gh-116520: Fix error handling in `os_get_terminal_size_impl` i… · python/cpython@f2898f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2898f8

Browse files
[3.11] gh-116520: Fix error handling in os_get_terminal_size_impl in posixmodule (GH-116521) (#116540)
gh-116520: Fix error handling in `os_get_terminal_size_impl` in `posixmodule` (GH-116521) (cherry picked from commit b4b4e76) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent b1c77ba commit f2898f8

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Modules/posixmodule.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13447,12 +13447,23 @@ os_get_terminal_size_impl(PyObject *module, int fd)
1344713447
termsize = PyStructSequence_New((PyTypeObject *)TerminalSizeType);
1344813448
if (termsize == NULL)
1344913449
return NULL;
13450-
PyStructSequence_SET_ITEM(termsize, 0, PyLong_FromLong(columns));
13451-
PyStructSequence_SET_ITEM(termsize, 1, PyLong_FromLong(lines));
13452-
if (PyErr_Occurred()) {
13453-
Py_DECREF(termsize);
13454-
return NULL;
13455-
}
13450+
13451+
int pos = 0;
13452+
13453+
#define SET_TERMSIZE(CALL) \
13454+
do { \
13455+
PyObject *item = (CALL); \
13456+
if (item == NULL) { \
13457+
Py_DECREF(termsize); \
13458+
return NULL; \
13459+
} \
13460+
PyStructSequence_SET_ITEM(termsize, pos++, item); \
13461+
} while(0)
13462+
13463+
SET_TERMSIZE(PyLong_FromLong(columns));
13464+
SET_TERMSIZE(PyLong_FromLong(lines));
13465+
#undef SET_TERMSIZE
13466+
1345613467
return termsize;
1345713468
}
1345813469
#endif /* defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) */

0 commit comments

Comments
 (0)
0