summaryrefslogtreecommitdiff
path: root/intrpvar.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-01-03 22:18:02 -0700
committerKarl Williamson <khw@cpan.org>2020-02-19 22:09:48 -0700
commit5a6637f01ac3edd837722b6d156ddb2250ea049f (patch)
treef6138a6fbd869dcd0a560fffcd31a0aca1321556 /intrpvar.h
parent63bebc1439c3a3eefd310e674f2593ff60cceca4 (diff)
downloadperl-5a6637f01ac3edd837722b6d156ddb2250ea049f.tar.gz
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.
Diffstat (limited to 'intrpvar.h')
-rw-r--r--intrpvar.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/intrpvar.h b/intrpvar.h
index 39bc99d898..64e581ab88 100644
--- a/intrpvar.h
+++ b/intrpvar.h
@@ -941,6 +941,12 @@ PERLVAR(I, Private_Use, SV *)
#ifdef HAS_MBRLEN
PERLVAR(I, mbrlen_ps, mbstate_t)
#endif
+#ifdef HAS_MBRTOWC
+PERLVAR(I, mbrtowc_ps, mbstate_t)
+#endif
+#ifdef HAS_WCRTOMB
+PERLVAR(I, wcrtomb_ps, mbstate_t)
+#endif
/* If you are adding a U8 or U16, check to see if there are 'Space' comments
* above on where there are gaps which currently will be structure padding. */