]> granicus.if.org Git - php/commitdiff
Add JSON_G(precision)
authorYasuo Ohgaki <yohgaki@ohgaki.net>
Wed, 5 Aug 2015 05:36:37 +0000 (14:36 +0900)
committerJakub Zelenka <bukka@php.net>
Sun, 26 Jun 2016 12:26:43 +0000 (13:26 +0100)
ext/json/json.c
ext/json/json_encoder.c
ext/json/php_json.h

index d3c6111d4df264870abc994abecdb0710f181c10..0cfffe8b66679e0803e79a3d86486e9b95e166ca 100644 (file)
@@ -93,6 +93,31 @@ static const zend_function_entry json_serializable_interface[] = {
 };
 /* }}} */
 
+
+/* {{{ PHP_INI_MH
+ */
+static PHP_INI_MH(OnSetJsonPrecision)
+{
+       zend_long i;
+
+       ZEND_ATOL(i, ZSTR_VAL(new_value));
+       if (i >= -1) {
+               JSON_G(precision) = i;
+               return SUCCESS;
+       } else {
+               return FAILURE;
+       }
+}
+/* }}} */
+
+
+/* {{{ PHP_INI
+ */
+PHP_INI_BEGIN()
+STD_PHP_INI_ENTRY("json.precision", "-1",  PHP_INI_ALL, OnSetJsonPrecision, precision, zend_json_globals, json_globals)
+PHP_INI_END()
+/* }}} */
+
 /* Register constant for options and errors */
 #define PHP_JSON_REGISTER_CONSTANT(_name, _value) \
        REGISTER_LONG_CONSTANT(_name,  _value, CONST_CS | CONST_PERSISTENT);
@@ -102,6 +127,8 @@ static PHP_MINIT_FUNCTION(json)
 {
        zend_class_entry ce;
 
+       REGISTER_INI_ENTRIES();
+
        INIT_CLASS_ENTRY(ce, "JsonSerializable", json_serializable_interface);
        php_json_serializable_ce = zend_register_internal_interface(&ce);
 
@@ -153,6 +180,16 @@ static PHP_GINIT_FUNCTION(json)
 }
 /* }}} */
 
+/* {{{ PHP_MSHUTDOWN_FUNCTION
+*/
+static PHP_MSHUTDOWN_FUNCTION(json)
+{
+       UNREGISTER_INI_ENTRIES();
+
+       return SUCCESS;
+}
+/* }}} */
+
 
 /* {{{ json_module_entry
  */
@@ -161,7 +198,7 @@ zend_module_entry json_module_entry = {
        "json",
        json_functions,
        PHP_MINIT(json),
-       NULL,
+       PHP_MSHUTDOWN(json),
        NULL,
        NULL,
        PHP_MINFO(json),
index 92ab413cf0202651932c83e57772a5c92160412e..cf9d9adaa2cc28ebd79ecf91a8062b188e2031d1 100644 (file)
@@ -104,10 +104,10 @@ static inline void php_json_encode_double(smart_str *buf, double d, int options)
 {
        size_t len;
        char num[PHP_JSON_DOUBLE_MAX_LENGTH];
-       if (PG(serialize_precision) == -1) {
+       if (JSON_G(precision) == -1) {
                php_0cvt(d, 17, '.', 'e', num);
        } else {
-               php_gcvt(d, PG(serialize_precision), '.', 'e', num);
+               php_gcvt(d, JSON_G(precision), '.', 'e', num);
        }
        len = strlen(num);
        if (options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < PHP_JSON_DOUBLE_MAX_LENGTH - 2) {
index d1fabd1e6b60af5a22c2e2353df618e77d74be51..2bf1c68eb449edfb4e69e129a81e81ae856b60f7 100644 (file)
@@ -81,6 +81,7 @@ typedef enum {
 #define PHP_JSON_PARSER_DEFAULT_DEPTH 512
 
 ZEND_BEGIN_MODULE_GLOBALS(json)
+       zend_long precision;
        int encoder_depth;
        int encode_max_depth;
        php_json_error_code error_code;