summaryrefslogtreecommitdiff
path: root/ext/json
diff options
context:
space:
mode:
authorJakub Zelenka <bukka@php.net>2014-12-27 19:42:04 +0000
committerJakub Zelenka <bukka@php.net>2014-12-27 19:42:04 +0000
commitb68da91d52801fb2cc4d2a4a44c859ea5b6c622b (patch)
tree290f7c8ea7fd2df02c995b07c1d490c2de333db5 /ext/json
parent4f6539bdaf62f0343f4ec67638d2f96e8c1c00ae (diff)
parenta9e86957c70c181e830ba05bb030c468d0cb15e1 (diff)
downloadphp-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')
-rw-r--r--ext/json/config.m42
-rw-r--r--ext/json/config.w329
-rw-r--r--ext/json/json.c25
-rw-r--r--ext/json/json_encoder.c68
-rw-r--r--ext/json/json_parser.y8
-rw-r--r--ext/json/json_scanner.re2
-rw-r--r--ext/json/php_json.h14
-rw-r--r--ext/json/php_json_encoder.h2
-rw-r--r--ext/json/php_json_parser.h5
-rw-r--r--ext/json/php_json_scanner.h2
10 files changed, 67 insertions, 70 deletions
diff --git a/ext/json/config.m4 b/ext/json/config.m4
index 805330cea5..fb87a93992 100644
--- a/ext/json/config.m4
+++ b/ext/json/config.m4
@@ -14,7 +14,7 @@ PHP_NEW_EXTENSION(json,
json_encoder.c \
json_parser.tab.c \
json_scanner.c,
- $ext_shared)
+ $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
PHP_INSTALL_HEADERS([ext/json], [php_json.h])
PHP_ADD_MAKEFILE_FRAGMENT()
PHP_SUBST(JSON_SHARED_LIBADD)
diff --git a/ext/json/config.w32 b/ext/json/config.w32
index a6c54e654f..996b86829d 100644
--- a/ext/json/config.w32
+++ b/ext/json/config.w32
@@ -4,13 +4,8 @@
ARG_ENABLE("json", "JavaScript Object Serialization support", "yes");
if (PHP_JSON != "no") {
- EXTENSION('json', 'json.c', PHP_JSON_SHARED, "");
- PHP_NEW_EXTENSION(json,
- json.c \
- json_encoder.c \
- json_parser.tab.c \
- json_scanner.c,
- $ext_shared)
+ EXTENSION('json', 'json.c', PHP_JSON_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
+ ADD_SOURCES(configure_module_dirname, "json_encoder.c json_parser.tab.c json_scanner.c", "json");
PHP_INSTALL_HEADERS("ext/json/", "php_json.h");
}
diff --git a/ext/json/json.c b/ext/json/json.c
index f59daceda1..819a6dfe8e 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -90,7 +90,7 @@ static PHP_MINIT_FUNCTION(json)
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "JsonSerializable", json_serializable_interface);
- php_json_serializable_ce = zend_register_internal_interface(&ce TSRMLS_CC);
+ php_json_serializable_ce = zend_register_internal_interface(&ce);
REGISTER_LONG_CONSTANT("JSON_HEX_TAG", PHP_JSON_HEX_TAG, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("JSON_HEX_AMP", PHP_JSON_HEX_AMP, CONST_CS | CONST_PERSISTENT);
@@ -124,6 +124,9 @@ static PHP_MINIT_FUNCTION(json)
*/
static PHP_GINIT_FUNCTION(json)
{
+#if defined(COMPILE_DL_JSON) && defined(ZTS)
+ ZEND_TSRMLS_CACHE_UPDATE;
+#endif
json_globals->encoder_depth = 0;
json_globals->error_code = 0;
json_globals->encode_max_depth = 0;
@@ -152,6 +155,9 @@ zend_module_entry json_module_entry = {
/* }}} */
#ifdef COMPILE_DL_JSON
+#ifdef ZTS
+ZEND_TSRMLS_CACHE_DEFINE;
+#endif
ZEND_GET_MODULE(json)
#endif
@@ -166,18 +172,17 @@ static PHP_MINFO_FUNCTION(json)
}
/* }}} */
-
-PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options TSRMLS_DC) /* {{{ */
+PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */
{
- php_json_encode_zval(buf, val, options TSRMLS_CC);
+ php_json_encode_zval(buf, val, options);
}
/* }}} */
-PHP_JSON_API void php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long options, zend_long depth TSRMLS_DC) /* {{{ */
+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_parser parser;
- php_json_parser_init(&parser, return_value, str, str_len, options, depth TSRMLS_CC);
+ php_json_parser_init(&parser, return_value, str, str_len, options, depth);
if (php_json_yyparse(&parser)) {
JSON_G(error_code) = php_json_parser_error_code(&parser);
@@ -195,7 +200,7 @@ static PHP_FUNCTION(json_encode)
zend_long options = 0;
zend_long depth = PHP_JSON_PARSER_DEFAULT_DEPTH;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ll", &parameter, &options, &depth) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|ll", &parameter, &options, &depth) == FAILURE) {
return;
}
@@ -203,7 +208,7 @@ static PHP_FUNCTION(json_encode)
JSON_G(encode_max_depth) = depth;
- php_json_encode(&buf, parameter, options TSRMLS_CC);
+ php_json_encode(&buf, parameter, options);
if (JSON_G(error_code) != PHP_JSON_ERROR_NONE && !(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) {
smart_str_free(&buf);
@@ -225,7 +230,7 @@ static PHP_FUNCTION(json_decode)
zend_long depth = PHP_JSON_PARSER_DEFAULT_DEPTH;
zend_long options = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|bll", &str, &str_len, &assoc, &depth, &options) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|bll", &str, &str_len, &assoc, &depth, &options) == FAILURE) {
return;
}
@@ -242,7 +247,7 @@ static PHP_FUNCTION(json_decode)
options &= ~PHP_JSON_OBJECT_AS_ARRAY;
}
- php_json_decode_ex(return_value, str, str_len, options, depth TSRMLS_CC);
+ php_json_decode_ex(return_value, str, str_len, options, depth);
}
/* }}} */
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:
diff --git a/ext/json/json_parser.y b/ext/json/json_parser.y
index dbacc3d483..4af46ecbd1 100644
--- a/ext/json/json_parser.y
+++ b/ext/json/json_parser.y
@@ -158,14 +158,13 @@ errlex:
%% /* Functions */
-void php_json_parser_init(php_json_parser *parser, zval *return_value, char *str, int str_len, long options, long max_depth TSRMLS_DC)
+void php_json_parser_init(php_json_parser *parser, zval *return_value, char *str, int str_len, long options, long max_depth)
{
memset(parser, 0, sizeof(php_json_parser));
php_json_scanner_init(&parser->scanner, str, str_len, options);
parser->depth = 1;
parser->max_depth = max_depth;
parser->return_value = return_value;
- TSRMLS_SET_CTX(parser->zts_ctx);
}
php_json_error_code php_json_parser_error_code(php_json_parser *parser)
@@ -175,7 +174,6 @@ php_json_error_code php_json_parser_error_code(php_json_parser *parser)
void php_json_parser_object_init(php_json_parser *parser, zval *object)
{
- TSRMLS_FETCH_FROM_CTX(parser->zts_ctx);
if (parser->scanner.options & PHP_JSON_OBJECT_AS_ARRAY) {
array_init(object);
} else {
@@ -187,7 +185,6 @@ void php_json_parser_object_update(php_json_parser *parser, zval *object, zval *
{
char *key = Z_STRVAL_P(zkey);
int key_len = Z_STRLEN_P(zkey);
- TSRMLS_FETCH_FROM_CTX(parser->zts_ctx);
if (parser->scanner.options & PHP_JSON_OBJECT_AS_ARRAY) {
add_assoc_zval_ex(object, key, key_len, zvalue);
@@ -217,8 +214,7 @@ void php_json_parser_array_append(zval *array, zval *zvalue)
int php_json_yylex(union YYSTYPE *value, php_json_parser *parser)
{
- TSRMLS_FETCH_FROM_CTX(parser->zts_ctx);
- int token = php_json_scan(&parser->scanner TSRMLS_CC);
+ int token = php_json_scan(&parser->scanner);
value->value = parser->scanner.value;
return token;
}
diff --git a/ext/json/json_scanner.re b/ext/json/json_scanner.re
index 79df12413c..0592da83fd 100644
--- a/ext/json/json_scanner.re
+++ b/ext/json/json_scanner.re
@@ -89,7 +89,7 @@ void php_json_scanner_init(php_json_scanner *s, char *str, int str_len, long opt
PHP_JSON_CONDITION_SET(JS);
}
-int php_json_scan(php_json_scanner *s TSRMLS_DC)
+int php_json_scan(php_json_scanner *s)
{
ZVAL_NULL(&s->value);
diff --git a/ext/json/php_json.h b/ext/json/php_json.h
index 2e0bc1b2ee..25c799b383 100644
--- a/ext/json/php_json.h
+++ b/ext/json/php_json.h
@@ -78,8 +78,12 @@ ZEND_BEGIN_MODULE_GLOBALS(json)
php_json_error_code error_code;
ZEND_END_MODULE_GLOBALS(json)
+
#ifdef ZTS
-# define JSON_G(v) TSRMG(json_globals_id, zend_json_globals *, v)
+# define JSON_G(v) ZEND_TSRMG(json_globals_id, zend_json_globals *, v)
+# ifdef COMPILE_DL_JSON
+ZEND_TSRMLS_CACHE_EXTERN;
+# endif
#else
# define JSON_G(v) (json_globals.v)
#endif
@@ -88,12 +92,12 @@ ZEND_END_MODULE_GLOBALS(json)
#define PHP_JSON_OBJECT_AS_ARRAY (1<<0)
#define PHP_JSON_BIGINT_AS_STRING (1<<1)
-PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options TSRMLS_DC);
-PHP_JSON_API void php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long options, zend_long depth TSRMLS_DC);
+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);
-static inline void php_json_decode(zval *return_value, char *str, int str_len, zend_bool assoc, zend_long depth TSRMLS_DC)
+static inline void 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 TSRMLS_CC);
+ php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth);
}
diff --git a/ext/json/php_json_encoder.h b/ext/json/php_json_encoder.h
index 4f2b9ccc23..db81262a02 100644
--- a/ext/json/php_json_encoder.h
+++ b/ext/json/php_json_encoder.h
@@ -22,6 +22,6 @@
#include "php.h"
#include "zend_smart_str.h"
-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);
#endif /* PHP_JSON_ENCODER_H */
diff --git a/ext/json/php_json_parser.h b/ext/json/php_json_parser.h
index 7912b79b9c..08c3ee1287 100644
--- a/ext/json/php_json_parser.h
+++ b/ext/json/php_json_parser.h
@@ -27,12 +27,9 @@ typedef struct _php_json_parser {
zval *return_value;
long depth;
long max_depth;
-#if ZTS
- void *zts_ctx;
-#endif
} php_json_parser;
-void php_json_parser_init(php_json_parser *parser, zval *return_value, char *str, int str_len, long options, long max_depth TSRMLS_DC);
+void php_json_parser_init(php_json_parser *parser, zval *return_value, char *str, int str_len, long options, long max_depth);
php_json_error_code php_json_parser_error_code(php_json_parser *parser);
diff --git a/ext/json/php_json_scanner.h b/ext/json/php_json_scanner.h
index 203465466b..fbf65eac70 100644
--- a/ext/json/php_json_scanner.h
+++ b/ext/json/php_json_scanner.h
@@ -41,7 +41,7 @@ typedef struct _php_json_scanner {
void php_json_scanner_init(php_json_scanner *scanner, char *str, int str_len, long options);
-int php_json_scan(php_json_scanner *s TSRMLS_DC);
+int php_json_scan(php_json_scanner *s);
#endif /* PHP_JSON_SCANNER_H */