Skip to content

Commit 3d68d84

Browse files
committed
Merge branch 'PHP-5.6'
* PHP-5.6: updated NEWS Fixed bug #65230 setting locale randomly broken
2 parents 0d76e16 + 8d79139 commit 3d68d84

File tree

6 files changed

+108
-8
lines changed

6 files changed

+108
-8
lines changed

ext/standard/formatted_print.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727

2828
#ifdef HAVE_LOCALE_H
2929
#include <locale.h>
30+
#ifdef ZTS
31+
#define LCONV_DECIMAL_POINT (*lconv.decimal_point)
32+
#else
3033
#define LCONV_DECIMAL_POINT (*lconv->decimal_point)
34+
#endif
3135
#else
3236
#define LCONV_DECIMAL_POINT '.'
3337
#endif
@@ -211,7 +215,11 @@ php_sprintf_appenddouble(zend_string **buffer, size_t *pos,
211215
size_t s_len = 0;
212216
int is_negative = 0;
213217
#ifdef HAVE_LOCALE_H
218+
#ifdef ZTS
219+
struct lconv lconv;
220+
#else
214221
struct lconv *lconv;
222+
#endif
215223
#endif
216224

217225
PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n",
@@ -243,7 +251,11 @@ php_sprintf_appenddouble(zend_string **buffer, size_t *pos,
243251
case 'f':
244252
case 'F':
245253
#ifdef HAVE_LOCALE_H
254+
#ifdef ZTS
255+
localeconv_r(&lconv);
256+
#else
246257
lconv = localeconv();
258+
#endif
247259
#endif
248260
s = php_conv_fp((fmt == 'f')?'F':fmt, number, 0, precision,
249261
(fmt == 'f')?LCONV_DECIMAL_POINT:'.',
@@ -267,7 +279,11 @@ php_sprintf_appenddouble(zend_string **buffer, size_t *pos,
267279
* * We use &num_buf[ 1 ], so that we have room for the sign
268280
*/
269281
#ifdef HAVE_LOCALE_H
282+
#ifdef ZTS
283+
localeconv_r(&lconv);
284+
#else
270285
lconv = localeconv();
286+
#endif
271287
#endif
272288
s = php_gcvt(number, precision, LCONV_DECIMAL_POINT, (fmt == 'G')?'E':'e', &num_buf[1]);
273289
is_negative = 0;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--TEST--
2+
Bug #65230 setting locale randomly broken
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) != 'WIN') {
6+
die('skip');
7+
}
8+
?>
9+
--INI--
10+
date.timezone=Europe/Berlin
11+
--FILE--
12+
<?php
13+
14+
function test($locale, $value)
15+
{
16+
$newlocale = setlocale(LC_ALL, $locale);
17+
$conv = localeconv();
18+
$sep = $conv['decimal_point'];
19+
20+
printf("%s\n--------------------------\n", $newlocale);
21+
printf(" sep: %s\n", $sep);
22+
printf(" %%f: %f\n", $value);
23+
printf(" %%F: %F\n", $value);
24+
printf("date: %s\n", strftime('%x'));
25+
printf("\n");
26+
}
27+
28+
test('german', 3.41);
29+
test('english', 3.41);
30+
test('french', 3.41);
31+
test('german', 3.41);
32+
--EXPECT--
33+
German_Germany.1252
34+
--------------------------
35+
sep: ,
36+
%f: 3,410000
37+
%F: 3.410000
38+
date: 05.12.2014
39+
40+
English_United States.1252
41+
--------------------------
42+
sep: .
43+
%f: 3.410000
44+
%F: 3.410000
45+
date: 12/5/2014
46+
47+
French_France.1252
48+
--------------------------
49+
sep: ,
50+
%f: 3,410000
51+
%F: 3.410000
52+
date: 05/12/2014
53+
54+
German_Germany.1252
55+
--------------------------
56+
sep: ,
57+
%f: 3,410000
58+
%F: 3.410000
59+
date: 05.12.2014
60+

main/snprintf.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@
3838

3939
#ifdef HAVE_LOCALE_H
4040
#include <locale.h>
41+
#ifdef ZTS
42+
#define LCONV_DECIMAL_POINT (*lconv.decimal_point)
43+
#else
4144
#define LCONV_DECIMAL_POINT (*lconv->decimal_point)
45+
#endif
4246
#else
4347
#define LCONV_DECIMAL_POINT '.'
4448
#endif
@@ -607,7 +611,11 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
607611
char char_buf[2]; /* for printing %% and %<unknown> */
608612

609613
#ifdef HAVE_LOCALE_H
614+
#ifdef ZTS
615+
struct lconv lconv;
616+
#else
610617
struct lconv *lconv = NULL;
618+
#endif
611619
#endif
612620

613621
/*
@@ -1017,9 +1025,13 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
10171025
s_len = 3;
10181026
} else {
10191027
#ifdef HAVE_LOCALE_H
1028+
#ifdef ZTS
1029+
localeconv_r(&lconv);
1030+
#else
10201031
if (!lconv) {
10211032
lconv = localeconv();
10221033
}
1034+
#endif
10231035
#endif
10241036
s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form,
10251037
(adjust_precision == NO) ? FLOAT_DIGITS : precision,
@@ -1074,9 +1086,13 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
10741086
* * We use &num_buf[ 1 ], so that we have room for the sign
10751087
*/
10761088
#ifdef HAVE_LOCALE_H
1089+
#ifdef ZTS
1090+
localeconv_r(&lconv);
1091+
#else
10771092
if (!lconv) {
10781093
lconv = localeconv();
10791094
}
1095+
#endif
10801096
#endif
10811097
s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]);
10821098
if (*s == '-') {

main/spprintf.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@
9393

9494
#ifdef HAVE_LOCALE_H
9595
#include <locale.h>
96+
#ifdef ZTS
97+
#define LCONV_DECIMAL_POINT (*lconv.decimal_point)
98+
#else
9699
#define LCONV_DECIMAL_POINT (*lconv->decimal_point)
100+
#endif
97101
#else
98102
#define LCONV_DECIMAL_POINT '.'
99103
#endif
@@ -218,7 +222,11 @@ static void xbuf_format_converter(void *xbuf, zend_bool is_char, const char *fmt
218222
char char_buf[2]; /* for printing %% and %<unknown> */
219223

220224
#ifdef HAVE_LOCALE_H
225+
#ifdef ZTS
226+
struct lconv lconv;
227+
#else
221228
struct lconv *lconv = NULL;
229+
#endif
222230
#endif
223231

224232
/*
@@ -633,9 +641,13 @@ static void xbuf_format_converter(void *xbuf, zend_bool is_char, const char *fmt
633641
s_len = 3;
634642
} else {
635643
#ifdef HAVE_LOCALE_H
644+
#ifdef ZTS
645+
localeconv_r(&lconv);
646+
#else
636647
if (!lconv) {
637648
lconv = localeconv();
638649
}
650+
#endif
639651
#endif
640652
s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form,
641653
(adjust_precision == NO) ? FLOAT_DIGITS : precision,
@@ -689,9 +701,13 @@ static void xbuf_format_converter(void *xbuf, zend_bool is_char, const char *fmt
689701
* * We use &num_buf[ 1 ], so that we have room for the sign
690702
*/
691703
#ifdef HAVE_LOCALE_H
704+
#ifdef ZTS
705+
localeconv_r(&lconv);
706+
#else
692707
if (!lconv) {
693708
lconv = localeconv();
694709
}
710+
#endif
695711
#endif
696712
s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]);
697713
if (*s == '-')

tests/lang/034.phpt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ Bug #12647 (Locale settings affecting float parsing)
44
precision=14
55
--SKIPIF--
66
<?php # try to activate a german locale
7-
if (substr(PHP_OS, 0, 3) == 'WIN') {
8-
/* skip on windows until #63688 was fixed */
9-
die('skip');
10-
}
117
if (setlocale(LC_NUMERIC, "de_DE.UTF-8", "de_DE", "de", "german", "ge", "de_DE.ISO-8859-1") === FALSE) {
128
print "skip Can't find german locale";
139
}

tests/lang/bug30638.phpt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
Bug #30638 (localeconv returns wrong LC_NUMERIC settings) (ok to fail on MacOS X)
33
--SKIPIF--
44
<?php # try to activate a german locale
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
/* skip on windows until #63688 was fixed */
7-
die('skip');
8-
}
95
if (setlocale(LC_NUMERIC, "de_DE.UTF-8", "de_DE", "de", "german", "ge", "de_DE.ISO-8859-1") === FALSE) {
106
print "skip setlocale() failed";
117
} elseif (strtolower(php_uname('s')) == 'darwin') {

0 commit comments

Comments
 (0)