Skip to content

Commit a83cff2

Browse files
committed
locale.c: Work around a z/OS limitation/feature
Without per-thread locales, a multi-thread application is inherently unsafe. IBM solves that by allowing you to set up the locale any way you want, but after you've created a thread, all future locale changes are ignored, and return failure. But Perl itself changes the locale in a couple of cases. Recent changes have surfaced this issue in one case, leading to a panic. And this commit works around it, so that messages will be displayed in the locale in effect before the threads were created. The remaining case requires further investigation. Nothing in our suite is failing.
1 parent d0f6d17 commit a83cff2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

locale.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5371,7 +5371,19 @@ Perl_my_strerror(pTHX_ const int errnum)
53715371
/* The setlocale() just below likely will zap 'save_locale', so
53725372
* create a copy. */
53735373
save_locale = savepv(save_locale);
5374-
do_setlocale_c(LC_MESSAGES, "C");
5374+
if (! do_setlocale_c(LC_MESSAGES, "C")) {
5375+
5376+
/* If, for some reason, the locale change failed, we
5377+
* soldier on as best as possible under the circumstances,
5378+
* using the current locale, and clear save_locale, so we
5379+
* don't try to change back. On z/0S, all setlocale()
5380+
* calls fail after you've created a thread. This is their
5381+
* way of making sure the entire process is always a single
5382+
* locale. This means that 'use locale' is always in place
5383+
* for messages under these circumstances. */
5384+
Safefree(save_locale);
5385+
save_locale = NULL;
5386+
}
53755387
}
53765388
}
53775389
} /* end of ! within_locale_scope */

0 commit comments

Comments
 (0)