As reported in https://bugs.launchpad.net/bugs/1818953 POSIX::mblen()
is broken on threaded perls with glibc.
% perl -MPOSIX=mblen -e 'mblen("a", 1)'
perl: mbrtowc.c:105: __mbrtowc: Assertion `__mbsinit (data.__statep)' failed.
zsh: abort (core dumped) perl -MPOSIX=mblen -e 'mblen("a", 1)'
This broke in v5.27.8-134-g6c9ff7e96e which made the function
use mbrlen(3) under the hood on threaded perls.
The problem is initialization of the shift state with
mbrlen(NULL, 0, &ps));
The glibc documentation for mbrlen(3) at
https://www.gnu.org/software/libc/manual/html_node/Converting-a-Character.html#Converting-a-Character
does not mention initialization by passing in a null pointer for the
string, only a pointer to a NUL wide character.
If the next multibyte character corresponds to the NUL wide character,
the return value is 0. If the next n bytes form a valid multibyte
character, the number of bytes belonging to this multibyte character
byte sequence is returned.
Use memset(3) instead for mbstate_t initialization, as suggested in
https://www.gnu.org/software/libc/manual/html_node/Keeping-the-state.html
with the hope that this is more portable.
While at it, add a few basic test cases. These are in a new file because
they need fresh_perl_is() from test.pl while the existing ones use
Test::More (and conversion of at least posix.t looks way too involved.)
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1818953