summaryrefslogtreecommitdiff
path: root/Zend/zend_API.h
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2015-03-20 23:18:52 +0300
committerDmitry Stogov <dmitry@zend.com>2015-03-20 23:18:52 +0300
commit35f9b90bb839a49c67b594b23694140d04dbb270 (patch)
tree1c6fc18bef714ec3dcd4747058b02dc7c9ca3495 /Zend/zend_API.h
parent4e5767b5d710583789ac65e644e013a7fa5deda4 (diff)
downloadphp-git-35f9b90bb839a49c67b594b23694140d04dbb270.tar.gz
ZPP changed to lazely check for "strict/weak" only if it's really necessary.
Cleanup.
Diffstat (limited to 'Zend/zend_API.h')
-rw-r--r--Zend/zend_API.h178
1 files changed, 54 insertions, 124 deletions
diff --git a/Zend/zend_API.h b/Zend/zend_API.h
index 31b7b054d3..bd90e953fe 100644
--- a/Zend/zend_API.h
+++ b/Zend/zend_API.h
@@ -256,9 +256,7 @@ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array);
/* Parameter parsing API -- andrei */
-#define ZEND_PARSE_PARAMS_QUIET (1<<1)
-#define ZEND_PARSE_PARAMS_STRICT (1<<2)
-
+#define ZEND_PARSE_PARAMS_QUIET (1<<1)
ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...);
ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_spec, ...);
ZEND_API char *zend_zval_type_name(const zval *arg);
@@ -297,7 +295,6 @@ ZEND_API int zend_disable_function(char *function_name, size_t function_name_len
ZEND_API int zend_disable_class(char *class_name, size_t class_name_length);
ZEND_API void zend_wrong_param_count(void);
-ZEND_API void zend_wrong_param_count_ex(zend_bool strict);
#define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0)
#define IS_CALLABLE_CHECK_NO_ACCESS (1<<1)
@@ -707,10 +704,10 @@ typedef enum _zend_expected_type {
Z_EXPECTED_LAST
} zend_expected_type;
-ZEND_API void zend_wrong_paramers_count_error(int num_args, int min_num_args, int max_num_args, zend_bool strict);
-ZEND_API void zend_wrong_paramer_type_error(int num, zend_expected_type expected_type, zval *arg, zend_bool strict);
-ZEND_API void zend_wrong_paramer_class_error(int num, char *name, zval *arg, zend_bool strict);
-ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend_bool strict);
+ZEND_API void ZEND_FASTCALL zend_wrong_paramers_count_error(int num_args, int min_num_args, int max_num_args);
+ZEND_API void ZEND_FASTCALL zend_wrong_paramer_type_error(int num, zend_expected_type expected_type, zval *arg);
+ZEND_API void ZEND_FASTCALL zend_wrong_paramer_class_error(int num, char *name, zval *arg);
+ZEND_API void ZEND_FASTCALL zend_wrong_callback_error(int severity, int num, char *error);
#define ZPP_ERROR_OK 0
#define ZPP_ERROR_FAILURE 1
@@ -720,8 +717,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
#define ZPP_ERROR_WRONG_COUNT 5
#define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
- zend_bool _strict = ZEND_ARG_USES_STRICT_TYPES(); \
- const int _flags = (flags) | (_strict ? ZEND_PARSE_PARAMS_STRICT : 0); \
+ const int _flags = (flags); \
int _min_num_args = (min_num_args); \
int _max_num_args = (max_num_args); \
int _num_args = EX_NUM_ARGS(); \
@@ -745,7 +741,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
(UNEXPECTED(_num_args > _max_num_args) && \
EXPECTED(_max_num_args >= 0))) { \
if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
- zend_wrong_paramers_count_error(_num_args, _min_num_args, _max_num_args, _strict); \
+ zend_wrong_paramers_count_error(_num_args, _min_num_args, _max_num_args); \
} \
error_code = ZPP_ERROR_FAILURE; \
break; \
@@ -761,11 +757,11 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
if (UNEXPECTED(error_code != ZPP_ERROR_OK)) { \
if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
if (error_code == ZPP_ERROR_WRONG_CALLBACK) { \
- zend_wrong_callback_error(E_WARNING, _i, _error, _strict); \
+ zend_wrong_callback_error(E_WARNING, _i, _error); \
} else if (error_code == ZPP_ERROR_WRONG_CLASS) { \
- zend_wrong_paramer_class_error(_i, _error, _arg, _strict); \
+ zend_wrong_paramer_class_error(_i, _error, _arg); \
} else if (error_code == ZPP_ERROR_WRONG_ARG) { \
- zend_wrong_paramer_type_error(_i, _expected_type, _arg, _strict); \
+ zend_wrong_paramer_type_error(_i, _expected_type, _arg); \
} \
} \
failure; \
@@ -818,7 +814,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
/* old "b" */
#define Z_PARAM_BOOL_EX(dest, is_null, check_null, separate) \
Z_PARAM_PROLOGUE(separate); \
- if (UNEXPECTED(!zend_parse_arg_bool(_arg, &dest, &is_null, check_null, _strict))) { \
+ if (UNEXPECTED(!zend_parse_arg_bool(_arg, &dest, &is_null, check_null))) { \
_expected_type = Z_EXPECTED_BOOL; \
error_code = ZPP_ERROR_WRONG_ARG; \
break; \
@@ -830,7 +826,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
/* old "C" */
#define Z_PARAM_CLASS_EX(dest, check_null, separate) \
Z_PARAM_PROLOGUE(separate); \
- if (UNEXPECTED(!zend_parse_arg_class(_arg, &dest, _i, check_null, _strict))) { \
+ if (UNEXPECTED(!zend_parse_arg_class(_arg, &dest, _i, check_null))) { \
error_code = ZPP_ERROR_FAILURE; \
break; \
}
@@ -841,7 +837,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
/* old "d" */
#define Z_PARAM_DOUBLE_EX(dest, is_null, check_null, separate) \
Z_PARAM_PROLOGUE(separate); \
- if (UNEXPECTED(!zend_parse_arg_double(_arg, &dest, &is_null, check_null, _strict))) { \
+ if (UNEXPECTED(!zend_parse_arg_double(_arg, &dest, &is_null, check_null))) { \
_expected_type = Z_EXPECTED_DOUBLE; \
error_code = ZPP_ERROR_WRONG_ARG; \
break; \
@@ -863,7 +859,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
break; \
} \
} else if (UNEXPECTED(_error != NULL)) { \
- zend_wrong_callback_error(E_STRICT, _i, _error, _strict); \
+ zend_wrong_callback_error(E_STRICT, _i, _error); \
}
#define Z_PARAM_FUNC(dest_fci, dest_fcc) \
@@ -896,7 +892,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
/* old "l" */
#define Z_PARAM_LONG_EX(dest, is_null, check_null, separate) \
Z_PARAM_PROLOGUE(separate); \
- if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, 0, _strict))) { \
+ if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, 0))) { \
_expected_type = Z_EXPECTED_LONG; \
error_code = ZPP_ERROR_WRONG_ARG; \
break; \
@@ -908,7 +904,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
/* old "L" */
#define Z_PARAM_STRICT_LONG_EX(dest, is_null, check_null, separate) \
Z_PARAM_PROLOGUE(separate); \
- if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, 1, _strict))) { \
+ if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, 1))) { \
_expected_type = Z_EXPECTED_LONG; \
error_code = ZPP_ERROR_WRONG_ARG; \
break; \
@@ -950,7 +946,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
/* old "p" */
#define Z_PARAM_PATH_EX(dest, dest_len, check_null, separate) \
Z_PARAM_PROLOGUE(separate); \
- if (UNEXPECTED(!zend_parse_arg_path(_arg, &dest, &dest_len, check_null, _strict))) { \
+ if (UNEXPECTED(!zend_parse_arg_path(_arg, &dest, &dest_len, check_null))) { \
_expected_type = Z_EXPECTED_PATH; \
error_code = ZPP_ERROR_WRONG_ARG; \
break; \
@@ -962,7 +958,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
/* old "P" */
#define Z_PARAM_PATH_STR_EX(dest, check_null, separate) \
Z_PARAM_PROLOGUE(separate); \
- if (UNEXPECTED(!zend_parse_arg_path_str(_arg, &dest, check_null, _strict))) { \
+ if (UNEXPECTED(!zend_parse_arg_path_str(_arg, &dest, check_null))) { \
_expected_type = Z_EXPECTED_PATH; \
error_code = ZPP_ERROR_WRONG_ARG; \
break; \
@@ -986,7 +982,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
/* old "s" */
#define Z_PARAM_STRING_EX(dest, dest_len, check_null, separate) \
Z_PARAM_PROLOGUE(separate); \
- if (UNEXPECTED(!zend_parse_arg_string(_arg, &dest, &dest_len, check_null, _strict))) { \
+ if (UNEXPECTED(!zend_parse_arg_string(_arg, &dest, &dest_len, check_null))) { \
_expected_type = Z_EXPECTED_STRING; \
error_code = ZPP_ERROR_WRONG_ARG; \
break; \
@@ -998,7 +994,7 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
/* old "S" */
#define Z_PARAM_STR_EX(dest, check_null, separate) \
Z_PARAM_PROLOGUE(separate); \
- if (UNEXPECTED(!zend_parse_arg_str(_arg, &dest, check_null, _strict))) { \
+ if (UNEXPECTED(!zend_parse_arg_str(_arg, &dest, check_null))) { \
_expected_type = Z_EXPECTED_STRING; \
error_code = ZPP_ERROR_WRONG_ARG; \
break; \
@@ -1052,34 +1048,37 @@ ZEND_API void zend_wrong_callback_error(int severity, int num, char *error, zend
/* Inlined implementations shared by new and old parameter parsing APIs */
-ZEND_API int parse_arg_object_to_str(zval *arg, zend_string **str, int type);
-ZEND_API int zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, int check_null, zend_bool strict);
-
-static zend_always_inline int zend_parse_arg_bool(zval *arg, zend_bool *dest, zend_bool *is_null, int check_null, zend_bool strict)
+ZEND_API int ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, int check_null);
+ZEND_API int ZEND_FASTCALL zend_parse_arg_bool_slow(zval *arg, zend_bool *dest);
+ZEND_API int ZEND_FASTCALL zend_parse_arg_bool_weak(zval *arg, zend_bool *dest);
+ZEND_API int ZEND_FASTCALL zend_parse_arg_long_slow(zval *arg, zend_long *dest);
+ZEND_API int ZEND_FASTCALL zend_parse_arg_long_weak(zval *arg, zend_long *dest);
+ZEND_API int ZEND_FASTCALL zend_parse_arg_long_cap_slow(zval *arg, zend_long *dest);
+ZEND_API int ZEND_FASTCALL zend_parse_arg_long_cap_weak(zval *arg, zend_long *dest);
+ZEND_API int ZEND_FASTCALL zend_parse_arg_double_slow(zval *arg, double *dest);
+ZEND_API int ZEND_FASTCALL zend_parse_arg_double_weak(zval *arg, double *dest);
+ZEND_API int ZEND_FASTCALL zend_parse_arg_str_slow(zval *arg, zend_string **dest);
+ZEND_API int ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **dest);
+
+static zend_always_inline int zend_parse_arg_bool(zval *arg, zend_bool *dest, zend_bool *is_null, int check_null)
{
if (check_null) {
*is_null = 0;
}
if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
*dest = 1;
- } else if (EXPECTED(Z_TYPE_P(arg) < IS_TRUE)) {
- if (check_null) {
- *is_null = (Z_TYPE_P(arg) == IS_NULL);
- } else if (strict && Z_TYPE_P(arg) == IS_NULL) {
- return 0;
- }
+ } else if (EXPECTED(Z_TYPE_P(arg) == IS_FALSE)) {
+ *dest = 0;
+ } else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
+ *is_null = 1;
*dest = 0;
- } else if (UNEXPECTED(strict)) {
- return 0;
- } else if (EXPECTED(Z_TYPE_P(arg) <= IS_STRING)) {
- *dest = zend_is_true(arg);
} else {
- return 0;
+ return zend_parse_arg_bool_slow(arg, dest);
}
return 1;
}
-static zend_always_inline int zend_parse_arg_long(zval *arg, zend_long *dest, zend_bool *is_null, int check_null, int cap, zend_bool strict)
+static zend_always_inline int zend_parse_arg_long(zval *arg, zend_long *dest, zend_bool *is_null, int check_null, int cap)
{
if (check_null) {
*is_null = 0;
@@ -1089,54 +1088,15 @@ static zend_always_inline int zend_parse_arg_long(zval *arg, zend_long *dest, ze
} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
*is_null = 1;
*dest = 0;
- } else if (UNEXPECTED(strict)) {
- return 0;
- } else if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) {
- if (UNEXPECTED(zend_isnan(Z_DVAL_P(arg)))) {
- return 0;
- }
- if (UNEXPECTED(!ZEND_DOUBLE_FITS_LONG(Z_DVAL_P(arg)))) {
- if (cap) {
- *dest = (Z_DVAL_P(arg) > 0) ? ZEND_LONG_MAX : ZEND_LONG_MIN;
- } else {
- return 0;
- }
- } else {
- *dest = zend_dval_to_lval(Z_DVAL_P(arg));
- }
- } else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
- double d;
- int type;
-
- if (UNEXPECTED((type = is_numeric_str_function(Z_STR_P(arg), dest, &d)) != IS_LONG)) {
- if (EXPECTED(type != 0)) {
- if (UNEXPECTED(zend_isnan(d))) {
- return 0;
- }
- if (UNEXPECTED(!ZEND_DOUBLE_FITS_LONG(d))) {
- if (cap) {
- *dest = (d > 0) ? ZEND_LONG_MAX : ZEND_LONG_MIN;
- } else {
- return 0;
- }
- } else {
- *dest = zend_dval_to_lval(d);
- }
- } else {
- return 0;
- }
- }
- } else if (EXPECTED(Z_TYPE_P(arg) < IS_TRUE)) {
- *dest = 0;
- } else if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
- *dest = 1;
+ } else if (cap) {
+ return zend_parse_arg_long_cap_slow(arg, dest);
} else {
- return 0;
+ return zend_parse_arg_long_slow(arg, dest);
}
return 1;
}
-static zend_always_inline int zend_parse_arg_double(zval *arg, double *dest, zend_bool *is_null, int check_null, zend_bool strict)
+static zend_always_inline int zend_parse_arg_double(zval *arg, double *dest, zend_bool *is_null, int check_null)
{
if (check_null) {
*is_null = 0;
@@ -1144,61 +1104,31 @@ static zend_always_inline int zend_parse_arg_double(zval *arg, double *dest, zen
if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) {
*dest = Z_DVAL_P(arg);
} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
- *is_null = 0;
- *dest = 0.0;
- } else if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
- /* SSTH Exception: IS_LONG ma be accepted instead as IS_DOUBLE */
- *dest = (double)Z_LVAL_P(arg);
- } else if (UNEXPECTED(strict)) {
- return 0;
- } else if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
- zend_long l;
- int type;
-
- if (UNEXPECTED((type = is_numeric_str_function(Z_STR_P(arg), &l, dest)) != IS_DOUBLE)) {
- if (EXPECTED(type != 0)) {
- *dest = (double)(l);
- } else {
- return 0;
- }
- }
- } else if (EXPECTED(Z_TYPE_P(arg) < IS_TRUE)) {
+ *is_null = 1;
*dest = 0.0;
- } else if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
- *dest = 1.0;
} else {
- return 0;
+ return zend_parse_arg_double_slow(arg, dest);
}
return 1;
}
-static zend_always_inline int zend_parse_arg_str(zval *arg, zend_string **dest, int check_null, zend_bool strict)
+static zend_always_inline int zend_parse_arg_str(zval *arg, zend_string **dest, int check_null)
{
if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
*dest = Z_STR_P(arg);
} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
*dest = NULL;
- } else if (UNEXPECTED(strict)) {
- return 0;
- } else if (EXPECTED(Z_TYPE_P(arg) < IS_STRING)) {
- if (Z_COPYABLE_P(arg) && Z_REFCOUNT_P(arg) > 1) {
- Z_DELREF_P(arg);
- zval_copy_ctor_func(arg);
- }
- convert_to_string(arg);
- *dest = Z_STR_P(arg);
- } else if (UNEXPECTED(Z_TYPE_P(arg) != IS_OBJECT) ||
- UNEXPECTED(parse_arg_object_to_str(arg, dest, IS_STRING) != SUCCESS)) {
- return 0;
+ } else {
+ return zend_parse_arg_str_slow(arg, dest);
}
return 1;
}
-static zend_always_inline int zend_parse_arg_string(zval *arg, char **dest, size_t *dest_len, int check_null, zend_bool strict)
+static zend_always_inline int zend_parse_arg_string(zval *arg, char **dest, size_t *dest_len, int check_null)
{
zend_string *str;
- if (!zend_parse_arg_str(arg, &str, check_null, strict)) {
+ if (!zend_parse_arg_str(arg, &str, check_null)) {
return 0;
}
if (check_null && UNEXPECTED(!str)) {
@@ -1211,20 +1141,20 @@ static zend_always_inline int zend_parse_arg_string(zval *arg, char **dest, size
return 1;
}
-static zend_always_inline int zend_parse_arg_path_str(zval *arg, zend_string **dest, int check_null, zend_bool strict)
+static zend_always_inline int zend_parse_arg_path_str(zval *arg, zend_string **dest, int check_null)
{
- if (!zend_parse_arg_str(arg, dest, check_null, strict) ||
+ if (!zend_parse_arg_str(arg, dest, check_null) ||
(*dest && UNEXPECTED(CHECK_NULL_PATH((*dest)->val, (*dest)->len)))) {
return 0;
}
return 1;
}
-static zend_always_inline int zend_parse_arg_path(zval *arg, char **dest, size_t *dest_len, int check_null, zend_bool strict)
+static zend_always_inline int zend_parse_arg_path(zval *arg, char **dest, size_t *dest_len, int check_null)
{
zend_string *str;
- if (!zend_parse_arg_path_str(arg, &str, check_null, strict)) {
+ if (!zend_parse_arg_path_str(arg, &str, check_null)) {
return 0;
}
if (check_null && UNEXPECTED(!str)) {