diff options
author | Yasuo Ohgaki <yohgaki@ohgaki.net> | 2015-08-05 08:12:10 +0900 |
---|---|---|
committer | Jakub Zelenka <bukka@php.net> | 2016-06-26 13:26:42 +0100 |
commit | f943daf2d7eeed98d3ead5c05637c2ea8a2ff0e6 (patch) | |
tree | 869bb1269326a413167ce94e81aaa1136cfce71f /ext/standard/var.c | |
parent | 8de8636a2b6dc331486284f1f037259bb7347768 (diff) | |
download | php-git-f943daf2d7eeed98d3ead5c05637c2ea8a2ff0e6.tar.gz |
Initial patch for 0 mode float conversion. The magic number is better to be improved. Any suggestion where to define it?
Diffstat (limited to 'ext/standard/var.c')
-rw-r--r-- | ext/standard/var.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/ext/standard/var.c b/ext/standard/var.c index efd5119fed..e197198557 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -436,8 +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; - size_t tmp_len; + char tmp_str[2048]; /* Use the same magic number of spprintf.c NUM_BUF_SIZE */ zend_string *ztmp, *ztmp2; zend_ulong index; zend_string *key; @@ -458,18 +457,26 @@ again: smart_str_append_long(buf, Z_LVAL_P(struc)); break; case IS_DOUBLE: + /* TODO: check INF, -INF and NAN in the new logic tmp_len = spprintf(&tmp_str, 0,"%.*H", PG(serialize_precision), Z_DVAL_P(struc)); smart_str_appendl(buf, tmp_str, tmp_len); - /* Without a decimal point, PHP treats a number literal as an int. + * Without a decimal point, PHP treats a number literal as an int. * This check even works for scientific notation, because the * mantissa always contains a decimal point. * We need to check for finiteness, because INF, -INF and NAN * must not have a decimal point added. - */ + * if (zend_finite(Z_DVAL_P(struc)) && NULL == strchr(tmp_str, '.')) { smart_str_appendl(buf, ".0", 2); } efree(tmp_str); + */ + if (PG(serialize_precision < 0)) { + php_0cvt(Z_DVAL_P(struc), 17, '.', 'E', tmp_str); + } else { + php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', tmp_str); + } + smart_str_appends(buf, tmp_str); break; case IS_STRING: ztmp = php_addcslashes(Z_STR_P(struc), 0, "'\\", 2); @@ -844,16 +851,17 @@ again: return; case IS_DOUBLE: { - char *s; - - smart_str_appendl(buf, "d:", 2); - s = (char *) safe_emalloc(PG(serialize_precision), 1, MAX_LENGTH_OF_DOUBLE + 1); - php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', s); - smart_str_appends(buf, s); - smart_str_appendc(buf, ';'); - efree(s); - return; + char tmp_str[2048]; /* Use the same magic number of spprintf.c NUM_BUF_SIZE */ + smart_str_appendl(buf, "d:", 2); + if (PG(serialize_precision < 0)) { + php_0cvt(Z_DVAL_P(struc), 17, '.', 'E', tmp_str); + } else { + php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', tmp_str); } + smart_str_appends(buf, tmp_str); + smart_str_appendc(buf, ';'); + return; + } case IS_STRING: php_var_serialize_string(buf, Z_STRVAL_P(struc), Z_STRLEN_P(struc)); |