10000 gh-134210: handle signals in `_curses.window.getch` by picnixz · Pull Request #134326 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-134210: handle signals in _curses.window.getch #134326

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

Merged
merged 6 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
handle input errors in getch, get_wch and getkey
  • Loading branch information
picnixz committed May 20, 2025
commit 81056a3ce8dc05937738e60ed84b48fe44b0bb18
33 changes: 14 additions & 19 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ curses_check_signals_on_input_error(PyCursesWindowObject *self,
}

/*[clinic input]
_curses.window.getch -> int
_curses.window.getch

[
y: int
Expand All @@ -1690,10 +1690,10 @@ keypad keys and so on return numbers higher than 256. In no-delay mode, -1
is returned if there is no input, else getch() waits until a key is pressed.
[clinic start generated code]*/

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

Expand All @@ -1706,7 +1706,12 @@ _curses_window_getch_impl(PyCursesWindowObject *self, int group_right_1,
}
Py_END_ALLOW_THREADS

return rtn;
if (rtn == ERR) {
/* wgetch() returns ERR in nodelay mode */
const char *funcname = group_right_1 ? "mvwgetch" : "wgetch";
return curses_check_signals_on_input_error(self, funcname, "getch");
}
return PyLong_FromLong(rtn);
}

/*[clinic input]
Expand Down Expand Up @@ -1744,14 +1749,9 @@ _curses_window_getkey_impl(PyCursesWindowObject *self, int group_right_1,
Py_END_ALLOW_THREADS

if (rtn == ERR) {
/* getch() returns ERR in nodelay mode */
PyErr_CheckSignals();
if (!PyErr_Occurred()) {
cursesmodule_state *state = get_cursesmodule_state_by_win(self);
const char *funcname = group_right_1 ? "mvwgetch" : "wgetch";
PyErr_Format(state->error, "getkey(): %s(): no input", funcname);
}
return NULL;
/* wgetch() returns ERR in nodelay mode */
const char *funcname = group_right_1 ? "mvwgetch" : "wgetch";
return curses_check_signals_on_input_error(self, funcname, "getkey");
} else if (rtn <= 255) {
#ifdef NCURSES_VERSION_MAJOR
#if NCURSES_VERSION_MAJOR*100+NCURSES_VERSION_MINOR <= 507
Expand Down Expand Up @@ -1804,14 +1804,9 @@ _curses_window_get_wch_impl(PyCursesWindowObject *self, int group_right_1,
Py_END_ALLOW_THREADS

if (ct == ERR) {
if (PyErr_CheckSignals())
return NULL;

/* get_wch() returns ERR in nodelay mode */
cursesmodule_state *state = get_cursesmodule_state_by_win(self);
/* wget_wch() returns ERR in nodelay mode */
const char *funcname = group_right_1 ? "mvwget_wch" : "wget_wch";
PyErr_Format(state->error, "get_wch(): %s(): no input", funcname);
return NULL;
return curses_check_signals_on_input_error(self, funcname, "get_wch");
}
if (ct == KEY_CODE_YES)
return PyLong_FromLong(rtn);
Expand Down
11 changes: 3 additions & 8 deletions Modules/clinic/_cursesmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
0