Skip to content

Commit ec53e17

Browse files
authored
Use more appropriate types in JSON extension (php#8194)
Mainly zend_result
1 parent 27be6c3 commit ec53e17

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

ext/json/json.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ static PHP_MINFO_FUNCTION(json)
141141
}
142142
/* }}} */
143143

144-
PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth) /* {{{ */
144+
PHP_JSON_API zend_result php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth) /* {{{ */
145145
{
146146
php_json_encoder encoder;
147-
int return_code;
147+
zend_result return_code;
148148

149149
php_json_encode_init(&encoder);
150150
encoder.max_depth = depth;
@@ -156,7 +156,7 @@ PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend
156156
}
157157
/* }}} */
158158

159-
PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */
159+
PHP_JSON_API zend_result php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */
160160
{
161161
return php_json_encode_ex(buf, val, options, JSON_G(encode_max_depth));
162162
}
@@ -195,7 +195,7 @@ static const char *php_json_get_error_msg(php_json_error_code error_code) /* {{{
195195
}
196196
/* }}} */
197197

198-
PHP_JSON_API int php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth) /* {{{ */
198+
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) /* {{{ */
199199
{
200200
php_json_parser parser;
201201

ext/json/json_encoder.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
static const char digits[] = "0123456789abcdef";
3333

34-
static int php_json_escape_string(
34+
static zend_result php_json_escape_string(
3535
smart_str *buf, const char *s, size_t len,
3636
int options, php_json_encoder *encoder);
3737

@@ -71,7 +71,7 @@ static inline void php_json_pretty_print_indent(smart_str *buf, int options, php
7171

7272
/* }}} */
7373

74-
static inline int php_json_is_valid_double(double d) /* {{{ */
74+
static inline bool php_json_is_valid_double(double d) /* {{{ */
7575
{
7676
return !zend_isinf(d) && !zend_isnan(d);
7777
}
@@ -107,7 +107,7 @@ static inline void php_json_encode_double(smart_str *buf, double d, int options)
107107
} \
108108
} while (0)
109109

110-
static int php_json_encode_array(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
110+
static zend_result php_json_encode_array(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
111111
{
112112
int i, r, need_comma = 0;
113113
HashTable *myht, *prop_ht;
@@ -312,7 +312,7 @@ static int php_json_encode_array(smart_str *buf, zval *val, int options, php_jso
312312
}
313313
/* }}} */
314314

315-
static int php_json_escape_string(
315+
static zend_result php_json_escape_string(
316316
smart_str *buf, const char *s, size_t len,
317317
int options, php_json_encoder *encoder) /* {{{ */
318318
{
@@ -525,12 +525,12 @@ static int php_json_escape_string(
525525
}
526526
/* }}} */
527527

528-
static int php_json_encode_serializable_object(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
528+
static zend_result php_json_encode_serializable_object(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
529529
{
530530
zend_class_entry *ce = Z_OBJCE_P(val);
531531
HashTable* myht = Z_OBJPROP_P(val);
532532
zval retval, fname;
533-
int return_code;
533+
zend_result return_code;
534534

535535
if (myht && GC_IS_RECURSIVE(myht)) {
536536
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
587587
}
588588
/* }}} */
589589

590-
static int php_json_encode_serializable_enum(smart_str *buf, zval *val, int options, php_json_encoder *encoder)
590+
static zend_result php_json_encode_serializable_enum(smart_str *buf, zval *val, int options, php_json_encoder *encoder)
591591
{
592592
zend_class_entry *ce = Z_OBJCE_P(val);
593593
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
600600
return php_json_encode_zval(buf, value_zv, options, encoder);
601601
}
602602

603-
int php_json_encode_zval(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
603+
zend_result php_json_encode_zval(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
604604
{
605605
again:
606606
switch (Z_TYPE_P(val))

ext/json/php_json.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ PHP_JSON_API ZEND_EXTERN_MODULE_GLOBALS(json)
9797
ZEND_TSRMLS_CACHE_EXTERN()
9898
#endif
9999

100-
PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth);
101-
PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options);
102-
PHP_JSON_API int php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth);
100+
PHP_JSON_API zend_result php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth);
101+
PHP_JSON_API zend_result php_json_encode(smart_str *buf, zval *val, int options);
102+
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);
103103

104-
static inline int php_json_decode(zval *return_value, const char *str, int str_len, bool assoc, zend_long depth)
104+
static inline zend_result php_json_decode(zval *return_value, const char *str, size_t str_len, bool assoc, zend_long depth)
105105
{
106106
return php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth);
107107
}

ext/json/php_json_encoder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ static inline void php_json_encode_init(php_json_encoder *encoder)
3333
memset(encoder, 0, sizeof(php_json_encoder));
3434
}
3535

36-
int php_json_encode_zval(smart_str *buf, zval *val, int options, php_json_encoder *encoder);
36+
zend_result php_json_encode_zval(smart_str *buf, zval *val, int options, php_json_encoder *encoder);
3737

3838
#endif /* PHP_JSON_ENCODER_H */

0 commit comments

Comments
 (0)