summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2014-08-14 11:56:03 -0600
committerKarl Williamson <khw@cpan.org>2014-08-14 12:04:39 -0600
commit747c467a69dad4c76485fb6311c9645d3152d02a (patch)
tree1e6f06312ddbe789b94766c449d46704f85df7a2 /locale.c
parenta94ee3a1678e204b7e436950171bf0c28ea554f5 (diff)
downloadperl-747c467a69dad4c76485fb6311c9645d3152d02a.tar.gz
Add sync_locale()
This trivial function is to be used by XS code when it changes the program's locale. It hides the details from that code of what needs to be done, which could change in the future.
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/locale.c b/locale.c
index cfe15cbe7b..8f77885a6f 100644
--- a/locale.c
+++ b/locale.c
@@ -1558,6 +1558,41 @@ Perl_my_strerror(pTHX_ const int errnum) {
}
/*
+
+=head1 Locale-related functions and macros
+
+=for apidoc sync_locale
+
+Changing the program's locale should be avoided by XS code. Nevertheless,
+certain non-Perl libraries called from XS, such as C<Gtk> do so. When this
+happens, Perl needs to be told that the locale has changed. Use this function
+to do so, before returning to Perl.
+
+=cut
+*/
+
+void
+Perl_sync_locale(pTHX)
+{
+
+#ifdef USE_LOCALE_CTYPE
+ new_ctype(setlocale(LC_CTYPE, NULL));
+#endif /* USE_LOCALE_CTYPE */
+
+#ifdef USE_LOCALE_COLLATE
+ new_collate(setlocale(LC_COLLATE, NULL));
+#endif
+
+#ifdef USE_LOCALE_NUMERIC
+ set_numeric_local(); /* Switch from "C" to underlying LC_NUMERIC */
+ new_numeric(setlocale(LC_NUMERIC, NULL));
+#endif /* USE_LOCALE_NUMERIC */
+
+}
+
+
+
+/*
* Local variables:
* c-indentation-style: bsd
* c-basic-offset: 4