summaryrefslogtreecommitdiff
path: root/intrpvar.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2018-01-02 16:54:28 -0700
committerKarl Williamson <khw@cpan.org>2018-01-30 22:35:09 -0700
commit47280b208d546ec0bb8c3d14cf015fb8f2665f58 (patch)
tree2271dbf77eddce956fedb276a63ca99182a585c2 /intrpvar.h
parent50bf02bdec7e84f5ebd09f3f200e5939e80e4e19 (diff)
downloadperl-47280b208d546ec0bb8c3d14cf015fb8f2665f58.tar.gz
Cache locale UTF8-ness lookups
Some locales are UTF-8, some are not. Knowledge of this is needed in various circumstances. This commit saves the results of the last several lookups so they don't have to be recalculated each time. The full generality of POSIX locales is such that you can have error messages be displayed in one locale, say Spanish, while other things are in French. To accommodate this generality, the program can loop through all the locale categories finding the UTF8ness of the locale it points to. However, in almost all instances, people are going to be in either French or in Spanish, and not in some combination. Suppose it is a French UTF-8 locale for all categories. This new cache will know that the French locale is UTF-8, and the queries for all but the first category can return that immediately. This simple cache avoids the overhead of hashes. This also fixes a bug I realized exists in threaded perls, but haven't reproduced. We do not support locales in such perls, and the user must not change the locale or 'use locale'. But perl itself could change the locale behind the scenes, leading to segfaults or incorrect results. One such instance is the determination of UTF8ness. But this only could happen if the full generality of locales is used so that the categories are not all in the same locale. This could only happen (if the user doesn't change locales) if the environment is such that the perl program is started up so that the categories are in such a state. This commit fixes this potential bug by caching the UTF8ness of each category at startup, before any threads are instantiated, and so checking for it later just looks it up in the cache, without perl changing the locale.
Diffstat (limited to 'intrpvar.h')
-rw-r--r--intrpvar.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/intrpvar.h b/intrpvar.h
index cbb789118e..3cc83881ed 100644
--- a/intrpvar.h
+++ b/intrpvar.h
@@ -262,6 +262,8 @@ PERLVAR(I, exit_flags, U8) /* was exit() unexpected, etc. */
PERLVAR(I, utf8locale, bool) /* utf8 locale detected */
PERLVAR(I, in_utf8_CTYPE_locale, bool)
PERLVAR(I, in_utf8_COLLATE_locale, bool)
+PERLVARA(I, locale_utf8ness, 256, char)
+
#ifdef USE_LOCALE_CTYPE
PERLVAR(I, warn_locale, SV *)
#endif