com php-src: Use one place to define max length of double: ext/json/json.c ext/json/json_encoder.c ext/standard/var.c main/php .h main/spprintf.c

From: Date: Sun, 26 Jun 2016 13:03:01 +0000
Subject: com php-src: Use one place to define max length of double: ext/json/json.c ext/json/json_encoder.c ext/standard/var.c main/php .h main/spprintf.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-92665@lists.php.net to get a copy of this message
Commit: 3f13507dd281adf0518c9162dce5391e9250e93b Author: Jakub Zelenka <bukka@php.net> Sun, 26 Jun 2016 14:03:01 +0100 Parents: 158b537c99ca5fc7846e7d16d532644be95894a7 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3f13507dd281adf0518c9162dce5391e9250e93b Log: Use one place to define max length of double Introduce new constant PHP_DOUBLE_MAX_LENGTH for that purpose Changed paths: M ext/json/json.c M ext/json/json_encoder.c M ext/standard/var.c M main/php.h M main/spprintf.c Diff: diff --git a/ext/json/json.c b/ext/json/json.c index d3c6111..8bb5e51 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -33,14 +33,6 @@ #include "php_json_parser.h" #include <zend_exceptions.h> -#include <float.h> -#if defined(DBL_MANT_DIG) && defined(DBL_MIN_EXP) -#define NUM_BUF_SIZE (3 + DBL_MANT_DIG - DBL_MIN_EXP) -#else -#define NUM_BUF_SIZE 1080 -#endif - - static PHP_MINFO_FUNCTION(json); static PHP_FUNCTION(json_encode); static PHP_FUNCTION(json_decode); diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c index 7720393...7cf7673 100644 --- a/ext/json/json_encoder.c +++ b/ext/json/json_encoder.c @@ -31,14 +31,6 @@ #include "php_json.h" #include <zend_exceptions.h> -/* double limits */ -#include <float.h> -#if defined(DBL_MANT_DIG) && defined(DBL_MIN_EXP) -#define PHP_JSON_DOUBLE_MAX_LENGTH (3 + DBL_MANT_DIG - DBL_MIN_EXP) -#else -#define PHP_JSON_DOUBLE_MAX_LENGTH 1080 -#endif - static const char digits[] = "0123456789abcdef"; static void php_json_escape_string(smart_str *buf, char *s, size_t len, int options); @@ -103,11 +95,11 @@ static inline int php_json_is_valid_double(double d) /* {{{ */ static inline void php_json_encode_double(smart_str *buf, double d, int options) /* {{{ */ { size_t len; - char num[PHP_JSON_DOUBLE_MAX_LENGTH]; + char num[PHP_DOUBLE_MAX_LENGTH]; php_gcvt(d, (int)PG(serialize_precision), '.', 'e', num); len = strlen(num); - if (options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < PHP_JSON_DOUBLE_MAX_LENGTH - 2) { + if (options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < PHP_DOUBLE_MAX_LENGTH - 2) { num[len++] = '..'; num[len++] = '0'; num[len] = '\0'; diff --git a/ext/standard/var.c b/ext/standard/var.c index e0938fe..809161a 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -35,17 +35,6 @@ #define COMMON (is_ref ? "&" : "") -/* Copied from main/spprintf..c and use the same buffer size - * - * NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions - * - * XXX: this is a magic number; do not decrease it - * Emax = 1023 - * NDIG = 320 - * NUM_BUF_SIZE >= strlen("-") + Emax + strlrn(".") + NDIG + strlen("E+1023") + 1; - */ -#define NUM_BUF_SIZE 2048 - static void php_array_element_dump(zval *zv, zend_ulong index, zend_string *key, int level) /* {{{ */ { if (key == NULL) { /* numeric key */ @@ -447,7 +436,7 @@ static void php_object_element_export(zval *zv, zend_ulong index, zend_string *k PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */ { HashTable *myht; - char tmp_str[NUM_BUF_SIZE]; + char tmp_str[PHP_DOUBLE_MAX_LENGTH]; zend_string *ztmp, *ztmp2; zend_ulong index; zend_string *key; @@ -853,7 +842,7 @@ again: return; case IS_DOUBLE: { - char tmp_str[NUM_BUF_SIZE]; + char tmp_str[PHP_DOUBLE_MAX_LENGTH]; smart_str_appendl(buf, "d:", 2); php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', tmp_str); smart_str_appends(buf, tmp_str); diff --git a/main/php.h b/main/php.h index 8eb1c53..8cc7851 100644 --- a/main/php.h +++ b/main/php.h @@ -231,6 +231,14 @@ char *strerror(int); #define INT_MIN (- INT_MAX - 1) #endif +/* double limits */ +#include <float.h> +#if defined(DBL_MANT_DIG) && defined(DBL_MIN_EXP) +#define PHP_DOUBLE_MAX_LENGTH (3 + DBL_MANT_DIG - DBL_MIN_EXP) +#else +#define PHP_DOUBLE_MAX_LENGTH 1080 +#endif + #define PHP_GCC_VERSION ZEND_GCC_VERSION #define PHP_ATTRIBUTE_MALLOC ZEND_ATTRIBUTE_MALLOC #define PHP_ATTRIBUTE_FORMAT ZEND_ATTRIBUTE_FORMAT diff --git a/main/spprintf.c b/main/spprintf.c index cac4210..73a5ff52 100644 --- a/main/spprintf.c +++ b/main/spprintf.c @@ -152,13 +152,9 @@ /* * NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions - * - * XXX: this is a magic number; do not decrease it - * Emax = 1023 - * NDIG = 320 - * NUM_BUF_SIZE >= strlen("-") + Emax + strlrn(".") + NDIG + strlen("E+1023") + 1; + * which can be at most max length of double */ -#define NUM_BUF_SIZE 2048 +#define NUM_BUF_SIZE PHP_DOUBLE_MAX_LENGTH #define NUM(c) (c - '0')

« previous php.cvs (#92665) next »