Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

termios.tpsetattr does rewrite errors #110365

Closed
Assignees
sobolevn
Labels
extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error
@sobolevn

Description

@sobolevn

Bug report

This code is problematic:

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_tispeed= (speed_t)PyLong_AsLong(PyList_GetItem(term,4));
speed_tospeed= (speed_t)PyLong_AsLong(PyList_GetItem(term,5));
PyObject*cc=PyList_GetItem(term,6);
if (PyErr_Occurred()) {
returnNULL;
}

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:

>>>importtermios>>>termios.tcsetattr(0,0, [0,1,2,'3',4,5,6])Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>TypeError:'str'objectcannotbeinterpretedasaninteger>>>termios.tcsetattr(0,0, [object(),1,2,'3',4,5,6])Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>TypeError:'str'objectcannotbeinterpretedasaninteger

The second error should say:

>>>termios.tcsetattr(0,0, [object(),1,2,'3',4,5,6])Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>TypeError:'object'objectcannotbeinterpretedasaninteger

And while we are there we can also changePyList_GetItem toPyList_GET_ITEM, because:

  • term is known to be alist
  • the size ofterm is known to be 7
    See check
    if (!PyList_Check(term)||PyList_Size(term)!=7) {
    PyErr_SetString(PyExc_TypeError,
    "tcsetattr, arg 3: must be 7 element list");
    returnNULL;
    }
    before these lines.

The only problem is tests. I think thattermios is not tested that much in our suite. We don't even havetest_termios.py file. Should I add one?

Refs#110260

Linked PRs

Metadata

Metadata

Assignees

Labels

extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp