mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
gh-116520: Fix error handling in os_get_terminal_size_impl in posixmodule (#116521)
This commit is contained in:
parent
03f86b1b62
commit
b4b4e764a7
1 changed files with 17 additions and 6 deletions
|
|
@ -14981,12 +14981,23 @@ os_get_terminal_size_impl(PyObject *module, int fd)
|
||||||
termsize = PyStructSequence_New((PyTypeObject *)TerminalSizeType);
|
termsize = PyStructSequence_New((PyTypeObject *)TerminalSizeType);
|
||||||
if (termsize == NULL)
|
if (termsize == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
PyStructSequence_SET_ITEM(termsize, 0, PyLong_FromLong(columns));
|
|
||||||
PyStructSequence_SET_ITEM(termsize, 1, PyLong_FromLong(lines));
|
int pos = 0;
|
||||||
if (PyErr_Occurred()) {
|
|
||||||
Py_DECREF(termsize);
|
#define SET_TERMSIZE(CALL) \
|
||||||
return NULL;
|
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;
|
return termsize;
|
||||||
}
|
}
|
||||||
#endif /* defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) */
|
#endif /* defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue