Browse Source

- Fixed bug #30630: Added a BSD based strtod function that is

locale-independent.
PHP-5.1
Derick Rethans 22 years ago
parent
commit
e612284ea4
  1. 2
      Zend/zend_execute_API.c
  2. 3
      Zend/zend_globals.h
  3. 7
      Zend/zend_ini.c
  4. 5
      Zend/zend_language_scanner.l
  5. 14
      Zend/zend_operators.c
  6. 3
      Zend/zend_operators.h
  7. 1760
      Zend/zend_strtod.c
  8. 28
      Zend/zend_strtod.h

2
Zend/zend_execute_API.c

@ -183,8 +183,6 @@ void init_executor(TSRMLS_D)
EG(scope) = NULL;
EG(This) = NULL;
EG(float_separator)[0] = '.';
}
void shutdown_destructors(TSRMLS_D) {

3
Zend/zend_globals.h

@ -232,9 +232,6 @@ struct _zend_executor_globals {
zend_property_info std_property_info;
/* locale stuff */
char float_separator[1];
void *reserved[ZEND_MAX_RESERVED_RESOURCES];
};

7
Zend/zend_ini.c

@ -24,6 +24,7 @@
#include "zend_ini.h"
#include "zend_alloc.h"
#include "zend_operators.h"
#include "zend_strtod.h"
static HashTable *registered_zend_ini_directives;
@ -298,9 +299,9 @@ ZEND_API double zend_ini_double(char *name, uint name_length, int orig)
if (zend_hash_find(EG(ini_directives), name, name_length, (void **) &ini_entry)==SUCCESS) {
if (orig && ini_entry->modified) {
return (double) (ini_entry->orig_value ? strtod(ini_entry->orig_value, NULL) : 0.0);
return (double) (ini_entry->orig_value ? zend_strtod(ini_entry->orig_value, NULL) : 0.0);
} else if (ini_entry->value) {
return (double) strtod(ini_entry->value, NULL);
return (double) zend_strtod(ini_entry->value, NULL);
}
}
@ -486,7 +487,7 @@ ZEND_API ZEND_INI_MH(OnUpdateReal)
p = (double *) (base+(size_t) mh_arg1);
*p = strtod(new_value, NULL);
*p = zend_strtod(new_value, NULL);
return SUCCESS;
}

5
Zend/zend_language_scanner.l

@ -58,6 +58,7 @@
#include "zend_variables.h"
#include "zend_operators.h"
#include "zend_API.h"
#include "zend_strtod.h"
#ifdef HAVE_STDARG_H
# include <stdarg.h>
@ -1189,7 +1190,7 @@ NEWLINE ("\r"|"\n"|"\r\n")
errno = 0;
zendlval->value.lval = strtol(yytext, NULL, 0);
if (errno == ERANGE) { /* overflow */
zendlval->value.dval = strtod(yytext, NULL);
zendlval->value.dval = zend_strtod(yytext, NULL);
zendlval->type = IS_DOUBLE;
return T_DNUMBER;
} else {
@ -1226,7 +1227,7 @@ NEWLINE ("\r"|"\n"|"\r\n")
}
<ST_IN_SCRIPTING>{DNUM}|{EXPONENT_DNUM} {
zendlval->value.dval = strtod(yytext, NULL);
zendlval->value.dval = zend_strtod(yytext, NULL);
zendlval->type = IS_DOUBLE;
return T_DNUMBER;
}

14
Zend/zend_operators.c

@ -29,6 +29,7 @@
#include "zend_fast_cache.h"
#include "zend_API.h"
#include "zend_multiply.h"
#include "zend_strtod.h"
#define LONG_SIGN_MASK (1L << (8*sizeof(long)-1))
@ -384,7 +385,7 @@ ZEND_API void convert_to_double(zval *op)
case IS_STRING:
strval = op->value.str.val;
op->value.dval = strtod(strval, NULL);
op->value.dval = zend_strtod(strval, NULL);
STR_FREE(strval);
break;
case IS_ARRAY:
@ -1897,9 +1898,9 @@ ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2)
(ret2=is_numeric_string(s2->value.str.val, s2->value.str.len, &lval2, &dval2, 0))) {
if ((ret1==IS_DOUBLE) || (ret2==IS_DOUBLE)) {
if (ret1!=IS_DOUBLE) {
dval1 = strtod(s1->value.str.val, NULL);
dval1 = zend_strtod(s1->value.str.val, NULL);
} else if (ret2!=IS_DOUBLE) {
dval2 = strtod(s2->value.str.val, NULL);
dval2 = zend_strtod(s2->value.str.val, NULL);
}
result->value.dval = dval1 - dval2;
result->value.lval = ZEND_NORMALIZE_BOOL(result->value.dval);
@ -1973,13 +1974,6 @@ ZEND_API void zend_locale_sprintf_double(zval *op ZEND_FILE_LINE_DC)
op->value.str.val = (char *) emalloc_rel(MAX_LENGTH_OF_DOUBLE + EG(precision) + 1);
sprintf(op->value.str.val, "%.*G", (int) EG(precision), dval);
op->value.str.len = strlen(op->value.str.val);
if (EG(float_separator)[0] != '.') {
char *p = op->value.str.val;
if ((p = strchr(p, '.'))) {
*p = EG(float_separator)[0];
}
}
}
/*

3
Zend/zend_operators.h

@ -29,6 +29,7 @@
#include <ieeefp.h>
#endif
#include "zend_strtod.h"
#if 0&&HAVE_BCMATH
#include "ext/bcmath/libbcmath/src/bcmath.h"
@ -99,7 +100,7 @@ static inline zend_bool is_numeric_string(char *str, int length, long *lval, dou
}
errno=0;
local_dval = strtod(str, &end_ptr_double);
local_dval = zend_strtod(str, &end_ptr_double);
if (errno != ERANGE) {
if (end_ptr_double == str+length) { /* floating point string */
if (!zend_finite(local_dval)) {

1760
Zend/zend_strtod.c
File diff suppressed because it is too large
View File

28
Zend/zend_strtod.h

@ -0,0 +1,28 @@
/*
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
| Copyright (c) 1998-2004 Zend Technologies Ltd. (http://www.zend.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 2.00 of the Zend license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.zend.com/license/2_00.txt. |
| If you did not receive a copy of the Zend license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@zend.com so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Derick Rethans <derick@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
/* This is a header file for the strtod implementation by David M. Gay which
* can be found in zend_strtod.c */
#ifndef ZEND_STRTOD_H
#define ZEND_STRTOD_H
double zend_strtod(const char *s00, char **se);
#endif
Loading…
Cancel
Save