8000 `_curses.window.getch` does not check for interruption signals as `_curses.window.{getkey,get_wch}` do · Issue #134210 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

_curses.window.getch does not check for interruption signals as _curses.window.{getkey,get_wch} do #134210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
picnixz opened this issue May 19, 2025 · 4 comments
Assignees
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@picnixz
Copy link
Member
picnixz commented May 19, 2025

Bug report

Bug description:

In _curses.window.{getkey,get_wch}, we are checking for possible interrupting signals and say:

In no-delay mode, an exception is raised if there is no input

However, in getch, we say:

In no-delay mode, -1 is returned if there is no input.

In particular, I think we should also check for signals and possibly raise an exception if PyErr_CheckSignals fails, and otherwise return -1 as documented. (note that getch returns ERR in no-delay mode, see https://linux.die.net/man/3/wgetch).

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

@picnixz picnixz self-assigned this May 19, 2025
@picnixz picnixz added type-bug An unexpected behavior, bug, or error extension-modules C modules in the Modules dir labels May 19, 2025
@zydtiger
Copy link

Hi! I think this fix should raise an error when PyErr_CheckSignals() failed. This is copied from the get_wch() no-delay code:

static int
_curses_window_getch_impl(PyCursesWindowObject *self, int group_right_1,
                          int y, int x)
/*[clinic end generated code: output=980aa6af0c0ca387 input=bb24ebfb379f991f]*/
{
    int rtn;

    Py_BEGIN_ALLOW_THREADS
    if (!group_right_1) {
        rtn = wgetch(self->win);
    }
    else {
        rtn = mvwgetch(self->win, y, x);
    }
    Py_END_ALLOW_THREADS

    /* getch() returns ERR in nodelay mode */
    if (PyErr_CheckSignals()) {
      cursesmodule_state *state = get_cursesmodule_state_by_win(self);
      const char *funcname = group_right_1 ? "mvwgetch" : "wgetch";
      PyErr_Format(state->error, "getch(): %s(): no input", funcname);
      return ERR;
    }

    return rtn;
}

@zydtiger
Copy link
zydtiger commented May 19, 2025

Another potential issue that I am seeing is a return type mismatch between getch and get_wch or getkey. Both of get_wch() and getkey() returns a PyObject *. Maybe we can change _curses_window_getch_impl to return a PyLong pointer similar to get_wch_impl and getkey_impl? This would make sure we are always dealing with the same return type.

@picnixz
Copy link
Member Author
picnixz commented May 19, 2025

It's not a mismatch. It's handled by Argument Clinic so it's fine.

@picnixz
Copy link
Member Author
picnixz commented May 19, 2025

But I'll probably handle it as part of the rest of the cleanup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
Status: No status
Development

No branches or pull requests

2 participants
0