Skip to content

Commit b926e64

Browse files
committed
do not break stuff!
1 parent 81056a3 commit b926e64

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

Modules/_cursesmodule.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,19 +1659,6 @@ _curses_window_getbkgd_impl(PyCursesWindowObject *self)
16591659
return (long) getbkgd(self->win);
16601660
}
16611661

1662-
static PyObject *
1663-
curses_check_signals_on_input_error(PyCursesWindowObject *self,
1664-
const char *curses_funcname,
1665-
const char *python_funcname)
1666-
{
1667-
if (!PyErr_CheckSignals() && !PyErr_Occurred()) {
1668-
cursesmodule_state *state = get_cursesmodule_state_by_win(self);
1669-
PyErr_Format(state->error, "%s() (called by %s()): no input",
1670-
curses_funcname, python_funcname);
1671-
}
1672-
return NULL;
1673-
}
1674-
16751662
/*[clinic input]
16761663
_curses.window.getch
16771664
@@ -1707,13 +1694,31 @@ _curses_window_getch_impl(PyCursesWindowObject *self, int group_right_1,
17071694
Py_END_ALLOW_THREADS
17081695

17091696
if (rtn == ERR) {
1710-
/* wgetch() returns ERR in nodelay mode */
1711-
const char *funcname = group_right_1 ? "mvwgetch" : "wgetch";
1712-
return curses_check_signals_on_input_error(self, funcname, "getch");
1697+
// We suppress ERR returned by wgetch() in nodelay mode
1698+
// after we handled possible interruption signals.
1699+
if (PyErr_CheckSignals()) {
1700+
return NULL;
1701+
}
1702+
// ERR is an implementation detail, so to be on the safe side,
1703+
// we forcibly set the return value to -1 as documented above.
1704+
rtn = -1;
17131705
}
17141706
return PyLong_FromLong(rtn);
17151707
}
17161708

1709+
static PyObject *
1710+
curses_check_signals_on_input_error(PyCursesWindowObject *self,
1711+
const char *curses_funcname,
1712+
const char *python_funcname)
1713+
{
1714+
if (!PyErr_CheckSignals() && !PyErr_Occurred()) {
1715+
cursesmodule_state *state = get_cursesmodule_state_by_win(self);
1716+
PyErr_Format(state->error, "%s() (called by %s()): no input",
1717+
curses_funcname, python_funcname);
1718+
}
1719+
return NULL;
1720+
}
1721+
17171722
/*[clinic input]
17181723
_curses.window.getkey
17191724

0 commit comments

Comments
 (0)