summaryrefslogtreecommitdiff
path: root/perlvars.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2016-07-20 10:33:40 -0600
committerKarl Williamson <khw@cpan.org>2016-07-29 15:46:46 -0600
commit6ebbc8624b039b6346d70b097fe51229b3938d1b (patch)
tree3a3dabd8ff5075596d355c003f470f2357440fa6 /perlvars.h
parent8ebda0e9b901456f365e0c5fbdbba0fef14054fe (diff)
downloadperl-6ebbc8624b039b6346d70b097fe51229b3938d1b.tar.gz
locale.c: Revamp my_strerror() for thread-safeness
This commit is the first step in making locale handling thread-safe. [perl #127708] was solved for 5.24 by adding a mutex in this function. That bug was caused by the code changing the locale even if the calling program is not consciously using locales. Posix 2008 introduced thread-safe locale functions. This commit changes this function to use them if the perl is threaded and the platform has them available. This means that the mutex is avoided on modern platforms. It restructures the function to return a mortal copy of the error message. This is a step towards making the function completely thread safe. Right now, as documented, if you do 'use locale', locale handling isn't thread-safe. A global C locale object is created and used here if necessary. It is destroyed at the end of the program. Note that some platforms have a strerror_r(), which is automatically used instead of strerror() if available. It differs form straight strerror() by taking a buffer to place the returned string, so the return does not point to internal static storage. One could test for the existence of this and avoid the mortal copy.
Diffstat (limited to 'perlvars.h')
-rw-r--r--perlvars.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/perlvars.h b/perlvars.h
index 5466294963..89e2e1eb52 100644
--- a/perlvars.h
+++ b/perlvars.h
@@ -101,6 +101,10 @@ PERLVARI(G, mmap_page_size, IV, 0)
PERLVAR(G, hints_mutex, perl_mutex) /* Mutex for refcounted he refcounting */
PERLVAR(G, locale_mutex, perl_mutex) /* Mutex for setlocale() changing */
+# ifdef HAS_NEWLOCALE
+PERLVAR(G, C_locale_obj, locale_t)
+# endif
+
#endif
#ifdef DEBUGGING