| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
… a wide build
On a wide build, winch() returns the low 8 bits of the character's code
point with no locale conversion, so inch()/mvinch() disagreed with instr()
for a non-ASCII character of an 8-bit locale ('€' under ISO-8859-15 gave
0xAC instead of 0xA4). Re-encode the cell to its locale byte via wctob(),
as ncurses does for getbkgd().
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Documentation build overview2 files changed ± library/curses.html ± whatsnew/changelog.html |
Sorry, something went wrong.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
| if (curses_getcchar(cell, wstr, &attrs, &pair) == ERR | ||
| || wstr[0] == L'\0' || wstr[1] != L'\0') | ||
| { | ||
| return rtn; |
There was a problem hiding this comment.
You may report the error to the caller. Something like:
Detailsdiff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index 1e874d65bfc..e9d8bbbc5d0 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -779,7 +779,8 @@ curses_getcchar(const cchar_t *wcval, wchar_t *wstr, attr_t *attrs, int *pair)
when the character maps to exactly one byte, keeping the attribute and color
bits in RTN. A character with no single-byte form is left to winch(). */
static chtype
-curses_cell_locale_byte(chtype rtn, const cchar_t *cell)
+curses_cell_locale_byte(PyCursesWindowObject *self, chtype rtn,
+ const cchar_t *cell, const char *funcname)
{
wchar_t wstr[CCHARW_MAX + 1];
attr_t attrs;
@@ -787,13 +788,15 @@ curses_cell_locale_byte(chtype rtn, const cchar_t *cell)
if (curses_getcchar(cell, wstr, &attrs, &pair) == ERR
|| wstr[0] == L'\0' || wstr[1] != L'\0')
{
- return rtn;
+ curses_window_set_error(self, "curses_getcchar", funcname);
+ return (chtype)ERR;
}
/* wctob() mirrors ncurses' own _nc_to_char(): the single-byte form, or EOF
when the character has none in this locale. */
int byte = wctob(wstr[0]);
if (byte != EOF) {
rtn = (rtn & ~(chtype)A_CHARTEXT) | (unsigned char)byte;
+ assert(rtn != (chtype)ERR);
}
return rtn;
}
@@ -3638,7 +3641,10 @@ _curses_window_inch_impl(PyCursesWindowObject *self, int group_right_1,
if ((group_right_1 ? mvwin_wch(self->win, y, x, &cell)
: win_wch(self->win, &cell)) != ERR)
{
- rtn = curses_cell_locale_byte(rtn, &cell);
+ rtn = curses_cell_locale_byte(self, rtn, &cell, "inch");
+ if (rtn == (chtype)ERR) {
+ return NULL;
+ }
}
#endif
return PyLong_FromUnsignedLong(rtn);
Sorry, something went wrong.
There was a problem hiding this comment.
I do not know what is the good solution here. You still get correct attributes and color pair. getbkgd() returns default background (space) if background character cannot be encoded, but there is not good fallback for inch().
Sorry, something went wrong.
|
GH-154116 is a backport of this pull request to the 3.15 branch. |
Sorry, something went wrong.
…n a wide build (GH-153863) (GH-154116) On a wide build, winch() returns the low 8 bits of the character's code point with no locale conversion, so inch()/mvinch() disagreed with instr() for a non-ASCII character of an 8-bit locale ('€' under ISO-8859-15 gave 0xAC instead of 0xA4). Re-encode the cell to its locale byte via wctob(), as ncurses does for getbkgd(). (cherry picked from commit a83aaa9) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
|
GH-154151 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
|
GH-154153 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
…n a wide build (GH-153863) (GH-154153) On a wide build, winch() returns the low 8 bits of the character's code point with no locale conversion, so inch()/mvinch() disagreed with instr() for a non-ASCII character of an 8-bit locale ('€' under ISO-8859-15 gave 0xAC instead of 0xA4). Re-encode the cell to its locale byte via wctob(), as ncurses does for getbkgd(). (cherry picked from commit a83aaa9) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
…n a wide build (GH-153863) (GH-154151) On a wide build, winch() returns the low 8 bits of the character's code point with no locale conversion, so inch()/mvinch() disagreed with instr() for a non-ASCII character of an 8-bit locale ('€' under ISO-8859-15 gave 0xAC instead of 0xA4). Re-encode the cell to its locale byte via wctob(), as ncurses does for getbkgd(). (cherry picked from commit a83aaa9) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
| Back | FazBrowse Home | New Git URL |
On a wide (ncursesw) build, winch() returns the low 8 bits of the cell character's code point with no locale conversion, so window.inch() and window.mvinch() disagreed with instr() for a non-ASCII character representable in an 8-bit locale — e.g. € under ISO-8859-15 gave 0xAC instead of the locale byte 0xA4.
The fix re-encodes the cell to its locale byte via wctob() when the character has a single-byte form, keeping winch()'s value otherwise (combining cells and multibyte characters, which in_wch() reads in full). This mirrors the conversion ncurses itself performs for getbkgd() (_nc_to_char()), which is unaffected.
The underlying ncurses behavior was reported upstream and is considered documented, so it is worked around on the CPython side.