diff options
author | Jakub Zelenka <bukka@php.net> | 2014-12-27 19:42:04 +0000 |
---|---|---|
committer | Jakub Zelenka <bukka@php.net> | 2014-12-27 19:42:04 +0000 |
commit | b68da91d52801fb2cc4d2a4a44c859ea5b6c622b (patch) | |
tree | 290f7c8ea7fd2df02c995b07c1d490c2de333db5 /ext/json/json_encoder.c | |
parent | 4f6539bdaf62f0343f4ec67638d2f96e8c1c00ae (diff) | |
parent | a9e86957c70c181e830ba05bb030c468d0cb15e1 (diff) | |
download | php-git-b68da91d52801fb2cc4d2a4a44c859ea5b6c622b.tar.gz |
Merge branch 'master' into jsond
Conflicts:
ext/json/JSON_parser.c
ext/json/JSON_parser.h
ext/json/config.m4
ext/json/config.w32
ext/json/json.c
ext/json/php_json.h
Diffstat (limited to 'ext/json/json_encoder.c')
-rw-r--r-- | ext/json/json_encoder.c | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c index 6976d906c0..b9fb355a16 100644 --- a/ext/json/json_encoder.c +++ b/ext/json/json_encoder.c @@ -34,9 +34,9 @@ ZEND_DECLARE_MODULE_GLOBALS(json) static const char digits[] = "0123456789abcdef"; -static void json_escape_string(smart_str *buf, char *s, size_t len, int options TSRMLS_DC); +static void json_escape_string(smart_str *buf, char *s, size_t len, int options); -static int json_determine_array_type(zval *val TSRMLS_DC) /* {{{ */ +static int json_determine_array_type(zval *val) /* {{{ */ { int i; HashTable *myht = HASH_OF(val); @@ -65,7 +65,7 @@ static int json_determine_array_type(zval *val TSRMLS_DC) /* {{{ */ /* {{{ Pretty printing support functions */ -static inline void json_pretty_print_char(smart_str *buf, int options, char c TSRMLS_DC) /* {{{ */ +static inline void json_pretty_print_char(smart_str *buf, int options, char c) /* {{{ */ { if (options & PHP_JSON_PRETTY_PRINT) { smart_str_appendc(buf, c); @@ -73,7 +73,7 @@ static inline void json_pretty_print_char(smart_str *buf, int options, char c TS } /* }}} */ -static inline void json_pretty_print_indent(smart_str *buf, int options TSRMLS_DC) /* {{{ */ +static inline void json_pretty_print_indent(smart_str *buf, int options) /* {{{ */ { int i; @@ -87,14 +87,14 @@ static inline void json_pretty_print_indent(smart_str *buf, int options TSRMLS_D /* }}} */ -static void json_encode_array(smart_str *buf, zval *val, int options TSRMLS_DC) /* {{{ */ +static void json_encode_array(smart_str *buf, zval *val, int options) /* {{{ */ { int i, r, need_comma = 0; HashTable *myht; if (Z_TYPE_P(val) == IS_ARRAY) { myht = HASH_OF(val); - r = (options & PHP_JSON_FORCE_OBJECT) ? PHP_JSON_OUTPUT_OBJECT : json_determine_array_type(val TSRMLS_CC); + r = (options & PHP_JSON_FORCE_OBJECT) ? PHP_JSON_OUTPUT_OBJECT : json_determine_array_type(val); } else { myht = Z_OBJPROP_P(val); r = PHP_JSON_OUTPUT_OBJECT; @@ -136,9 +136,9 @@ static void json_encode_array(smart_str *buf, zval *val, int options TSRMLS_DC) need_comma = 1; } - json_pretty_print_char(buf, options, '\n' TSRMLS_CC); - json_pretty_print_indent(buf, options TSRMLS_CC); - php_json_encode(buf, data, options TSRMLS_CC); + json_pretty_print_char(buf, options, '\n'); + json_pretty_print_indent(buf, options); + php_json_encode(buf, data, options); } else if (r == PHP_JSON_OUTPUT_OBJECT) { if (key) { if (key->val[0] == '\0' && Z_TYPE_P(val) == IS_OBJECT) { @@ -155,15 +155,15 @@ static void json_encode_array(smart_str *buf, zval *val, int options TSRMLS_DC) need_comma = 1; } - json_pretty_print_char(buf, options, '\n' TSRMLS_CC); - json_pretty_print_indent(buf, options TSRMLS_CC); + json_pretty_print_char(buf, options, '\n'); + json_pretty_print_indent(buf, options); - json_escape_string(buf, key->val, key->len, options & ~PHP_JSON_NUMERIC_CHECK TSRMLS_CC); + json_escape_string(buf, key->val, key->len, options & ~PHP_JSON_NUMERIC_CHECK); smart_str_appendc(buf, ':'); - json_pretty_print_char(buf, options, ' ' TSRMLS_CC); + json_pretty_print_char(buf, options, ' '); - php_json_encode(buf, data, options TSRMLS_CC); + php_json_encode(buf, data, options); } else { if (need_comma) { smart_str_appendc(buf, ','); @@ -171,17 +171,17 @@ static void json_encode_array(smart_str *buf, zval *val, int options TSRMLS_DC) need_comma = 1; } - json_pretty_print_char(buf, options, '\n' TSRMLS_CC); - json_pretty_print_indent(buf, options TSRMLS_CC); + json_pretty_print_char(buf, options, '\n'); + json_pretty_print_indent(buf, options); smart_str_appendc(buf, '"'); smart_str_append_long(buf, (zend_long) index); smart_str_appendc(buf, '"'); smart_str_appendc(buf, ':'); - json_pretty_print_char(buf, options, ' ' TSRMLS_CC); + json_pretty_print_char(buf, options, ' '); - php_json_encode(buf, data, options TSRMLS_CC); + php_json_encode(buf, data, options); } } @@ -198,8 +198,8 @@ static void json_encode_array(smart_str *buf, zval *val, int options TSRMLS_DC) /* Only keep closing bracket on same line for empty arrays/objects */ if (need_comma) { - json_pretty_print_char(buf, options, '\n' TSRMLS_CC); - json_pretty_print_indent(buf, options TSRMLS_CC); + json_pretty_print_char(buf, options, '\n'); + json_pretty_print_indent(buf, options); } if (r == PHP_JSON_OUTPUT_ARRAY) { @@ -247,7 +247,7 @@ static int json_utf8_to_utf16(unsigned short *utf16, char utf8[], int len) /* {{ } /* }}} */ -static void json_escape_string(smart_str *buf, char *s, size_t len, int options TSRMLS_DC) /* {{{ */ +static void json_escape_string(smart_str *buf, char *s, size_t len, int options) /* {{{ */ { int status; unsigned int us, next_us = 0; @@ -287,7 +287,7 @@ static void json_escape_string(smart_str *buf, char *s, size_t len, int options if (json_utf8_to_utf16(NULL, s, len) < 0) { JSON_G(error_code) = PHP_JSON_ERROR_UTF8; smart_str_appendl(buf, "null", 4); - return; + return; } } @@ -412,12 +412,12 @@ static void json_escape_string(smart_str *buf, char *s, size_t len, int options break; } } while (pos < len || next_us); - + smart_str_appendc(buf, '"'); } /* }}} */ -static void json_encode_serializable_object(smart_str *buf, zval *val, int options TSRMLS_DC) /* {{{ */ +static void json_encode_serializable_object(smart_str *buf, zval *val, int options) /* {{{ */ { zend_class_entry *ce = Z_OBJCE_P(val); zval retval, fname; @@ -437,12 +437,12 @@ static void json_encode_serializable_object(smart_str *buf, zval *val, int optio ZVAL_STRING(&fname, "jsonSerialize"); - if (FAILURE == call_user_function_ex(EG(function_table), val, &fname, &retval, 0, NULL, 1, NULL TSRMLS_CC) || Z_TYPE(retval) == IS_UNDEF) { - zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Failed calling %s::jsonSerialize()", ce->name->val); + if (FAILURE == call_user_function_ex(EG(function_table), val, &fname, &retval, 0, NULL, 1, NULL) || Z_TYPE(retval) == IS_UNDEF) { + zend_throw_exception_ex(NULL, 0, "Failed calling %s::jsonSerialize()", ce->name->val); smart_str_appendl(buf, "null", sizeof("null") - 1); zval_ptr_dtor(&fname); return; - } + } if (EG(exception)) { /* Error already raised */ @@ -455,10 +455,10 @@ static void json_encode_serializable_object(smart_str *buf, zval *val, int optio if ((Z_TYPE(retval) == IS_OBJECT) && (Z_OBJ_HANDLE(retval) == Z_OBJ_HANDLE_P(val))) { /* Handle the case where jsonSerialize does: return $this; by going straight to encode array */ - json_encode_array(buf, &retval, options TSRMLS_CC); + json_encode_array(buf, &retval, options); } else { /* All other types, encode as normal */ - php_json_encode(buf, &retval, options TSRMLS_CC); + php_json_encode(buf, &retval, options); } zval_ptr_dtor(&retval); @@ -466,7 +466,7 @@ static void json_encode_serializable_object(smart_str *buf, zval *val, int optio } /* }}} */ -void php_json_encode_zval(smart_str *buf, zval *val, int options TSRMLS_DC) /* {{{ */ +void php_json_encode_zval(smart_str *buf, zval *val, int options) /* {{{ */ { again: switch (Z_TYPE_P(val)) @@ -504,17 +504,17 @@ again: break; case IS_STRING: - json_escape_string(buf, Z_STRVAL_P(val), Z_STRLEN_P(val), options TSRMLS_CC); + json_escape_string(buf, Z_STRVAL_P(val), Z_STRLEN_P(val), options); break; case IS_OBJECT: - if (instanceof_function(Z_OBJCE_P(val), php_json_serializable_ce TSRMLS_CC)) { - json_encode_serializable_object(buf, val, options TSRMLS_CC); + if (instanceof_function(Z_OBJCE_P(val), php_json_serializable_ce)) { + json_encode_serializable_object(buf, val, options); break; } /* fallthrough -- Non-serializable object */ case IS_ARRAY: - json_encode_array(buf, val, options TSRMLS_CC); + json_encode_array(buf, val, options); break; case IS_REFERENCE: |