[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 b4b4e764a7)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2024-03-09 12:41:46 +01:00 committed by GitHub
parent b1c77ba1ce
commit f2898f89bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 6 deletions

View File

@ -13447,12 +13447,23 @@ os_get_terminal_size_impl(PyObject *module, int fd)
termsize = PyStructSequence_New((PyTypeObject *)TerminalSizeType);
if (termsize == NULL)
return NULL;
PyStructSequence_SET_ITEM(termsize, 0, PyLong_FromLong(columns));
PyStructSequence_SET_ITEM(termsize, 1, PyLong_FromLong(lines));
if (PyErr_Occurred()) {
Py_DECREF(termsize);
return NULL;
}
int pos = 0;
#define SET_TERMSIZE(CALL) \
do { \
PyObject *item = (CALL); \
if (item == NULL) { \
Py_DECREF(termsize); \
return NULL; \
} \
PyStructSequence_SET_ITEM(termsize, pos++, item); \
} while(0)
SET_TERMSIZE(PyLong_FromLong(columns));
SET_TERMSIZE(PyLong_FromLong(lines));
#undef SET_TERMSIZE
return termsize;
}
#endif /* defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) */