diff options
Diffstat (limited to 'ext/json/json.c')
-rw-r--r-- | ext/json/json.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/ext/json/json.c b/ext/json/json.c index 395f11db53..202296c65c 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -186,7 +186,17 @@ static PHP_MINFO_FUNCTION(json) PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */ { - return php_json_encode_zval(buf, val, options); + php_json_encoder encoder; + int return_code; + + php_json_encode_init(&encoder); + encoder.max_depth = JSON_G(encode_max_depth); + encoder.error_code = PHP_JSON_ERROR_NONE; + + return_code = php_json_encode_zval(buf, val, options, &encoder); + JSON_G(error_code) = encoder.error_code; + + return return_code; } /* }}} */ @@ -211,6 +221,7 @@ PHP_JSON_API int php_json_decode_ex(zval *return_value, char *str, size_t str_le static PHP_FUNCTION(json_encode) { zval *parameter; + php_json_encoder encoder; smart_str buf = {0}; zend_long options = 0; zend_long depth = PHP_JSON_PARSER_DEFAULT_DEPTH; @@ -219,22 +230,22 @@ static PHP_FUNCTION(json_encode) return; } - JSON_G(error_code) = PHP_JSON_ERROR_NONE; - - JSON_G(encode_max_depth) = (int)depth; + php_json_encode_init(&encoder); + encoder.max_depth = (int)depth; + encoder.error_code = PHP_JSON_ERROR_NONE; + php_json_encode_zval(&buf, parameter, (int)options, &encoder); + JSON_G(error_code) = encoder.error_code; - php_json_encode(&buf, parameter, (int)options); - - if (JSON_G(error_code) != PHP_JSON_ERROR_NONE && !(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) { + if (encoder.error_code != PHP_JSON_ERROR_NONE && !(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) { smart_str_free(&buf); - ZVAL_FALSE(return_value); - } else { - smart_str_0(&buf); /* copy? */ - if (buf.s) { - RETURN_NEW_STR(buf.s); - } - RETURN_EMPTY_STRING(); + RETURN_FALSE; + } + + smart_str_0(&buf); /* copy? */ + if (buf.s) { + RETURN_NEW_STR(buf.s); } + RETURN_EMPTY_STRING(); } /* }}} */ |