-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
This code is problematic:
Lines 215 to 224 in bf4bc36
mode.c_iflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 0)); | |
mode.c_oflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 1)); | |
mode.c_cflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 2)); | |
mode.c_lflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 3)); | |
speed_t ispeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 4)); | |
speed_t ospeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 5)); | |
PyObject *cc = PyList_GetItem(term, 6); | |
if (PyErr_Occurred()) { | |
return NULL; | |
} |
It does rewrite errors that happened before. Showing the last error, not the first one.
This goes against Python's semantics.
Here's the reproducer:
>>> import termios
>>> termios.tcsetattr(0, 0, [0, 1, 2, '3', 4, 5, 6])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object cannot be interpreted as an integer
>>> termios.tcsetattr(0, 0, [object(), 1, 2, '3', 4, 5, 6])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object cannot be interpreted as an integer
The second error should say:
>>> termios.tcsetattr(0, 0, [object(), 1, 2, '3', 4, 5, 6])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'object' object cannot be interpreted as an integer
And while we are there we can also change PyList_GetItem
to PyList_GET_ITEM
, because:
term
is known to be alist
- the size of
term
is known to be 7
See checkLines 197 to 201 in bf4bc36
if (!PyList_Check(term) || PyList_Size(term) != 7) { PyErr_SetString(PyExc_TypeError, "tcsetattr, arg 3: must be 7 element list"); return NULL; }
The only problem is tests. I think that termios
is not tested that much in our suite. We don't even have test_termios.py
file. Should I add one?
Refs #110260
Linked PRs
erlend-aasland
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error