summaryrefslogtreecommitdiff
path: root/ext/json/json.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/json/json.c')
-rw-r--r--ext/json/json.c81
1 files changed, 15 insertions, 66 deletions
diff --git a/ext/json/json.c b/ext/json/json.c
index 8474642266..1797c00c9c 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
@@ -29,61 +27,16 @@
#include "php_json.h"
#include "php_json_encoder.h"
#include "php_json_parser.h"
+#include "json_arginfo.h"
#include <zend_exceptions.h>
static PHP_MINFO_FUNCTION(json);
-static PHP_FUNCTION(json_encode);
-static PHP_FUNCTION(json_decode);
-static PHP_FUNCTION(json_last_error);
-static PHP_FUNCTION(json_last_error_msg);
PHP_JSON_API zend_class_entry *php_json_serializable_ce;
PHP_JSON_API zend_class_entry *php_json_exception_ce;
PHP_JSON_API ZEND_DECLARE_MODULE_GLOBALS(json)
-/* {{{ arginfo */
-ZEND_BEGIN_ARG_INFO_EX(arginfo_json_encode, 0, 0, 1)
- ZEND_ARG_INFO(0, value)
- ZEND_ARG_INFO(0, options)
- ZEND_ARG_INFO(0, depth)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_json_decode, 0, 0, 1)
- ZEND_ARG_INFO(0, json)
- ZEND_ARG_INFO(0, assoc)
- ZEND_ARG_INFO(0, depth)
- ZEND_ARG_INFO(0, options)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO(arginfo_json_last_error, 0)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO(arginfo_json_last_error_msg, 0)
-ZEND_END_ARG_INFO()
-/* }}} */
-
-/* {{{ json_functions[] */
-static const zend_function_entry json_functions[] = {
- PHP_FE(json_encode, arginfo_json_encode)
- PHP_FE(json_decode, arginfo_json_decode)
- PHP_FE(json_last_error, arginfo_json_last_error)
- PHP_FE(json_last_error_msg, arginfo_json_last_error_msg)
- PHP_FE_END
-};
-/* }}} */
-
-/* {{{ JsonSerializable methods */
-ZEND_BEGIN_ARG_INFO(json_serialize_arginfo, 0)
- /* No arguments */
-ZEND_END_ARG_INFO();
-
-static const zend_function_entry json_serializable_interface[] = {
- PHP_ABSTRACT_ME(JsonSerializable, jsonSerialize, json_serialize_arginfo)
- PHP_FE_END
-};
-/* }}} */
-
/* Register constant for options and errors */
#define PHP_JSON_REGISTER_CONSTANT(_name, _value) \
REGISTER_LONG_CONSTANT(_name, _value, CONST_CS | CONST_PERSISTENT);
@@ -93,7 +46,7 @@ static PHP_MINIT_FUNCTION(json)
{
zend_class_entry ce;
- INIT_CLASS_ENTRY(ce, "JsonSerializable", json_serializable_interface);
+ INIT_CLASS_ENTRY(ce, "JsonSerializable", class_JsonSerializable_methods);
php_json_serializable_ce = zend_register_internal_interface(&ce);
INIT_CLASS_ENTRY(ce, "JsonException", NULL);
@@ -158,7 +111,7 @@ static PHP_GINIT_FUNCTION(json)
zend_module_entry json_module_entry = {
STANDARD_MODULE_HEADER,
"json",
- json_functions,
+ ext_functions,
PHP_MINIT(json),
NULL,
NULL,
@@ -242,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, char *str, size_t str_len, zend_long options, zend_long depth) /* {{{ */
+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_parser parser;
@@ -265,7 +218,7 @@ PHP_JSON_API int php_json_decode_ex(zval *return_value, char *str, size_t str_le
/* {{{ proto string json_encode(mixed data [, int options[, int depth]])
Returns the JSON representation of a value */
-static PHP_FUNCTION(json_encode)
+PHP_FUNCTION(json_encode)
{
zval *parameter;
php_json_encoder encoder;
@@ -294,7 +247,7 @@ static PHP_FUNCTION(json_encode)
if (encoder.error_code != PHP_JSON_ERROR_NONE) {
smart_str_free(&buf);
zend_throw_exception(php_json_exception_ce, php_json_get_error_msg(encoder.error_code), encoder.error_code);
- RETURN_FALSE;
+ RETURN_THROWS();
}
}
@@ -308,7 +261,7 @@ static PHP_FUNCTION(json_encode)
/* {{{ proto mixed json_decode(string json [, bool assoc [, int depth]])
Decodes the JSON representation into a PHP value */
-static PHP_FUNCTION(json_decode)
+PHP_FUNCTION(json_decode)
{
char *str;
size_t str_len;
@@ -339,13 +292,13 @@ static PHP_FUNCTION(json_decode)
}
if (depth <= 0) {
- php_error_docref(NULL, E_WARNING, "Depth must be greater than zero");
- RETURN_NULL();
+ zend_argument_value_error(3, "must be greater than 0");
+ RETURN_THROWS();
}
if (depth > INT_MAX) {
- php_error_docref(NULL, E_WARNING, "Depth must be lower than %d", INT_MAX);
- RETURN_NULL();
+ zend_argument_value_error(3, "must be less than %d", INT_MAX);
+ RETURN_THROWS();
}
/* For BC reasons, the bool $assoc overrides the long $options bit for PHP_JSON_OBJECT_AS_ARRAY */
@@ -363,11 +316,9 @@ static PHP_FUNCTION(json_decode)
/* {{{ proto int json_last_error()
Returns the error code of the last json_encode() or json_decode() call. */
-static PHP_FUNCTION(json_last_error)
+PHP_FUNCTION(json_last_error)
{
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_NONE();
RETURN_LONG(JSON_G(error_code));
}
@@ -375,11 +326,9 @@ static PHP_FUNCTION(json_last_error)
/* {{{ proto string json_last_error_msg()
Returns the error string of the last json_encode() or json_decode() call. */
-static PHP_FUNCTION(json_last_error_msg)
+PHP_FUNCTION(json_last_error_msg)
{
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
+ ZEND_PARSE_PARAMETERS_NONE();
RETURN_STRING(php_json_get_error_msg(JSON_G(error_code)));
}