diff options
author | Xinchen Hui <laruence@gmail.com> | 2016-05-06 18:39:18 +0800 |
---|---|---|
committer | Xinchen Hui <laruence@gmail.com> | 2016-05-06 18:39:18 +0800 |
commit | 10f8ca9151f304cee2f95cc0946c5bebaa4684a0 (patch) | |
tree | 272088d749dd37fd54b361e4aee331f5d882ea0b /ext/json/json_encoder.c | |
parent | 8ae695cd7515af0bcb84844392b5b00910d5cf5b (diff) | |
parent | 459a7cc209da130256d66c1f896199540f4dadbc (diff) | |
download | php-git-10f8ca9151f304cee2f95cc0946c5bebaa4684a0.tar.gz |
Merge branch 'PHP-7.0'
* PHP-7.0:
Fixed bug #72170 (JsonSerializable may inc apply count without dec it)
Diffstat (limited to 'ext/json/json_encoder.c')
-rw-r--r-- | ext/json/json_encoder.c | 83 |
1 files changed, 45 insertions, 38 deletions
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c index 62df102847..d6c3ed299b 100644 --- a/ext/json/json_encoder.c +++ b/ext/json/json_encoder.c @@ -157,26 +157,8 @@ static void php_json_encode_array(smart_str *buf, zval *val, int options) /* {{{ ZEND_HASH_INC_APPLY_COUNT(tmp_ht); } - if (r == PHP_JSON_OUTPUT_ARRAY) { - if (need_comma) { - smart_str_appendc(buf, ','); - } else { - need_comma = 1; - } - - php_json_pretty_print_char(buf, options, '\n'); - php_json_pretty_print_indent(buf, options); - php_json_encode(buf, data, options); - } else if (r == PHP_JSON_OUTPUT_OBJECT) { - if (key) { - if (ZSTR_VAL(key)[0] == '\0' && Z_TYPE_P(val) == IS_OBJECT) { - /* Skip protected and private members. */ - if (tmp_ht && ZEND_HASH_APPLY_PROTECTION(tmp_ht)) { - ZEND_HASH_DEC_APPLY_COUNT(tmp_ht); - } - continue; - } - + zend_try { + if (r == PHP_JSON_OUTPUT_ARRAY) { if (need_comma) { smart_str_appendc(buf, ','); } else { @@ -185,33 +167,58 @@ static void php_json_encode_array(smart_str *buf, zval *val, int options) /* {{{ php_json_pretty_print_char(buf, options, '\n'); php_json_pretty_print_indent(buf, options); + php_json_encode(buf, data, options); + } else if (r == PHP_JSON_OUTPUT_OBJECT) { + if (key) { + if (ZSTR_VAL(key)[0] == '\0' && Z_TYPE_P(val) == IS_OBJECT) { + /* Skip protected and private members. */ + if (tmp_ht && ZEND_HASH_APPLY_PROTECTION(tmp_ht)) { + ZEND_HASH_DEC_APPLY_COUNT(tmp_ht); + } + continue; + } - php_json_escape_string(buf, ZSTR_VAL(key), ZSTR_LEN(key), options & ~PHP_JSON_NUMERIC_CHECK); - smart_str_appendc(buf, ':'); + if (need_comma) { + smart_str_appendc(buf, ','); + } else { + need_comma = 1; + } - php_json_pretty_print_char(buf, options, ' '); + php_json_pretty_print_char(buf, options, '\n'); + php_json_pretty_print_indent(buf, options); - php_json_encode(buf, data, options); - } else { - if (need_comma) { - smart_str_appendc(buf, ','); + php_json_escape_string(buf, ZSTR_VAL(key), ZSTR_LEN(key), options & ~PHP_JSON_NUMERIC_CHECK); + smart_str_appendc(buf, ':'); + + php_json_pretty_print_char(buf, options, ' '); + + php_json_encode(buf, data, options); } else { - need_comma = 1; - } + if (need_comma) { + smart_str_appendc(buf, ','); + } else { + need_comma = 1; + } - php_json_pretty_print_char(buf, options, '\n'); - php_json_pretty_print_indent(buf, options); + php_json_pretty_print_char(buf, options, '\n'); + php_json_pretty_print_indent(buf, options); - smart_str_appendc(buf, '"'); - smart_str_append_long(buf, (zend_long) index); - smart_str_appendc(buf, '"'); - smart_str_appendc(buf, ':'); + smart_str_appendc(buf, '"'); + smart_str_append_long(buf, (zend_long) index); + smart_str_appendc(buf, '"'); + smart_str_appendc(buf, ':'); - php_json_pretty_print_char(buf, options, ' '); + php_json_pretty_print_char(buf, options, ' '); - php_json_encode(buf, data, options); + php_json_encode(buf, data, options); + } } - } + } zend_catch { + if (tmp_ht && ZEND_HASH_APPLY_PROTECTION(tmp_ht)) { + ZEND_HASH_DEC_APPLY_COUNT(tmp_ht); + } + zend_bailout(); + } zend_end_try(); if (tmp_ht && ZEND_HASH_APPLY_PROTECTION(tmp_ht)) { ZEND_HASH_DEC_APPLY_COUNT(tmp_ht); |