8000 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
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
do not break stuff!
  • Loading branch information
picnixz committed May 20, 2025
commit b926e640a1b43ea286cb8d2a040b89d38360cccd
37 changes: 21 additions & 16 deletions Modules/_cursesmodule.c
8000
Original file line number Diff line number Diff line change
Expand Up @@ -1659,19 +1659,6 @@ _curses_window_getbkgd_impl(PyCursesWindowObject *self)
return (long) getbkgd(self->win);
}

static PyObject *
curses_check_signals_on_input_error(PyCursesWindowObject *self,
const char *curses_funcname,
const char *python_funcname)
{
if (!PyErr_CheckSignals() && !PyErr_Occurred()) {
cursesmodule_state *state = get_cursesmodule_state_by_win(self);
PyErr_Format(state->error, "%s() (called by %s()): no input",
curses_funcname, python_funcname);
}
return NULL;
}

/*[clinic input]
_curses.window.getch

Expand Down Expand Up @@ -1707,13 +1694,31 @@ _curses_window_getch_impl(PyCursesWindowObject *self, int group_right_1,
Py_END_ALLOW_THREADS

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");
// We suppress ERR returned by wgetch() in nodelay mode
// after we handled possible interruption signals.
if (PyErr_CheckSignals()) {
return NULL;
}
// ERR is an implementation detail, so to be on the safe side,
// we forcibly set the return value to -1 as documented above.
rtn = -1;
}
return PyLong_FromLong(rtn);
}

static PyObject *
curses_check_signals_on_input_error(PyCursesWindowObject *self,
const char *curses_funcname,
const char *python_funcname)
{
if (!PyErr_CheckSignals() && !PyErr_Occurred()) {
cursesmodule_state *state = get_cursesmodule_state_by_win(self);
PyErr_Format(state->error, "%s() (called by %s()): no input",
curses_funcname, python_funcname);
}
return NULL;
}

/*[clinic input]
_curses.window.getkey

Expand Down
Loading
0