diff options
-rw-r--r-- | ext/standard/formatted_print.c | 16 | ||||
-rw-r--r-- | ext/standard/tests/strings/bug65230.phpt | 60 | ||||
-rw-r--r-- | main/snprintf.c | 16 | ||||
-rw-r--r-- | main/spprintf.c | 16 | ||||
-rw-r--r-- | tests/lang/034.phpt | 4 | ||||
-rw-r--r-- | tests/lang/bug30638.phpt | 4 |
6 files changed, 108 insertions, 8 deletions
diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index f84075440b..2efd16247f 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -27,7 +27,11 @@ #ifdef HAVE_LOCALE_H #include <locale.h> +#ifdef ZTS +#define LCONV_DECIMAL_POINT (*lconv.decimal_point) +#else #define LCONV_DECIMAL_POINT (*lconv->decimal_point) +#endif #else #define LCONV_DECIMAL_POINT '.' #endif @@ -211,8 +215,12 @@ php_sprintf_appenddouble(zend_string **buffer, size_t *pos, size_t s_len = 0; int is_negative = 0; #ifdef HAVE_LOCALE_H +#ifdef ZTS + struct lconv lconv; +#else struct lconv *lconv; #endif +#endif PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n", *buffer, pos, &(*buffer)->len, number, width, padding, alignment, fmt)); @@ -243,8 +251,12 @@ php_sprintf_appenddouble(zend_string **buffer, size_t *pos, case 'f': case 'F': #ifdef HAVE_LOCALE_H +#ifdef ZTS + localeconv_r(&lconv); +#else lconv = localeconv(); #endif +#endif s = php_conv_fp((fmt == 'f')?'F':fmt, number, 0, precision, (fmt == 'f')?LCONV_DECIMAL_POINT:'.', &is_negative, &num_buf[1], &s_len); @@ -267,8 +279,12 @@ php_sprintf_appenddouble(zend_string **buffer, size_t *pos, * * We use &num_buf[ 1 ], so that we have room for the sign */ #ifdef HAVE_LOCALE_H +#ifdef ZTS + localeconv_r(&lconv); +#else lconv = localeconv(); #endif +#endif s = php_gcvt(number, precision, LCONV_DECIMAL_POINT, (fmt == 'G')?'E':'e', &num_buf[1]); is_negative = 0; if (*s == '-') { diff --git a/ext/standard/tests/strings/bug65230.phpt b/ext/standard/tests/strings/bug65230.phpt new file mode 100644 index 0000000000..ca2c3ca922 --- /dev/null +++ b/ext/standard/tests/strings/bug65230.phpt @@ -0,0 +1,60 @@ +--TEST-- +Bug #65230 setting locale randomly broken +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip'); +} +?> +--INI-- +date.timezone=Europe/Berlin +--FILE-- +<?php + +function test($locale, $value) +{ + $newlocale = setlocale(LC_ALL, $locale); + $conv = localeconv(); + $sep = $conv['decimal_point']; + + printf("%s\n--------------------------\n", $newlocale); + printf(" sep: %s\n", $sep); + printf(" %%f: %f\n", $value); + printf(" %%F: %F\n", $value); + printf("date: %s\n", strftime('%x')); + printf("\n"); +} + +test('german', 3.41); +test('english', 3.41); +test('french', 3.41); +test('german', 3.41); +--EXPECT-- +German_Germany.1252 +-------------------------- + sep: , + %f: 3,410000 + %F: 3.410000 +date: 05.12.2014 + +English_United States.1252 +-------------------------- + sep: . + %f: 3.410000 + %F: 3.410000 +date: 12/5/2014 + +French_France.1252 +-------------------------- + sep: , + %f: 3,410000 + %F: 3.410000 +date: 05/12/2014 + +German_Germany.1252 +-------------------------- + sep: , + %f: 3,410000 + %F: 3.410000 +date: 05.12.2014 + diff --git a/main/snprintf.c b/main/snprintf.c index 0b9182b614..a1c03e5947 100644 --- a/main/snprintf.c +++ b/main/snprintf.c @@ -38,7 +38,11 @@ #ifdef HAVE_LOCALE_H #include <locale.h> +#ifdef ZTS +#define LCONV_DECIMAL_POINT (*lconv.decimal_point) +#else #define LCONV_DECIMAL_POINT (*lconv->decimal_point) +#endif #else #define LCONV_DECIMAL_POINT '.' #endif @@ -607,8 +611,12 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / char char_buf[2]; /* for printing %% and %<unknown> */ #ifdef HAVE_LOCALE_H +#ifdef ZTS + struct lconv lconv; +#else struct lconv *lconv = NULL; #endif +#endif /* * Flag variables @@ -1017,10 +1025,14 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / s_len = 3; } else { #ifdef HAVE_LOCALE_H +#ifdef ZTS + localeconv_r(&lconv); +#else if (!lconv) { lconv = localeconv(); } #endif +#endif s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form, (adjust_precision == NO) ? FLOAT_DIGITS : precision, (*fmt == 'f')?LCONV_DECIMAL_POINT:'.', @@ -1074,10 +1086,14 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / * * We use &num_buf[ 1 ], so that we have room for the sign */ #ifdef HAVE_LOCALE_H +#ifdef ZTS + localeconv_r(&lconv); +#else if (!lconv) { lconv = localeconv(); } #endif +#endif s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); if (*s == '-') { prefix_char = *s++; diff --git a/main/spprintf.c b/main/spprintf.c index 1fcce9df18..ff8b723310 100644 --- a/main/spprintf.c +++ b/main/spprintf.c @@ -93,7 +93,11 @@ #ifdef HAVE_LOCALE_H #include <locale.h> +#ifdef ZTS +#define LCONV_DECIMAL_POINT (*lconv.decimal_point) +#else #define LCONV_DECIMAL_POINT (*lconv->decimal_point) +#endif #else #define LCONV_DECIMAL_POINT '.' #endif @@ -218,8 +222,12 @@ static void xbuf_format_converter(void *xbuf, zend_bool is_char, const char *fmt char char_buf[2]; /* for printing %% and %<unknown> */ #ifdef HAVE_LOCALE_H +#ifdef ZTS + struct lconv lconv; +#else struct lconv *lconv = NULL; #endif +#endif /* * Flag variables @@ -633,10 +641,14 @@ static void xbuf_format_converter(void *xbuf, zend_bool is_char, const char *fmt s_len = 3; } else { #ifdef HAVE_LOCALE_H +#ifdef ZTS + localeconv_r(&lconv); +#else if (!lconv) { lconv = localeconv(); } #endif +#endif s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form, (adjust_precision == NO) ? FLOAT_DIGITS : precision, (*fmt == 'f')?LCONV_DECIMAL_POINT:'.', @@ -689,10 +701,14 @@ static void xbuf_format_converter(void *xbuf, zend_bool is_char, const char *fmt * * We use &num_buf[ 1 ], so that we have room for the sign */ #ifdef HAVE_LOCALE_H +#ifdef ZTS + localeconv_r(&lconv); +#else if (!lconv) { lconv = localeconv(); } #endif +#endif s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); if (*s == '-') prefix_char = *s++; diff --git a/tests/lang/034.phpt b/tests/lang/034.phpt index cea0797d69..5d2c610926 100644 --- a/tests/lang/034.phpt +++ b/tests/lang/034.phpt @@ -4,10 +4,6 @@ Bug #12647 (Locale settings affecting float parsing) precision=14 --SKIPIF-- <?php # try to activate a german locale -if (substr(PHP_OS, 0, 3) == 'WIN') { - /* skip on windows until #63688 was fixed */ - die('skip'); -} if (setlocale(LC_NUMERIC, "de_DE.UTF-8", "de_DE", "de", "german", "ge", "de_DE.ISO-8859-1") === FALSE) { print "skip Can't find german locale"; } diff --git a/tests/lang/bug30638.phpt b/tests/lang/bug30638.phpt index 945a228eda..30b70f30fb 100644 --- a/tests/lang/bug30638.phpt +++ b/tests/lang/bug30638.phpt @@ -2,10 +2,6 @@ Bug #30638 (localeconv returns wrong LC_NUMERIC settings) (ok to fail on MacOS X) --SKIPIF-- <?php # try to activate a german locale -if (substr(PHP_OS, 0, 3) == 'WIN') { - /* skip on windows until #63688 was fixed */ - die('skip'); -} if (setlocale(LC_NUMERIC, "de_DE.UTF-8", "de_DE", "de", "german", "ge", "de_DE.ISO-8859-1") === FALSE) { print "skip setlocale() failed"; } elseif (strtolower(php_uname('s')) == 'darwin') { |