#30638 [NEW]: localeconv returns wrong LC_NUMERIC settings
| From: | k at ailis dot de | Date: | Mon, 01 Nov 2004 00:14:58 +0000 |
| Subject: | #30638 [NEW]: localeconv returns wrong LC_NUMERIC settings | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-68544@lists.php.net to get a copy of this message | ||
From: k at ailis dot de
Operating system: Linux
PHP version: 5.0.2
PHP Bug Type: *Languages/Translation
Bug description: localeconv returns wrong LC_NUMERIC settings
Description:
------------
If locale is switched to a european language (like de_DE) then localeconv
returns wrong settings for decimal_point and thousands_sep while other
data (like mon_decimal_point and mon_thousands_sep) is correct.
This bug was introduced by this patch for ext/standard/string.c:
$Id: string.c,v 1.320 2002/10/10 16:29:35 iliaa Exp $
This patch modified setlocale() so it resets the LC_NUMERIC locale to C.
This was a bad enough but there were reasons I agree to.
Here is a patch which corrects this bug by remembering the LC_NUMERIC
locale, setting this remembered locale before calling localeconv_r() and
resetting it to C after the call. In that way localeconv() returns the
correct data and PHP can still stick to LC_NUMERIC=C:
diff -Nur php-src.orig/ext/standard/basic_functions.c
php-src/ext/standard/basic_functions.c
--- php-src.orig/ext/standard/basic_functions.c 2004-10-09
00:19:03.000000000 +0200
+++ php-src/ext/standard/basic_functions.c 2004-11-01 00:36:48.000000000
+0100
@@ -1156,6 +1156,7 @@
BG(strtok_string) = NULL;
BG(strtok_zval) = NULL;
BG(locale_string) = NULL;
+ BG(numeric_locale_string) = NULL;
BG(user_compare_func_name) = NULL;
BG(array_walk_func_name) = NULL;
BG(page_uid) = -1;
@@ -1212,7 +1213,8 @@
setlocale(LC_CTYPE, "");
}
STR_FREE(BG(locale_string));
-
+ STR_FREE(BG(numeric_locale_string));
+
if (FG(stream_wrappers)) {
zend_hash_destroy(FG(stream_wrappers));
efree(FG(stream_wrappers));
diff -Nur php-src.orig/ext/standard/basic_functions.h
php-src/ext/standard/basic_functions.h
--- php-src.orig/ext/standard/basic_functions.h 2004-08-07
17:59:59.000000000 +0200
+++ php-src/ext/standard/basic_functions.h 2004-11-01 00:30:18.000000000
+0100
@@ -155,6 +155,7 @@
zval *strtok_zval;
char *strtok_string;
char *locale_string;
+ char *numeric_locale_string;
char *strtok_last;
char strtok_table[256];
ulong strtok_len;
diff -Nur php-src.orig/ext/standard/string.c
php-src/ext/standard/string.c
--- php-src.orig/ext/standard/string.c 2004-10-21 00:44:43.000000000
+0200
+++ php-src/ext/standard/string.c 2004-11-01 00:36:01.000000000 +0100
@@ -3799,6 +3799,10 @@
EG(float_separator)[0] = (lc.decimal_point)[0];
+ /* Remember numeric locale */
+ STR_FREE(BG(numeric_locale_string));
+ BG(numeric_locale_string) = estrdup(loc);
+
if ((lc.decimal_point)[0] != '.') {
/* set locale back to C */
setlocale(LC_NUMERIC, "C");
@@ -4351,7 +4355,18 @@
{
struct lconv currlocdata;
+ /* Remember numeric locale */
+ if (BG(numeric_locale_string)) {
+ setlocale(LC_NUMERIC, BG(numeric_locale_string));
+ }
+
+ /* Fetch formatting information */
localeconv_r( &currlocdata );
+
+ /* Reset numeric locale to C */
+ if (BG(numeric_locale_string)) {
+ setlocale(LC_NUMERIC, "C");
+ }
/* Grab the grouping data out of the array */
len = strlen(currlocdata.grouping);
Reproduce code:
---------------
<?php
setlocale(LC_ALL, 'de_DE');
$lc = localeconv();
printf("decimal_point: %s\n", $lc['decimal_point']);
printf("thousands_sep: %s\n", $lc['thousands_sep']);
?>
Expected result:
----------------
decimal_point: ,
thousands_sep: .
Actual result:
--------------
decimal_point: .
thousands_sep:
--
Edit bug report at http://bugs.php.net/?id=30638&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30638&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30638&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30638&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=30638&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=30638&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=30638&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=30638&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=30638&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=30638&r=support
Expected behavior: http://bugs.php.net/fix.php?id=30638&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=30638&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=30638&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=30638&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30638&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=30638&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=30638&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=30638&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=30638&r=float
MySQL Configuration Error: http://bugs.php.net/fix.php?id=30638&r=mysqlcfg