]> granicus.if.org Git - php/commitdiff
Add return code from json API functions
authorJakub Zelenka <bukka@php.net>
Tue, 28 Jun 2016 19:49:38 +0000 (20:49 +0100)
committerJakub Zelenka <bukka@php.net>
Tue, 28 Jun 2016 19:49:38 +0000 (20:49 +0100)
It will allow fix few json bugs in a better way

ext/json/json.c
ext/json/php_json.h

index 8bb5e51d4159b409320f5265e99a4fcd9a4e387f..e8b111b28c3b08139bb10a8842fb7c51a34d607c 100644 (file)
@@ -184,13 +184,15 @@ static PHP_MINFO_FUNCTION(json)
 }
 /* }}} */
 
-PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */
+PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */
 {
        php_json_encode_zval(buf, val, options);
+
+       return JSON_G(error_code) > 0 ? FAILURE : SUCCESS;
 }
 /* }}} */
 
-PHP_JSON_API void php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long options, zend_long 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;
 
@@ -198,8 +200,11 @@ PHP_JSON_API void php_json_decode_ex(zval *return_value, char *str, size_t str_l
 
        if (php_json_yyparse(&parser)) {
                JSON_G(error_code) = php_json_parser_error_code(&parser);
-               RETURN_NULL();
+               RETVAL_NULL();
+               return FAILURE;
        }
+
+       return SUCCESS;
 }
 /* }}} */
 
index d1fabd1e6b60af5a22c2e2353df618e77d74be51..045ca02f4ab7b9db91a3dfa983f069c9659477a1 100644 (file)
@@ -93,12 +93,12 @@ PHP_JSON_API ZEND_EXTERN_MODULE_GLOBALS(json)
 ZEND_TSRMLS_CACHE_EXTERN()
 #endif
 
-PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options);
-PHP_JSON_API void php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long 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);
 
-static inline void php_json_decode(zval *return_value, char *str, int str_len, zend_bool assoc, zend_long depth)
+static inline int php_json_decode(zval *return_value, char *str, int str_len, zend_bool assoc, zend_long depth)
 {
-       php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth);
+       return php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth);
 }