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

configure.in
ext/soap/php_encoding.c
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 1c707bfb2e172edd2fc911d4ce06f46888673b24..463c4a3b4f73191961a15631c27e27451445dd45 100644 (file)
@@ -1280,7 +1280,7 @@ PHP_ADD_SOURCES(Zend, \
     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_ts_hash.c zend_stream.c \
-    zend_iterators.c zend_interfaces.c zend_exceptions.c)
+    zend_iterators.c zend_interfaces.c zend_exceptions.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 00c0f35fb1a81471006a23bcb617ce01628a00f3..64d1eaecce57fbd7d99496b0116d2dc53490b70c 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "php_soap.h"
 #include "ext/libxml/php_libxml.h"
+#include "zend_strtod.h"
 
 /* zval type decode */
 static zval *to_zval_double(encodeTypePtr type, xmlNodePtr data);
@@ -685,7 +686,7 @@ static zval *to_zval_long(encodeTypePtr type, xmlNodePtr data)
                        errno = 0;
                        ret->value.lval = strtol(data->children->content, NULL, 0);
                        if (errno == ERANGE) { /* overflow */
-                               ret->value.dval = strtod(data->children->content, NULL);
+                               ret->value.dval = zend_strtod(data->children->content, NULL);
                                ret->type = IS_DOUBLE;
                        } else {
                                ret->type = IS_LONG;
index 1e71a937d520b395fe0bf321e92ebdec3bd63a3b..e35946fa1064a1e40e327880092c72ab0755404a 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 3097d4f114c2b2f293e2c9accb5a627c75702276..9eddc44055441c9fc83b4d59baf0a031b1d78136 100644 (file)
@@ -112,7 +112,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 ba158e598c212a6a86bf8c77d5bd27c04bc5f174..8d84d50a9dd69d89e3d766f25cc27e78968fe196 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"
@@ -1204,7 +1205,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 32a37b0eccfa88a8da72e5f29bc85e49009b72a2..1a6eb13563e10328b154120ba11a61792d8ee630 100644 (file)
@@ -136,7 +136,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;
 
@@ -3793,18 +3793,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 475a0b7568817f146e27fd228eb1cf0f12b00858..9c640415d53867712d03aef17bf98562b7b7bb73 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) {
@@ -12,7 +12,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: .