gh-154786: Fix crashes on a screen without a terminal - #154787
Open
serhiy-storchaka wants to merge 1 commit into
Open
gh-154786: Fix crashes on a screen without a terminal#154787serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
screen.use() makes its screen current for the callback, so a new_prescr() screen, which has no terminal, can be current without set_term(). Operations that need a terminal then crashed inside curses. Raise curses.error instead, checking that stdscr exists.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
screen.use()makes its screen current for the callback, by callinguse_screen(), so a screen made bynew_prescr()can be current without going throughset_term(). It has no terminal, and operations that need one crashed inside curses.Eleven window methods crashed --
refresh(),noutrefresh(),getch(),getkey(),get_wch(),getstr(),get_wstr(),echochar(),keypad(),idlok(),idcok()-- andnewwin()andnewpad()returned a window whosedelwin()failed. They were found by calling every window method and every module-level function inside such a callback; some crash only for some arguments,idlok(0)is harmless whileidlok(True)is not.The check is that
stdscrexists, which is true whichever way the screen became current. It is added toPyCursesStatefulInitialised(), so every module-level function that already requiredinitscr()requires a terminal too, and to the window methods that need one. Window methods that only touch the window's own memory, such asaddstr()orclearok(), are unchanged.pre.use(lambda s: curses.use_env(False))keeps working: affecting the state beforeinitscr()is what such a screen is for, and those functions are not gated.