mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Use more appropriate types in JSON extension (#8194)
Mainly zend_result
This commit is contained in:
parent
27be6c34b5
commit
ec53e17adf
4 changed files with 17 additions and 17 deletions
|
@ -141,10 +141,10 @@ static PHP_MINFO_FUNCTION(json)
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth) /* {{{ */
|
PHP_JSON_API zend_result php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth) /* {{{ */
|
||||||
{
|
{
|
||||||
php_json_encoder encoder;
|
php_json_encoder encoder;
|
||||||
int return_code;
|
zend_result return_code;
|
||||||
|
|
||||||
php_json_encode_init(&encoder);
|
php_json_encode_init(&encoder);
|
||||||
encoder.max_depth = depth;
|
encoder.max_depth = depth;
|
||||||
|
@ -156,7 +156,7 @@ PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */
|
PHP_JSON_API zend_result php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */
|
||||||
{
|
{
|
||||||
return php_json_encode_ex(buf, val, options, JSON_G(encode_max_depth));
|
return php_json_encode_ex(buf, val, options, JSON_G(encode_max_depth));
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ static const char *php_json_get_error_msg(php_json_error_code error_code) /* {{{
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
PHP_JSON_API int php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth) /* {{{ */
|
PHP_JSON_API zend_result php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth) /* {{{ */
|
||||||
{
|
{
|
||||||
php_json_parser parser;
|
php_json_parser parser;
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
static const char digits[] = "0123456789abcdef";
|
static const char digits[] = "0123456789abcdef";
|
||||||
|
|
||||||
static int php_json_escape_string(
|
static zend_result php_json_escape_string(
|
||||||
smart_str *buf, const char *s, size_t len,
|
smart_str *buf, const char *s, size_t len,
|
||||||
int options, php_json_encoder *encoder);
|
int options, php_json_encoder *encoder);
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ static inline void php_json_pretty_print_indent(smart_str *buf, int options, php
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static inline int php_json_is_valid_double(double d) /* {{{ */
|
static inline bool php_json_is_valid_double(double d) /* {{{ */
|
||||||
{
|
{
|
||||||
return !zend_isinf(d) && !zend_isnan(d);
|
return !zend_isinf(d) && !zend_isnan(d);
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ static inline void php_json_encode_double(smart_str *buf, double d, int options)
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static int php_json_encode_array(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
|
static zend_result php_json_encode_array(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
|
||||||
{
|
{
|
||||||
int i, r, need_comma = 0;
|
int i, r, need_comma = 0;
|
||||||
HashTable *myht, *prop_ht;
|
HashTable *myht, *prop_ht;
|
||||||
|
@ -312,7 +312,7 @@ static int php_json_encode_array(smart_str *buf, zval *val, int options, php_jso
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static int php_json_escape_string(
|
static zend_result php_json_escape_string(
|
||||||
smart_str *buf, const char *s, size_t len,
|
smart_str *buf, const char *s, size_t len,
|
||||||
int options, php_json_encoder *encoder) /* {{{ */
|
int options, php_json_encoder *encoder) /* {{{ */
|
||||||
{
|
{
|
||||||
|
@ -525,12 +525,12 @@ static int php_json_escape_string(
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static int php_json_encode_serializable_object(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
|
static zend_result php_json_encode_serializable_object(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
|
||||||
{
|
{
|
||||||
zend_class_entry *ce = Z_OBJCE_P(val);
|
zend_class_entry *ce = Z_OBJCE_P(val);
|
||||||
HashTable* myht = Z_OBJPROP_P(val);
|
HashTable* myht = Z_OBJPROP_P(val);
|
||||||
zval retval, fname;
|
zval retval, fname;
|
||||||
int return_code;
|
zend_result return_code;
|
||||||
|
|
||||||
if (myht && GC_IS_RECURSIVE(myht)) {
|
if (myht && GC_IS_RECURSIVE(myht)) {
|
||||||
encoder->error_code = PHP_JSON_ERROR_RECURSION;
|
encoder->error_code = PHP_JSON_ERROR_RECURSION;
|
||||||
|
@ -587,7 +587,7 @@ static int php_json_encode_serializable_object(smart_str *buf, zval *val, int op
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static int php_json_encode_serializable_enum(smart_str *buf, zval *val, int options, php_json_encoder *encoder)
|
static zend_result php_json_encode_serializable_enum(smart_str *buf, zval *val, int options, php_json_encoder *encoder)
|
||||||
{
|
{
|
||||||
zend_class_entry *ce = Z_OBJCE_P(val);
|
zend_class_entry *ce = Z_OBJCE_P(val);
|
||||||
if (ce->enum_backing_type == IS_UNDEF) {
|
if (ce->enum_backing_type == IS_UNDEF) {
|
||||||
|
@ -600,7 +600,7 @@ static int php_json_encode_serializable_enum(smart_str *buf, zval *val, int opti
|
||||||
return php_json_encode_zval(buf, value_zv, options, encoder);
|
return php_json_encode_zval(buf, value_zv, options, encoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
int php_json_encode_zval(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
|
zend_result php_json_encode_zval(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
|
||||||
{
|
{
|
||||||
again:
|
again:
|
||||||
switch (Z_TYPE_P(val))
|
switch (Z_TYPE_P(val))
|
||||||
|
|
|
@ -97,11 +97,11 @@ PHP_JSON_API ZEND_EXTERN_MODULE_GLOBALS(json)
|
||||||
ZEND_TSRMLS_CACHE_EXTERN()
|
ZEND_TSRMLS_CACHE_EXTERN()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth);
|
PHP_JSON_API zend_result 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 zend_result php_json_encode(smart_str *buf, zval *val, int options);
|
||||||
PHP_JSON_API int php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth);
|
PHP_JSON_API zend_result php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth);
|
||||||
|
|
||||||
static inline int php_json_decode(zval *return_value, const char *str, int str_len, bool assoc, zend_long depth)
|
static inline zend_result php_json_decode(zval *return_value, const char *str, size_t str_len, bool assoc, zend_long depth)
|
||||||
{
|
{
|
||||||
return 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,6 @@ static inline void php_json_encode_init(php_json_encoder *encoder)
|
||||||
memset(encoder, 0, sizeof(php_json_encoder));
|
memset(encoder, 0, sizeof(php_json_encoder));
|
||||||
}
|
}
|
||||||
|
|
||||||
int php_json_encode_zval(smart_str *buf, zval *val, int options, php_json_encoder *encoder);
|
zend_result php_json_encode_zval(smart_str *buf, zval *val, int options, php_json_encoder *encoder);
|
||||||
|
|
||||||
#endif /* PHP_JSON_ENCODER_H */
|
#endif /* PHP_JSON_ENCODER_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue