]> granicus.if.org Git - php/commitdiff
- MFH: Fixed bug #30630: Added a BSD based strtod function that is
authorDerick Rethans <derick@php.net>
Wed, 3 Nov 2004 23:36:03 +0000 (23:36 +0000)
committerDerick Rethans <derick@php.net>
Wed, 3 Nov 2004 23:36:03 +0000 (23:36 +0000)
  locale-independent. (PHP part)

configure.in
ext/standard/formatted_print.c
ext/standard/php_string.h
ext/standard/scanf.c
ext/standard/string.c
tests/lang/034.phpt
tests/lang/bug30638.phpt [new file with mode: 0644]

index b282d7e6e053df699735342280f74d304aafa3cb..d51e4df2122fe2c7ebd895b44f1fa28ed228270f 100644 (file)
@@ -1213,7 +1213,7 @@ PHP_ADD_SOURCES(Zend, \
     zend_opcode.c zend_operators.c zend_ptr_stack.c zend_stack.c \
     zend_variables.c zend.c zend_API.c zend_extensions.c zend_hash.c \
     zend_list.c zend_indent.c zend_builtin_functions.c zend_sprintf.c \
-    zend_ini.c zend_qsort.c zend_multibyte.c)
+    zend_ini.c zend_qsort.c zend_multibyte.c zend_strtod.c)
 
 if test -r "$abs_srcdir/Zend/zend_objects.c"; then
   PHP_ADD_SOURCES(Zend, zend_objects.c zend_object_handlers.c zend_objects_API.c zend_mm.c)
index 68fe8b9d60b27acbd48f2ea58099512c9bcf99fa..9a5affe0596f0ee4817f421ff20faef0067568c7 100644 (file)
@@ -303,7 +303,14 @@ php_sprintf_appenddouble(char **buffer, int *pos,
        char *cvt;
        register int i = 0, j = 0;
        int sign, decpt, cvt_len;
-       char decimal_point = EG(float_separator)[0];
+#ifdef HAVE_LOCALE_H
+       struct lconv lc;
+       char decimal_point;
+       localeconv_r(&lc);
+       decimal_point = (lc.decimal_point)[0];
+#else
+       char decimal_point = '.';
+#endif
 
        PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n",
                                  *buffer, pos, size, number, width, padding, alignment, fmt));
index 51f8fdc782a123630c4db66080e6fd35fe50bba1..7300b0ed33a891ad60d12ae67b49e7475ba4f635 100644 (file)
@@ -109,7 +109,7 @@ PHP_MINIT_FUNCTION(nl_langinfo);
 PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len, int fold_case);
 
 #ifdef HAVE_LOCALECONV
-struct lconv *localeconv_r(struct lconv *out);
+PHPAPI struct lconv *localeconv_r(struct lconv *out);
 #endif
 
 PHPAPI char *php_strtoupper(char *s, size_t len);
index f86dd8e99736de28c781688cf10a832cc783e747..ccab16232baf07e718aaa54a4d57698bdbe8ca77 100644 (file)
@@ -78,6 +78,7 @@
 #endif
 #include "zend_execute.h"
 #include "zend_operators.h"
+#include "zend_strtod.h"
 #include "php_globals.h"
 #include "basic_functions.h"
 #include "scanf.h"
@@ -1194,7 +1195,7 @@ PHPAPI int php_sscanf_internal(   char *string, char *format,
                if (!(flags & SCAN_SUPPRESS)) {
                    double dvalue;
                    *end = '\0';
-                   dvalue = strtod(buf, NULL);
+                   dvalue = zend_strtod(buf, NULL);
             if (numVars) {
                 current = args[objIndex++];
                 convert_to_double( *current );
index 9fbf0fecd1ed10fd70f60c99fb0d35da55e24cef..556da7ba513ca07d50cd8e3560df16931956b301 100644 (file)
@@ -133,7 +133,7 @@ static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t *
 #ifdef HAVE_LOCALECONV
 /* {{{ localeconv_r
  * glibc's localeconv is not reentrant, so lets make it so ... sorta */
-struct lconv *localeconv_r(struct lconv *out)
+PHPAPI struct lconv *localeconv_r(struct lconv *out)
 {
        struct lconv *res;
 
@@ -3139,18 +3139,6 @@ PHP_FUNCTION(setlocale)
                        efree(args);
                        RETVAL_STRING(retval, 1);
                        
-                       if (cat == LC_NUMERIC || cat == LC_ALL) {
-                               struct lconv lc;
-                               localeconv_r(&lc);
-                       
-                               EG(float_separator)[0] = (lc.decimal_point)[0];
-
-                               if ((lc.decimal_point)[0] != '.') {
-                                       /* set locale back to C */
-                                       setlocale(LC_NUMERIC, "C");     
-                               }
-                       }
-                       
                        return;
                }
                
index 9b10603c83b529669aaa0dca131e45e4927c33ce..06aa9651f7125bdb8535c6b1a3de14ba62bf575d 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-Locale settings affecting float parsing
+Bug #12647 (Locale settings affecting float parsing)
 --SKIPIF--
 <?php  # try to activate a german locale
 if (setlocale(LC_NUMERIC, "de_DE", "de", "german", "ge") === FALSE) {
@@ -14,7 +14,6 @@ if (setlocale(LC_NUMERIC, "de_DE", "de", "german", "ge") === FALSE) {
 setlocale(LC_NUMERIC, "de_DE", "de", "german", "ge");
 
 echo (float)"3.14", "\n";
-
 ?>
 --EXPECT--
 3,14
diff --git a/tests/lang/bug30638.phpt b/tests/lang/bug30638.phpt
new file mode 100644 (file)
index 0000000..2574d13
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Bug #30638 (localeconv returns wrong LC_NUMERIC settings)
+--SKIPIF--
+<?php  # try to activate a german locale
+if (setlocale(LC_NUMERIC, "de_DE", "de", "german", "ge") === FALSE) {
+       print "skip";
+}
+?>
+--FILE--
+<?php 
+# activate the german locale
+setlocale(LC_NUMERIC, "de_DE", "de", "german", "ge");
+
+$lc = localeconv();
+printf("decimal_point: %s\n", $lc['decimal_point']);
+printf("thousands_sep: %s\n", $lc['thousands_sep']);
+?>
+--EXPECT--
+decimal_point: ,
+thousands_sep: .