This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fixup POSIX::mbtowc, wctomb
authorKarl Williamson <khw@cpan.org>
Sat, 4 Jan 2020 05:18:02 +0000 (22:18 -0700)
committerKarl Williamson <khw@cpan.org>
Thu, 20 Feb 2020 05:09:48 +0000 (22:09 -0700)
commit5a6637f01ac3edd837722b6d156ddb2250ea049f
treef6138a6fbd869dcd0a560fffcd31a0aca1321556
parent63bebc1439c3a3eefd310e674f2593ff60cceca4
Fixup POSIX::mbtowc, wctomb

This commit enhances these functions so that on threaded perls, they use
mbrtowc and wcrtomb when available, making them thread safe.  The
substitution isn't completely transparent, as no effort is made to hide
any differences in errno setting upon error.  And there may be slight
differences in edge case behavior on some platforms.

This commit also changes the behaviors so that they take a scalar
parameter instead of a char *, and this might be 'undef' or not be
forceable into a valid PV.  If not a PV, the functions initialize the
shift state.  Previously the shift state was always reinitialized with
every call, which meant these could not work on locales with shift
states.

In addition, there were several issues in mbtowc and wctomb that this
commit fixes.

mbtowc and wctomb, when used, are now run with a semaphore.  This avoids
races if called at the same time in another thread.

The returned wide character from mbtowc() could well have been garbage.

The final parameter to mbtowc is now optional, as passing an SV allows
us to determine the length without the need for an extra parameter.  It
is now used only to restrict the parsing of the string to shorter than
the actual length.

wctomb would segfault if the string parameter was shared or hadn't
been pre-allocated with a string of sufficient length to hold the
result.
embedvar.h
ext/POSIX/POSIX.xs
ext/POSIX/lib/POSIX.pod
ext/POSIX/t/mb.t
intrpvar.h
locale.c
pod/perldelta.pod
sv.c
t/porting/known_pod_issues.dat