Skip to content

Commit

Permalink
Recreate stdscr in case of errors in _curses_resize_term_impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
devdanzin committed Aug 6, 2024
1 parent b57e1e9 commit cb8a963
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3269,15 +3269,7 @@ _curses_initscr_impl(PyObject *module)
PyCursesWindowObject *winobj;

if (initialised) {
if (stdscr != NULL) {
wrefresh(stdscr);
} else {
stdscr = initscr();
if (stdscr == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
}
wrefresh(stdscr);
return (PyObject *)PyCursesWindow_New(stdscr, NULL);
}

Expand Down Expand Up @@ -4115,11 +4107,19 @@ _curses_resizeterm_impl(PyObject *module, int nlines, int ncols)

result = PyCursesCheckERR(resizeterm(nlines, ncols), "resizeterm");
if (!result) {
initialised = FALSE;
stdscr = initscr();
if (stdscr == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
return NULL;
}
if (!update_lines_cols()) {
initialised = FALSE;
stdscr = initscr();
if (stdscr == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
Py_DECREF(result);
return NULL;
}
Expand Down Expand Up @@ -4157,11 +4157,19 @@ _curses_resize_term_impl(PyObject *module, int nlines, int ncols)

result = PyCursesCheckERR(resize_term(nlines, ncols), "resize_term");
if (!result) {
initialised = FALSE;
stdscr = initscr();
if (stdscr == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
return NULL;
}
if (!update_lines_cols()) {
initialised = FALSE;
stdscr = initscr();
if (stdscr == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
Py_DECREF(result);
return NULL;
}
Expand Down

0 comments on commit cb8a963

Please sign in to comment.