Skip to content

Commit bea131f

Browse files
committed
Add return code from json API functions
It will allow fix few json bugs in a better way
1 parent 0a4f89b commit bea131f

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

ext/json/json.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,27 @@ static PHP_MINFO_FUNCTION(json)
184184
}
185185
/* }}} */
186186

187-
PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */
187+
PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */
188188
{
189189
php_json_encode_zval(buf, val, options);
190+
191+
return JSON_G(error_code) > 0 ? FAILURE : SUCCESS;
190192
}
191193
/* }}} */
192194

193-
PHP_JSON_API void php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long options, zend_long depth) /* {{{ */
195+
PHP_JSON_API int php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long options, zend_long depth) /* {{{ */
194196
{
195197
php_json_parser parser;
196198

197199
php_json_parser_init(&parser, return_value, str, str_len, (int)options, (int)depth);
198200

199201
if (php_json_yyparse(&parser)) {
200202
JSON_G(error_code) = php_json_parser_error_code(&parser);
201-
RETURN_NULL();
203+
RETVAL_NULL();
204+
return FAILURE;
202205
}
206+
207+
return SUCCESS;
203208
}
204209
/* }}} */
205210

ext/json/php_json.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ PHP_JSON_API ZEND_EXTERN_MODULE_GLOBALS(json)
9393
ZEND_TSRMLS_CACHE_EXTERN()
9494
#endif
9595

96-
PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options);
97-
PHP_JSON_API void php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long options, zend_long depth);
96+
PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options);
97+
PHP_JSON_API int php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long options, zend_long depth);
9898

99-
static inline void php_json_decode(zval *return_value, char *str, int str_len, zend_bool assoc, zend_long depth)
99+
static inline int php_json_decode(zval *return_value, char *str, int str_len, zend_bool assoc, zend_long depth)
100100
{
101-
php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth);
101+
return php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth);
102102
}
103103

104104

0 commit comments

Comments
 (0)