Skip to content

gh-69573: Check return value of msvcrt_putch and msvcrt_putwch - #155956

Closed
imabd645 wants to merge 2 commits into
python:mainfrom
imabd645:fix-msvcrt-putch-69573
Closed

gh-69573: Check return value of msvcrt_putch and msvcrt_putwch#155956
imabd645 wants to merge 2 commits into
python:mainfrom
imabd645:fix-msvcrt-putch-69573

Conversation

@imabd645

@imabd645 imabd645 commented Aug 17, 2026

Copy link
Copy Markdown

Description

This PR fixes a longstanding bug in the msvcrt module where the return values of the underlying Windows _putch and _putwch functions were ignored.

According to the Windows C Runtime documentation, these functions return EOF (or WEOF) when an error occurs (such as when the console is unattached or output is redirected improperly). Because the Python wrappers (msvcrt.putch and msvcrt.putwch) previously returned None unconditionally, these errors were silently swallowed.

Changes:

  • Added a check for EOF in msvcrt_putch_impl.
  • Added a check for WEOF in msvcrt_putwch_impl.
  • If an error is detected, they now correctly raise an OSError via PyErr_SetFromErrno(PyExc_OSError).
  • Added the corresponding NEWS blurb.

@aisk

aisk commented Aug 17, 2026

Copy link
Copy Markdown
Member

It looks like only a NEWS entry file was added. Did something go wrong with your Git operations?

@aisk

aisk commented Aug 17, 2026

Copy link
Copy Markdown
Member

It looks like this issue was already addressed by #154364, so this PR duplicates that work. I'll close this PR along with the original issue. Thank you for your contribution!

@aisk aisk closed this Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants