1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-01 05:16:05 +01:00

50081: reset global mbstate_t variables when LC_CTYPE changes

This commit is contained in:
Jun-ichi Takimoto 2022-04-20 21:06:53 +09:00
parent baa12a413f
commit 09ad15b986
3 changed files with 32 additions and 1 deletions

View file

@ -1,5 +1,8 @@
2022-04-20 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
* 50081: Src/pattern.c, Src/params.c: reset global mbstate_t
variables when LC_CTYPE changes
* 50080: Src/hist.c: add missing STOUC() in casemodify()
2022-04-19 Bart Schaefer <schaefer@zsh.org>

View file

@ -4594,6 +4594,19 @@ static struct localename {
{NULL, 0}
};
/* On some systems (at least on NetBSD-9), when LC_CTYPE changes,
* global variables (type mbstate_t) used by mbrtowc() etc. need be
* reset by clear_mbstate() */
/**/
static void
clear_mbstate(void) {
#ifdef MULTIBYTE_SUPPORT
mb_charinit(); /* utils.c */
clear_shiftstate(); /* pattern.c */
#endif
}
/**/
static void
setlang(char *x)
@ -4616,6 +4629,7 @@ setlang(char *x)
* that case.
*/
setlocale(LC_ALL, x ? unmeta(x) : "");
clear_mbstate();
queue_signals();
for (ln = lc_names; ln->name; ln++)
if ((x = getsparam_u(ln->name)) && *x)
@ -4641,8 +4655,10 @@ lc_allsetfn(Param pm, char *x)
unqueue_signals();
}
}
else
else {
setlocale(LC_ALL, unmeta(x));
clear_mbstate();
}
}
/**/
@ -4679,6 +4695,7 @@ lcsetfn(Param pm, char *x)
setlocale(ln->category, unmeta(x));
}
unqueue_signals();
clear_mbstate(); /* LC_CTYPE may have changed */
}
#endif /* USE_LOCALE */
@ -5627,6 +5644,7 @@ endparamscope(void)
setlocale(ln->category, val);
}
}
clear_mbstate(); /* LC_CTYPE may have changed */
}
#endif /* USE_LOCALE */
unqueue_signals();

View file

@ -320,6 +320,14 @@ typedef wint_t patint_t;
*/
static mbstate_t shiftstate;
/* See clear_mbstate() in params.c for the use of clear_shiftstate() */
/**/
mod_export void
clear_shiftstate(void) {
memset(&shiftstate, 0, sizeof(shiftstate));
}
/*
* Multibyte version: it's (almost) as easy to return the
* value as not, so do so since we sometimes need it..
@ -1999,6 +2007,8 @@ charsub(char *x, char *y)
if (ret == MB_INVALID || ret == MB_INCOMPLETE) {
/* Error. Treat remainder as single characters */
/* Reset the shift state for next time. */
memset(&shiftstate, 0, sizeof(shiftstate));
return res + (y - x);
}