Skip to content

gh-153862: Fix spurious color pair in curses window.inch() on a wide build#154703

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:curses-inch-color
Jul 26, 2026
Merged

gh-153862: Fix spurious color pair in curses window.inch() on a wide build#154703
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:curses-inch-color

Conversation

@serhiy-storchaka

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

Copy link
Copy Markdown
Member

winch() returns the character's full code point, so inch()/mvinch() recovering the locale byte by replacing only its low 8 bits left a code point past 0xff leaking into the color-pair field. Under ISO-8859-15, inch() of '€' returned 0x20A4 (the byte 0xA4 plus a spurious color pair 32) instead of 0xA4.

Rebuild the value from the attributes and color pair that getcchar() reports separately.

The test asserted only inch() & A_CHARTEXT, masking the leaked bits; it now asserts the whole value.

… wide build

winch() returns the whole code point, so inch() replacing only its low
8 bits left the high bits in the color field.  Rebuild from
getcchar()'s attributes and color pair.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
On a wide build inch() derived its result from winch(), whose character
is the whole code point rather than a locale byte, so a code point past
0xff overflowed into the color field and past 0xffff into the attribute
bits.  Read the cell with win_wch() and build the chtype from the locale
byte plus the attributes and color pair reported by getcchar().  The
character is 0 when it has no single-byte form; win_wch() and getcchar()
failures now raise.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@serhiy-storchaka
serhiy-storchaka merged commit b618874 into python:main Jul 26, 2026
50 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@serhiy-storchaka
serhiy-storchaka deleted the curses-inch-color branch July 26, 2026 08:02
@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.15 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker b6188749d69e9609a83ee0d526013920da314ab2 3.15

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker b6188749d69e9609a83ee0d526013920da314ab2 3.14

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker b6188749d69e9609a83ee0d526013920da314ab2 3.13

@bedevere-app

bedevere-app Bot commented Jul 26, 2026

Copy link
Copy Markdown

GH-154720 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 26, 2026
serhiy-storchaka added a commit that referenced this pull request Jul 26, 2026
…a wide build (GH-154703) (GH-154720)

winch() returns the whole code point, so inch() replacing only its low
8 bits left the high bits in the color field.  Rebuild from
getcchar()'s attributes and color pair.

(cherry picked from commit b618874)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* gh-153862: Suggest instr() for non-encodable characters read by inch()

A character that does not fit in a single byte has a character byte of 0
in the value returned by inch(); document reading such characters with
instr().

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bedevere-app

bedevere-app Bot commented Jul 26, 2026

Copy link
Copy Markdown

GH-154732 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 26, 2026
@bedevere-app

bedevere-app Bot commented Jul 26, 2026

Copy link
Copy Markdown

GH-154733 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 26, 2026
serhiy-storchaka added a commit that referenced this pull request Jul 26, 2026
…a wide build (GH-154703) (GH-154733)

winch() returns the whole code point, so inch() replacing only its low
8 bits left the high bits in the color field.  Rebuild from
getcchar()'s attributes and color pair.

(cherry picked from commit b618874)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
serhiy-storchaka added a commit that referenced this pull request Jul 26, 2026
…a wide build (GH-154703) (GH-154732)

winch() returns the whole code point, so inch() replacing only its low
8 bits left the high bits in the color field.  Rebuild from
getcchar()'s attributes and color pair.

(cherry picked from commit b618874)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant