summaryrefslogtreecommitdiff
path: root/ext/json/json_encoder.c
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2016-05-06 20:25:43 +0800
committerXinchen Hui <laruence@gmail.com>2016-05-06 20:25:43 +0800
commited0eb2bfddfd17d63828b4b0e8ba0ca6e4d70a89 (patch)
tree7b4a1ad7db7048f0196cab7331eab6443221ceef /ext/json/json_encoder.c
parent9a43e3f4bfa74a57ad2a1f84b44597b07dec1d08 (diff)
parent197470b62f8256898adfe758302cb0241195c480 (diff)
downloadphp-git-ed0eb2bfddfd17d63828b4b0e8ba0ca6e4d70a89.tar.gz
Merge branch 'PHP-7.0'
* PHP-7.0: Revert "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.c83
1 files changed, 38 insertions, 45 deletions
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c
index d6c3ed299b..62df102847 100644
--- a/ext/json/json_encoder.c
+++ b/ext/json/json_encoder.c
@@ -157,8 +157,26 @@ static void php_json_encode_array(smart_str *buf, zval *val, int options) /* {{{
ZEND_HASH_INC_APPLY_COUNT(tmp_ht);
}
- zend_try {
- if (r == PHP_JSON_OUTPUT_ARRAY) {
+ 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;
+ }
+
if (need_comma) {
smart_str_appendc(buf, ',');
} else {
@@ -167,58 +185,33 @@ 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;
- }
-
- 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_escape_string(buf, ZSTR_VAL(key), ZSTR_LEN(key), options & ~PHP_JSON_NUMERIC_CHECK);
+ 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_pretty_print_char(buf, options, ' ');
-
- php_json_encode(buf, data, options);
+ php_json_encode(buf, data, options);
+ } else {
+ if (need_comma) {
+ smart_str_appendc(buf, ',');
} else {
- if (need_comma) {
- smart_str_appendc(buf, ',');
- } else {
- need_comma = 1;
- }
+ 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);
- }
- }
- } zend_catch {
- if (tmp_ht && ZEND_HASH_APPLY_PROTECTION(tmp_ht)) {
- ZEND_HASH_DEC_APPLY_COUNT(tmp_ht);
+ php_json_encode(buf, data, options);
}
- zend_bailout();
- } zend_end_try();
+ }
if (tmp_ht && ZEND_HASH_APPLY_PROTECTION(tmp_ht)) {
ZEND_HASH_DEC_APPLY_COUNT(tmp_ht);