com php-src: Introduce internal php_json_encode_ex to allow extensions setting depth: ext/json/json.c ext/json/php_json.h
| From: | Jakub Zelenka | Date: | Sun, 16 Jul 2017 14:47:23 +0000 |
| Subject: | com php-src: Introduce internal php_json_encode_ex to allow extensions setting depth: ext/json/json.c ext/json/php_json.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-98565@lists.php.net to get a copy of this message | ||
Commit: 9c5882265333a40dcd2fc2c2f7542f3f6df3cf65
Author: Jakub Zelenka <bukka@php.net> Sun, 16 Jul 2017 15:47:23 +0100
Parents: 0d0f7cde8c321ae841ba0f60f4377b72f98db637
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9c5882265333a40dcd2fc2c2f7542f3f6df3cf65
Log:
Introduce internal php_json_encode_ex to allow extensions setting depth
Changed paths:
M ext/json/json.c
M ext/json/php_json.h
Diff:
diff --git a/ext/json/json.c b/ext/json/json.c
index e645f7c..f996275 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -188,14 +188,13 @@ static PHP_MINFO_FUNCTION(json)
}
/* }}} */
-PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */
+PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth) /* {{{
*/
{
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;
+ encoder.max_depth = depth;
return_code = php_json_encode_zval(buf, val, options, &encoder);
JSON_G(error_code) = encoder.error_code;
@@ -204,6 +203,12 @@ PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options) /* {{{
}
/* }}} */
+PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */
+{
+ return php_json_encode_ex(buf, val, options, JSON_G(encode_max_depth));
+}
+/* }}} */
+
PHP_JSON_API int php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long
options, zend_long depth) /* {{{ */
{
php_json_parser parser;
@@ -239,7 +244,6 @@ static PHP_FUNCTION(json_encode)
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;
diff --git a/ext/json/php_json.h b/ext/json/php_json.h
index e772d8d..0a21dd2 100644
--- a/ext/json/php_json.h
+++ b/ext/json/php_json.h
@@ -97,6 +97,7 @@ PHP_JSON_API ZEND_EXTERN_MODULE_GLOBALS(json)
ZEND_TSRMLS_CACHE_EXTERN()
#endif
+PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth);
PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options);
PHP_JSON_API int php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long
options, zend_long depth);
@@ -105,7 +106,6 @@ static inline int php_json_decode(zval *return_value, char *str, int str_len, ze
return php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0,
depth);
}
-
#endif /* PHP_JSON_H */
/*