summaryrefslogtreecommitdiff
path: root/perlapi.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 /perlapi.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 'perlapi.h')
-rw-r--r--perlapi.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/perlapi.h b/perlapi.h
index 7aa445578e..960983d090 100644
--- a/perlapi.h
+++ b/perlapi.h
@@ -99,6 +99,8 @@ END_EXTERN_C
#else /* !PERL_CORE */
+#undef PL_C_locale_obj
+#define PL_C_locale_obj (*Perl_GC_locale_obj_ptr(NULL))
#undef PL_appctx
#define PL_appctx (*Perl_Gappctx_ptr(NULL))
#undef PL_check