From: Nikita Popov Date: Mon, 25 Aug 2014 20:40:58 +0000 (+0200) Subject: Add zend_string_equals and zend_string_equals_literal X-Git-Tag: PRE_PHP7_REMOVALS~331 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=46b53e815c39bad6226cdc0ca6caa76cabeb09ef;p=php Add zend_string_equals and zend_string_equals_literal --- diff --git a/Zend/zend_API.c b/Zend/zend_API.c index fef05e1e84..ce5adc65b8 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2297,30 +2297,30 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio */ if ((fname_len == class_name_len) && !ctor && !memcmp(lowercase_name->val, lc_class_name, class_name_len+1)) { ctor = reg_function; - } else if ((fname_len == sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1) && !memcmp(lowercase_name->val, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME) - 1)) { + } else if (zend_string_equals_literal(lowercase_name, ZEND_CONSTRUCTOR_FUNC_NAME)) { ctor = reg_function; - } else if ((fname_len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME)-1) && !memcmp(lowercase_name->val, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME) - 1)) { + } else if (zend_string_equals_literal(lowercase_name, ZEND_DESTRUCTOR_FUNC_NAME)) { dtor = reg_function; if (internal_function->num_args) { zend_error(error_type, "Destructor %s::%s() cannot take arguments", scope->name->val, ptr->fname); } - } else if ((fname_len == sizeof(ZEND_CLONE_FUNC_NAME)-1) && !memcmp(lowercase_name->val, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME) - 1)) { + } else if (zend_string_equals_literal(lowercase_name, ZEND_CLONE_FUNC_NAME)) { clone = reg_function; - } else if ((fname_len == sizeof(ZEND_CALL_FUNC_NAME)-1) && !memcmp(lowercase_name->val, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME) - 1)) { + } else if (zend_string_equals_literal(lowercase_name, ZEND_CALL_FUNC_NAME)) { __call = reg_function; - } else if ((fname_len == sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1) && !memcmp(lowercase_name->val, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME) - 1)) { + } else if (zend_string_equals_literal(lowercase_name, ZEND_CALLSTATIC_FUNC_NAME)) { __callstatic = reg_function; - } else if ((fname_len == sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && !memcmp(lowercase_name->val, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME) - 1)) { + } else if (zend_string_equals_literal(lowercase_name, ZEND_TOSTRING_FUNC_NAME)) { __tostring = reg_function; - } else if ((fname_len == sizeof(ZEND_GET_FUNC_NAME)-1) && !memcmp(lowercase_name->val, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME) - 1)) { + } else if (zend_string_equals_literal(lowercase_name, ZEND_GET_FUNC_NAME)) { __get = reg_function; - } else if ((fname_len == sizeof(ZEND_SET_FUNC_NAME)-1) && !memcmp(lowercase_name->val, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME) - 1)) { + } else if (zend_string_equals_literal(lowercase_name, ZEND_SET_FUNC_NAME)) { __set = reg_function; - } else if ((fname_len == sizeof(ZEND_UNSET_FUNC_NAME)-1) && !memcmp(lowercase_name->val, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME) - 1)) { + } else if (zend_string_equals_literal(lowercase_name, ZEND_UNSET_FUNC_NAME)) { __unset = reg_function; - } else if ((fname_len == sizeof(ZEND_ISSET_FUNC_NAME)-1) && !memcmp(lowercase_name->val, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME) - 1)) { + } else if (zend_string_equals_literal(lowercase_name, ZEND_ISSET_FUNC_NAME)) { __isset = reg_function; - } else if ((fname_len == sizeof(ZEND_DEBUGINFO_FUNC_NAME)-1) && !memcmp(lowercase_name->val, ZEND_DEBUGINFO_FUNC_NAME, sizeof(ZEND_DEBUGINFO_FUNC_NAME) - 1)) { + } else if (zend_string_equals_literal(lowercase_name, ZEND_DEBUGINFO_FUNC_NAME)) { __debugInfo = reg_function; } else { reg_function = NULL; @@ -2850,8 +2850,7 @@ static int zend_is_callable_check_class(zend_string *name, zend_fcall_info_cache zend_str_tolower_copy(lcname->val, name->val, name_len); *strict_class = 0; - if (name_len == sizeof("self") - 1 && - !memcmp(lcname->val, "self", sizeof("self") - 1)) { + if (zend_string_equals_literal(lcname, "self")) { if (!EG(scope)) { if (error) *error = estrdup("cannot access self:: when no class scope is active"); } else { @@ -2862,8 +2861,7 @@ static int zend_is_callable_check_class(zend_string *name, zend_fcall_info_cache } ret = 1; } - } else if (name_len == sizeof("parent") - 1 && - !memcmp(lcname->val, "parent", sizeof("parent") - 1)) { + } else if (zend_string_equals_literal(lcname, "parent")) { if (!EG(scope)) { if (error) *error = estrdup("cannot access parent:: when no class scope is active"); } else if (!EG(scope)->parent) { @@ -2877,8 +2875,7 @@ static int zend_is_callable_check_class(zend_string *name, zend_fcall_info_cache *strict_class = 1; ret = 1; } - } else if (name_len == sizeof("static") - 1 && - !memcmp(lcname->val, "static", sizeof("static") - 1)) { + } else if (zend_string_equals_literal(lcname, "static")) { if (!EG(current_execute_data) || !EG(current_execute_data)->called_scope) { if (error) *error = estrdup("cannot access static:: when no class scope is active"); } else { @@ -3025,8 +3022,7 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca zend_str_tolower_copy(lmname->val, mname->val, mlen); if (strict_class && fcc->calling_scope && - mlen == sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1 && - !memcmp(lmname->val, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME) - 1)) { + zend_string_equals_literal(lmname, ZEND_CONSTRUCTOR_FUNC_NAME)) { fcc->function_handler = fcc->calling_scope->constructor; if (fcc->function_handler) { retval = 1; diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 0adb3d2df5..6af6debc1e 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1198,9 +1198,8 @@ ZEND_FUNCTION(method_exists) && (func->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0 ) { /* Returns true to the fake Closure's __invoke */ - RETVAL_BOOL((func->common.scope == zend_ce_closure - && (method_name->len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) - && memcmp(lcname->val, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0) ? 1 : 0); + RETVAL_BOOL(func->common.scope == zend_ce_closure + && zend_string_equals_literal(method_name, ZEND_INVOKE_FUNC_NAME)); zend_string_free(lcname); zend_string_release(func->common.function_name); @@ -1959,8 +1958,7 @@ ZEND_FUNCTION(get_resources) zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val); } } ZEND_HASH_FOREACH_END(); - } else if (type->len == sizeof("Unknown")-1 && - memcmp(type->val, "Unknown", sizeof("Unknown")-1) == 0) { + } else if (zend_string_equals_literal(type, "Unknown")) { array_init(return_value); ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { if (!key && Z_RES_TYPE_P(val) <= 0) { diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index 525be9dca1..f0920fb993 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -91,8 +91,7 @@ ZEND_METHOD(Closure, bind) ce = NULL; } else { zend_string *class_name = zval_get_string(scope_arg); - if ((class_name->len == sizeof("static") - 1) && - (memcmp("static", class_name->val, sizeof("static") - 1) == 0)) { + if (zend_string_equals_literal(class_name, "static")) { ce = closure->func.common.scope; } else if ((ce = zend_lookup_class_ex(class_name, NULL, 1 TSRMLS_CC)) == NULL) { zend_error(E_WARNING, "Class '%s' not found", class_name->val); @@ -158,9 +157,7 @@ static zend_function *zend_closure_get_method(zend_object **object, zend_string lc_name = zend_string_alloc(method->len, 0); zend_str_tolower_copy(lc_name->val, method->val, method->len); - if ((method->len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && - memcmp(lc_name->val, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - ) { + if (zend_string_equals_literal(method, ZEND_INVOKE_FUNC_NAME)) { zend_string_free(lc_name); return zend_get_closure_invoke_method(*object TSRMLS_CC); } diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 4a4afa2de6..ae23c453fc 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3250,17 +3250,12 @@ ZEND_API size_t zend_dirname(char *path, size_t len) } /* }}} */ -static inline zend_bool zend_str_equals_str(zend_string *str1, zend_string *str2) { - return str1->len == str2->len && !memcmp(str1->val, str2->val, str2->len); -} -static inline zend_bool zend_str_equals_str_ci(zend_string *str1, zend_string *str2) { +static inline zend_bool zend_string_equals_str_ci(zend_string *str1, zend_string *str2) { return str1->len == str2->len && !zend_binary_strcasecmp(str1->val, str1->len, str2->val, str2->len); } -#define zend_str_equals_literal(str, c) \ - ((str)->len == sizeof(c) - 1 && !memcmp((str)->val, (c), sizeof(c) - 1)) -#define zend_str_equals_literal_ci(str, c) \ +#define zend_string_equals_literal_ci(str, c) \ ((str)->len == sizeof(c) - 1 \ && !zend_binary_strcasecmp((str)->val, (str)->len, (c), sizeof(c) - 1)) @@ -3549,7 +3544,7 @@ static int zend_try_compile_cv(znode *result, zend_ast *ast TSRMLS_DC) { result->op_type = IS_CV; result->u.op.var = lookup_cv(CG(active_op_array), name TSRMLS_CC); - if (zend_str_equals_literal(name, "this")) { + if (zend_string_equals_literal(name, "this")) { CG(active_op_array)->this_var = result->u.op.var; } return SUCCESS; @@ -3644,7 +3639,7 @@ void zend_compile_dim(znode *result, zend_ast *ast, int type TSRMLS_DC) { static zend_bool is_this_fetch(zend_ast *ast) { if (ast->kind == ZEND_AST_VAR && ast->child[0]->kind == ZEND_AST_ZVAL) { zval *name = zend_ast_get_zval(ast->child[0]); - return Z_TYPE_P(name) == IS_STRING && zend_str_equals_literal(Z_STR_P(name), "this"); + return Z_TYPE_P(name) == IS_STRING && zend_string_equals_literal(Z_STR_P(name), "this"); } return 0; @@ -3804,7 +3799,7 @@ zend_bool zend_is_assign_to_self(zend_ast *var_ast, zend_ast *expr_ast TSRMLS_DC { zend_string *name1 = zval_get_string(zend_ast_get_zval(var_ast->child[0])); zend_string *name2 = zval_get_string(zend_ast_get_zval(expr_ast->child[0])); - zend_bool result = zend_str_equals_str(name1, name2); + zend_bool result = zend_string_equals(name1, name2); zend_string_release(name1); zend_string_release(name2); return result; @@ -4282,29 +4277,29 @@ int zend_compile_func_cuf(znode *result, zend_ast_list *args, zend_string *lcnam int zend_try_compile_special_func( znode *result, zend_string *lcname, zend_ast_list *args TSRMLS_DC ) { - if (zend_str_equals_literal(lcname, "strlen")) { + if (zend_string_equals_literal(lcname, "strlen")) { return zend_compile_func_strlen(result, args TSRMLS_CC); - } else if (zend_str_equals_literal(lcname, "is_null")) { + } else if (zend_string_equals_literal(lcname, "is_null")) { return zend_compile_func_typecheck(result, args, IS_NULL TSRMLS_CC); - } else if (zend_str_equals_literal(lcname, "is_bool")) { + } else if (zend_string_equals_literal(lcname, "is_bool")) { return zend_compile_func_typecheck(result, args, _IS_BOOL TSRMLS_CC); - } else if (zend_str_equals_literal(lcname, "is_long")) { + } else if (zend_string_equals_literal(lcname, "is_long")) { return zend_compile_func_typecheck(result, args, IS_LONG TSRMLS_CC); - } else if (zend_str_equals_literal(lcname, "is_float")) { + } else if (zend_string_equals_literal(lcname, "is_float")) { return zend_compile_func_typecheck(result, args, IS_DOUBLE TSRMLS_CC); - } else if (zend_str_equals_literal(lcname, "is_string")) { + } else if (zend_string_equals_literal(lcname, "is_string")) { return zend_compile_func_typecheck(result, args, IS_STRING TSRMLS_CC); - } else if (zend_str_equals_literal(lcname, "is_array")) { + } else if (zend_string_equals_literal(lcname, "is_array")) { return zend_compile_func_typecheck(result, args, IS_ARRAY TSRMLS_CC); - } else if (zend_str_equals_literal(lcname, "is_object")) { + } else if (zend_string_equals_literal(lcname, "is_object")) { return zend_compile_func_typecheck(result, args, IS_OBJECT TSRMLS_CC); - } else if (zend_str_equals_literal(lcname, "is_resource")) { + } else if (zend_string_equals_literal(lcname, "is_resource")) { return zend_compile_func_typecheck(result, args, IS_RESOURCE TSRMLS_CC); - } else if (zend_str_equals_literal(lcname, "defined")) { + } else if (zend_string_equals_literal(lcname, "defined")) { return zend_compile_func_defined(result, args TSRMLS_CC); - } else if (zend_str_equals_literal(lcname, "call_user_func_array")) { + } else if (zend_string_equals_literal(lcname, "call_user_func_array")) { return zend_compile_func_cufa(result, args, lcname TSRMLS_CC); - } else if (zend_str_equals_literal(lcname, "call_user_func")) { + } else if (zend_string_equals_literal(lcname, "call_user_func")) { return zend_compile_func_cuf(result, args, lcname TSRMLS_CC); } else { return FAILURE; @@ -4400,7 +4395,7 @@ void zend_compile_method_call(znode *result, zend_ast *ast, int type TSRMLS_DC) } zend_bool zend_is_constructor(zend_string *name) { - return zend_str_equals_literal_ci(name, ZEND_CONSTRUCTOR_FUNC_NAME); + return zend_string_equals_literal_ci(name, ZEND_CONSTRUCTOR_FUNC_NAME); } void zend_compile_static_call(znode *result, zend_ast *ast, int type TSRMLS_DC) { @@ -5123,7 +5118,7 @@ void zend_handle_encoding_declaration(zend_ast_list *declares TSRMLS_DC) { zend_ast *value_ast = declare_ast->child[1]; zend_string *name = zend_ast_get_str(name_ast); - if (zend_str_equals_literal_ci(name, "encoding")) { + if (zend_string_equals_literal_ci(name, "encoding")) { if (value_ast->kind != ZEND_AST_ZVAL) { zend_error_noreturn(E_COMPILE_ERROR, "Encoding must be a literal"); } @@ -5172,13 +5167,13 @@ void zend_compile_declare(zend_ast *ast TSRMLS_DC) { zend_ast *value_ast = declare_ast->child[1]; zend_string *name = zend_ast_get_str(name_ast); - if (zend_str_equals_literal_ci(name, "ticks")) { + if (zend_string_equals_literal_ci(name, "ticks")) { zval value_zv; zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC); convert_to_long(&value_zv); ZVAL_COPY_VALUE(&CG(declarables).ticks, &value_zv); zval_dtor(&value_zv); - } else if (zend_str_equals_literal_ci(name, "encoding")) { + } else if (zend_string_equals_literal_ci(name, "encoding")) { /* Encoding declaration was already handled during parsing. Here we * only check that it is the first statement in the file. */ uint32_t num = CG(active_op_array)->last; @@ -5248,7 +5243,7 @@ void zend_compile_params(zend_ast *ast TSRMLS_DC) { if (EX_VAR_TO_NUM(var_node.u.op.var) != i) { zend_error_noreturn(E_COMPILE_ERROR, "Redefinition of parameter $%s", name->val); - } else if (zend_str_equals_literal(name, "this")) { + } else if (zend_string_equals_literal(name, "this")) { if (op_array->scope && (op_array->fn_flags & ZEND_ACC_STATIC) == 0) { zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this"); } @@ -5355,7 +5350,7 @@ void zend_compile_closure_uses(zend_ast *ast TSRMLS_DC) { zend_bool by_ref = var_ast->attr; zval zv; - if (zend_str_equals_literal(name, "this")) { + if (zend_string_equals_literal(name, "this")) { zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as lexical variable"); } @@ -5425,115 +5420,115 @@ void zend_begin_method_decl( } if (in_interface) { - if (zend_str_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) { + if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __call() must have " "public visibility and cannot be static"); } - } else if (zend_str_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) { if (!is_public || !is_static) { zend_error(E_WARNING, "The magic method __callStatic() must have " "public visibility and be static"); } - } else if (zend_str_equals_literal(lcname, ZEND_GET_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __get() must have " "public visibility and cannot be static"); } - } else if (zend_str_equals_literal(lcname, ZEND_SET_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __set() must have " "public visibility and cannot be static"); } - } else if (zend_str_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __unset() must have " "public visibility and cannot be static"); } - } else if (zend_str_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __isset() must have " "public visibility and cannot be static"); } - } else if (zend_str_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __toString() must have " "public visibility and cannot be static"); } - } else if (zend_str_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __invoke() must have " "public visibility and cannot be static"); } - } else if (zend_str_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __debugInfo() must have " "public visibility and cannot be static"); } } } else { - if (!in_trait && zend_str_equals_str_ci(lcname, ce->name)) { + if (!in_trait && zend_string_equals_str_ci(lcname, ce->name)) { if (!ce->constructor) { ce->constructor = (zend_function *) op_array; } - } else if (zend_str_equals_literal(lcname, ZEND_CONSTRUCTOR_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_CONSTRUCTOR_FUNC_NAME)) { if (CG(active_class_entry)->constructor) { zend_error(E_STRICT, "Redefining already defined constructor for class %s", ce->name->val); } ce->constructor = (zend_function *) op_array; - } else if (zend_str_equals_literal(lcname, ZEND_DESTRUCTOR_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_DESTRUCTOR_FUNC_NAME)) { ce->destructor = (zend_function *) op_array; - } else if (zend_str_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) { ce->clone = (zend_function *) op_array; - } else if (zend_str_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __call() must have " "public visibility and cannot be static"); } ce->__call = (zend_function *) op_array; - } else if (zend_str_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) { if (!is_public || !is_static) { zend_error(E_WARNING, "The magic method __callStatic() must have " "public visibility and be static"); } ce->__callstatic = (zend_function *) op_array; - } else if (zend_str_equals_literal(lcname, ZEND_GET_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __get() must have " "public visibility and cannot be static"); } ce->__get = (zend_function *) op_array; - } else if (zend_str_equals_literal(lcname, ZEND_SET_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __set() must have " "public visibility and cannot be static"); } ce->__set = (zend_function *) op_array; - } else if (zend_str_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __unset() must have " "public visibility and cannot be static"); } ce->__unset = (zend_function *) op_array; - } else if (zend_str_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __isset() must have " "public visibility and cannot be static"); } ce->__isset = (zend_function *) op_array; - } else if (zend_str_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __toString() must have " "public visibility and cannot be static"); } ce->__tostring = (zend_function *) op_array; - } else if (zend_str_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __invoke() must have " "public visibility and cannot be static"); } - } else if (zend_str_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) { + } else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) { if (!is_public || is_static) { zend_error(E_WARNING, "The magic method __debugInfo() must have " "public visibility and cannot be static"); @@ -5561,13 +5556,13 @@ static void zend_begin_func_decl( if (CG(current_import_function)) { zend_string *import_name = zend_hash_find_ptr(CG(current_import_function), lcname); - if (import_name && !zend_str_equals_str_ci(lcname, import_name)) { + if (import_name && !zend_string_equals_str_ci(lcname, import_name)) { zend_error(E_COMPILE_ERROR, "Cannot declare function %s " "because the name is already in use", name->val); } } - if (zend_str_equals_literal(lcname, ZEND_AUTOLOAD_FUNC_NAME) + if (zend_string_equals_literal(lcname, ZEND_AUTOLOAD_FUNC_NAME) && zend_ast_get_list(params_ast)->children != 1 ) { zend_error_noreturn(E_COMPILE_ERROR, "%s() must take exactly 1 argument", @@ -5957,7 +5952,7 @@ void zend_compile_class_decl(zend_ast *ast TSRMLS_DC) { zend_string_addref(name); } - if (import_name && !zend_str_equals_str_ci(lcname, import_name)) { + if (import_name && !zend_string_equals_str_ci(lcname, import_name)) { zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare class %s " "because the name is already in use", name->val); } @@ -6120,7 +6115,7 @@ static char *zend_get_use_type_str(uint32_t type) { static void zend_check_already_in_use( uint32_t type, zend_string *old_name, zend_string *new_name, zend_string *check_name ) { - if (zend_str_equals_str_ci(old_name, check_name)) { + if (zend_string_equals_str_ci(old_name, check_name)) { return; } @@ -6154,7 +6149,7 @@ void zend_compile_use(zend_ast *ast TSRMLS_DC) { new_name = zend_string_copy(old_name); if (!current_ns) { - if (type == T_CLASS && zend_str_equals_literal(new_name, "strict")) { + if (type == T_CLASS && zend_string_equals_literal(new_name, "strict")) { zend_error_noreturn(E_COMPILE_ERROR, "You seem to be trying to use a different language..."); } @@ -6172,8 +6167,8 @@ void zend_compile_use(zend_ast *ast TSRMLS_DC) { zend_str_tolower_copy(lookup_name->val, new_name->val, new_name->len); } - if (type == T_CLASS && (zend_str_equals_literal(lookup_name, "self") - || zend_str_equals_literal(lookup_name, "parent")) + if (type == T_CLASS && (zend_string_equals_literal(lookup_name, "self") + || zend_string_equals_literal(lookup_name, "parent")) ) { zend_error_noreturn(E_COMPILE_ERROR, "Cannot use %s as %s because '%s' " "is a special class name", old_name->val, new_name->val, new_name->val); @@ -6260,7 +6255,7 @@ void zend_compile_const_decl(zend_ast *ast TSRMLS_DC) { if (CG(current_import_const) && (import_name = zend_hash_find_ptr(CG(current_import_const), name)) ) { - if (!zend_str_equals_str(import_name, name)) { + if (!zend_string_equals(import_name, name)) { zend_error(E_COMPILE_ERROR, "Cannot declare const %s because " "the name is already in use", name->val); } diff --git a/Zend/zend_string.h b/Zend/zend_string.h index 6f276253e2..479e92069e 100644 --- a/Zend/zend_string.h +++ b/Zend/zend_string.h @@ -209,6 +209,14 @@ static zend_always_inline void zend_string_release(zend_string *s) } } +static zend_always_inline zend_bool zend_string_equals(zend_string *s1, zend_string *s2) +{ + return s1 == s2 || (s1->len == s2->len && !memcmp(s1->val, s2->val, s1->len)); +} + +#define zend_string_equals_literal(str, literal) \ + ((str)->len == sizeof(literal)-1 && !memcmp((str)->val, literal, sizeof(literal) - 1)) + /* * DJBX33A (Daniel J. Bernstein, Times 33 with Addition) *