Skip to content

gh-153864: Fix curses window.insch() for non-ASCII characters on a wide build#153865

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:curses-insch-locale-decode
Open

gh-153864: Fix curses window.insch() for non-ASCII characters on a wide build#153865
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:curses-insch-locale-decode

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 17, 2026

Copy link
Copy Markdown
Member

On a wide (ncursesw) build, window.insch() and window.mvinsch() insert a non-ASCII int/bytes byte as its Latin-1 code point instead of decoding it through the window's encoding, unlike addch() — e.g. insch(0xA4) under ISO-8859-15 inserts ¤ (U+00A4) while addch(0xA4) inserts .

The cause is in ncurses: winsch() has a fast path for a printable 8-bit byte that stores it directly as a code point, bypassing the locale decode waddch() performs. The fix decodes the byte with btowc() (the inverse of inch()'s wctob()) and inserts it with wins_wch(); a byte with no single-byte form in the locale falls back to winsch().

The underlying ncurses behavior was reported upstream.

…n a wide build

On a wide build, winsch() does not locale-decode a byte above 127, unlike
waddch(), so insch() inserted '¤' (U+00A4) instead of '€' for byte 0xA4
under ISO-8859-15.  Decode the byte with btowc() and insert it as a wide
character, like addch().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread Modules/_cursesmodule.c
if (type == 1) {
/* winsch() does not locale-decode a byte above 127 on a wide build,
unlike waddch(), so decode it here and insert it as a wide
character. */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add gh-153864 reference to the comment.

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