com php-src: converted several switches to ifs and made more opcache friendly: Zend/zend.h Zend/zend_API.c Zend/zend_ast.c
Zend/zend_builtin_functions.c Zend/zend_compile. c Zend/zend_execute_API.c Zend/zend_vm_def.h Zend/zend_vm_execute.h ext/reflection/php_reflection .c
| From: | Bob Weinand | Date: | Fri, 01 Nov 2013 15:16:58 +0000 |
| Subject: | com php-src: converted several switches to ifs and made more opcache friendly: Zend/zend.h Zend/zend_API.c Zend/zend_ast.c Zend/zend_builtin_functions.c Zend/zend_compile. c Zend/zend_execute_API.c Zend/zend_vm_def.h Zend/zend_vm_execute.h ext/reflection/php_reflection .c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-74121@lists.php.net to get a copy of this message | ||
Commit: b45043a1b71c29a0c7b8de9e4929dde08bd61216
Author: Bob Weinand <bobwei9@hotmail.com> Fri, 1 Nov 2013 16:16:58 +0100
Parents: b56c1ca95e16ea1c2a3ce251b91297d0a81a9070
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b45043a1b71c29a0c7b8de9e4929dde08bd61216
Log:
converted several switches to ifs and made more opcache friendly
Changed paths:
M Zend/zend.h
M Zend/zend_API.c
M Zend/zend_ast.c
M Zend/zend_builtin_functions.c
M Zend/zend_compile.c
M Zend/zend_execute_API.c
M Zend/zend_vm_def.h
M Zend/zend_vm_execute.h
M ext/reflection/php_reflection.c
diff --git a/Zend/zend.h b/Zend/zend.h index 7ccd081..8154277 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -600,6 +600,8 @@ typedef int (*zend_write_func_t)(const char *str, uint str_length); #define IS_LEXICAL_REF 0x040 #define IS_CONSTANT_IN_NAMESPACE 0x100 +#define IS_CONSTANT_TYPE(type) (((type) & IS_CONSTANT_TYPE_MASK) >= IS_CONSTANT && ((type) & IS_CONSTANT_TYPE_MASK) <= IS_CONSTANT_AST) + /* overloaded elements data types */ #define OE_IS_ARRAY (1<<0) #define OE_IS_OBJECT (1<<1) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 3051d19..b414b52 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1053,37 +1053,33 @@ ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destro static int zval_update_class_constant(zval **pp, int is_static, int offset TSRMLS_DC) /* {{{ */ { - switch (Z_TYPE_PP(pp) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zend_class_entry **scope = EG(in_execution)?&EG(scope):&CG(active_class_entry); - - if ((*scope)->parent) { - zend_class_entry *ce = *scope; - HashPosition pos; - zend_property_info *prop_info; - - do { - for (zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop_info, &pos) == SUCCESS; - zend_hash_move_forward_ex(&ce->properties_info, &pos)) { - if (is_static == ((prop_info->flags & ZEND_ACC_STATIC) != 0) && - offset == prop_info->offset) { - int ret; - zend_class_entry *old_scope = *scope; - *scope = prop_info->ce; - ret = zval_update_constant(pp, (void*)1 TSRMLS_CC); - *scope = old_scope; - return ret; - } - } - ce = ce->parent; - } while (ce); - + if (IS_CONSTANT_TYPE(Z_TYPE_PP(pp))) { + zend_class_entry **scope = EG(in_execution)?&EG(scope):&CG(active_class_entry); + + if ((*scope)->parent) { + zend_class_entry *ce = *scope; + HashPosition pos; + zend_property_info *prop_info; + + do { + for (zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); + zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop_info, &pos) == SUCCESS; + zend_hash_move_forward_ex(&ce->properties_info, &pos)) { + if (is_static == ((prop_info->flags & ZEND_ACC_STATIC) != 0) && + offset == prop_info->offset) { + int ret; + zend_class_entry *old_scope = *scope; + *scope = prop_info->ce; + ret = zval_update_constant(pp, (void*)1 TSRMLS_CC); + *scope = old_scope; + return ret; + } + } + ce = ce->parent; + } while (ce); + } - return zval_update_constant(pp, (void*)1 TSRMLS_CC); - } + return zval_update_constant(pp, (void*)1 TSRMLS_CC); } return 0; } diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 7d85e24..21c08da 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -21,30 +21,6 @@ #include "zend_ast.h" #include "zend_execute.h" -#define OP_IS_CONST_THEN(op, do_code) \ - switch (op?Z_TYPE_P(op) & IS_CONSTANT_TYPE_MASK:-1) { \ - case -1: \ - case IS_CONSTANT: \ - case IS_CONSTANT_ARRAY: \ - case IS_CONSTANT_AST: { \ - do_code \ - } \ - } - -#define OP_IS_NOT_CONST_THEN(op, do_code) \ - if (op) { \ - switch (Z_TYPE_P(op) & IS_CONSTANT_TYPE_MASK) { \ - case IS_CONSTANT: \ - case IS_CONSTANT_ARRAY: \ - case IS_CONSTANT_AST: \ - break; \ -\ - default: { \ - do_code \ - } \ - } \ - } - #define COPY_ZVAL_TO_OP(nr) \ if (op##nr) { \ Z_AST_P(result)->ops[nr] = emalloc(sizeof(zval)); \ @@ -54,9 +30,9 @@ } void zend_ast_add(zval *result, intermediary_ast_function_type func, char op_count) { - zend_ast *ast = emalloc(sizeof(zend_ast)); + zend_ast *ast = emalloc(sizeof(zend_ast) + op_count * sizeof(zval *)); ast->op_count = op_count; - ast->ops = emalloc(op_count * sizeof(zval *)); + ast->ops = (zval **)(ast + 1); ast->refcount = 1; ast->func = func; Z_AST_P(result) = ast; @@ -66,23 +42,23 @@ void zend_ast_add(zval *result, intermediary_ast_function_type func, char op_cou /* Do operations on constant operators at compile time (AST building time) */ void zend_ast_add_unary(zval *result, unary_ast_func func, zval *op0 TSRMLS_DC) { - OP_IS_NOT_CONST_THEN(op0, + if (!op0 || !IS_CONSTANT_TYPE(Z_TYPE_P(op0))) { func(result, op0 TSRMLS_CC); - zval_dtor(op0); + if (op0) zval_dtor(op0); return; - ) + } zend_ast_add(result, (intermediary_ast_function_type)func, 1); COPY_ZVAL_TO_OP(0) } void zend_ast_add_binary(zval *result, binary_ast_func func, zval *op0, zval *op1 TSRMLS_DC) { - OP_IS_NOT_CONST_THEN(op0, OP_IS_NOT_CONST_THEN(op1, + if ((!op0 || !IS_CONSTANT_TYPE(Z_TYPE_P(op0))) && (!op1 || !IS_CONSTANT_TYPE(Z_TYPE_P(op1)))) { func(result, op0, op1 TSRMLS_CC); - zval_dtor(op0); - zval_dtor(op1); + if (op0) zval_dtor(op0); + if (op1) zval_dtor(op1); return; - )) + } zend_ast_add(result, (intermediary_ast_function_type)func, 2); COPY_ZVAL_TO_OP(0) @@ -90,13 +66,13 @@ void zend_ast_add_binary(zval *result, binary_ast_func func, zval *op0, zval *op } void zend_ast_add_ternary(zval *result, ternary_ast_func func, zval *op0, zval *op1, zval *op2 TSRMLS_DC) { - OP_IS_NOT_CONST_THEN(op0, OP_IS_NOT_CONST_THEN(op1, OP_IS_NOT_CONST_THEN(op2, + if ((!op0 || !IS_CONSTANT_TYPE(Z_TYPE_P(op0))) && (!op1 || !IS_CONSTANT_TYPE(Z_TYPE_P(op1))) && (!op2 || !IS_CONSTANT_TYPE(Z_TYPE_P(op2)))) { func(result, op0, op1, op2 TSRMLS_CC); - zval_dtor(op0); - zval_dtor(op1); - zval_dtor(op2); + if (op0) zval_dtor(op0); + if (op1) zval_dtor(op1); + if (op2) zval_dtor(op2); return; - ))) + } zend_ast_add(result, (intermediary_ast_function_type)func, 3); COPY_ZVAL_TO_OP(0) @@ -106,26 +82,38 @@ void zend_ast_add_ternary(zval *result, ternary_ast_func func, zval *op0, zval * void zend_ast_evaluate(zval *result, zend_ast *ast TSRMLS_DC) { int i; + zval **ops = emalloc((sizeof(zval *) + sizeof(zval)) * ast->op_count); for (i = ast->op_count; i--;) { - if (ast->ops[i]) { - OP_IS_CONST_THEN(ast->ops[i], - zval_update_constant_ex(&ast->ops[i], (void *)1, NULL TSRMLS_CC); - ) + if (ast->ops[i] && IS_CONSTANT_TYPE(Z_TYPE_P(ast->ops[i]))) { + ops[i] = ((zval *)(ops + ast->op_count)) + i; + *ops[i] = *ast->ops[i]; + zval_copy_ctor(ops[i]); + zval_update_constant_ex(&ops[i], (void *)1, NULL TSRMLS_CC); + } else { + ops[i] = ast->ops[i]; } } switch (ast->op_count) { case 1: - ((unary_ast_func)ast->func)(result, ast->ops[0] TSRMLS_CC); + ((unary_ast_func)ast->func)(result, ops[0] TSRMLS_CC); break; case 2: - ((binary_ast_func)ast->func)(result, ast->ops[0], ast->ops[1] TSRMLS_CC); + ((binary_ast_func)ast->func)(result, ops[0], ops[1] TSRMLS_CC); break; case 3: - ((ternary_ast_func)ast->func)(result, ast->ops[0], ast->ops[1], ast->ops[2] TSRMLS_CC); + ((ternary_ast_func)ast->func)(result, ops[0], ops[1], ops[2] TSRMLS_CC); break; } + + for (i = ast->op_count; i--;) { + if (ast->ops[i] != ops[i]) { + zval_dtor(ops[i]); + } + } + + efree(ops); } void zend_ast_destroy(zend_ast *ast TSRMLS_DC) { @@ -138,6 +126,5 @@ void zend_ast_destroy(zend_ast *ast TSRMLS_DC) { } } - efree(ast->ops); efree(ast); } diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index b3b7529..049864c 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -946,11 +946,8 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value /* this is necessary to make it able to work with default array * properties, returned to user */ - switch (Z_TYPE_P(prop_copy) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: - zval_update_constant(&prop_copy, 0 TSRMLS_CC); + switch (IS_CONSTANT_TYPE(Z_TYPE_P(prop_copy))) { + zval_update_constant(&prop_copy, 0 TSRMLS_CC); } add_assoc_zval(return_value, key, prop_copy); diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index f3bf5be..c51d173 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5529,9 +5529,7 @@ static zend_constant* zend_get_ct_const(const zval *const_name, int all_internal if (all_internal_constants_substitution && (c->flags & CONST_PERSISTENT) && !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION) && - Z_TYPE(c->value) != IS_CONSTANT && - Z_TYPE(c->value) != IS_CONSTANT_ARRAY && - Z_TYPE(c->value) != IS_CONSTANT_AST) { + !IS_CONSTANT_TYPE(Z_TYPE(c->value))) { return c; } return NULL; diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index e5b68c7..12047f0 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -520,8 +520,7 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco } if (actual[0] == '\\') { if (inline_change) { - memmove(Z_STRVAL_P(p), Z_STRVAL_P(p)+1, Z_STRLEN_P(p)); - --Z_STRLEN_P(p); + memmove(Z_STRVAL_P(p), Z_STRVAL_P(p)+1, Z_STRLEN_P(p)--); } else { ++actual; } @@ -626,7 +625,7 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco if ((str_index[str_index_len - 2] & IS_CONSTANT_UNQUALIFIED) == 0) { zend_error(E_ERROR, "Undefined constant '%s'", save); } - zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", str_index, str_index); + zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", str_index, str_index); } ZVAL_STRINGL(&const_value, str_index, str_index_len-3, 1); } @@ -640,7 +639,7 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco /* preserve this bit for inheritance */ Z_TYPE_PP(element) |= IS_CONSTANT_INDEX; - zval_ptr_dtor(element); + zval_ptr_dtor(element); *element = new_val; } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 4ee5a99..006f2ec 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -3252,16 +3252,11 @@ ZEND_VM_HANDLER(64, ZEND_RECV_INIT, ANY, CONST) if (param == NULL) { ALLOC_ZVAL(assignment_value); *assignment_value = *opline->op2.zv; - switch (Z_TYPE_P(assignment_value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: - Z_SET_REFCOUNT_P(assignment_value, 1); - zval_update_constant(&assignment_value, 0 TSRMLS_CC); - break; - default: - zval_copy_ctor(assignment_value); - break; + if (IS_CONSTANT_TYPE(Z_TYPE_P(assignment_value))) { + Z_SET_REFCOUNT_P(assignment_value, 1); + zval_update_constant(&assignment_value, 0 TSRMLS_CC); + } else { + zval_copy_ctor(assignment_value); } INIT_PZVAL(assignment_value); } else { @@ -3584,16 +3579,12 @@ ZEND_VM_HANDLER(99, ZEND_FETCH_CONSTANT, VAR|CONST|UNUSED, CONST) } if (EXPECTED(zend_hash_quick_find(&ce->constants_table, Z_STRVAL_P(opline->op2.zv), Z_STRLEN_P(opline->op2.zv)+1, Z_HASH_P(opline->op2.zv), (void **) &value) == SUCCESS)) { - switch (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zend_class_entry *old_scope = EG(scope); - - EG(scope) = ce; - zval_update_constant(value, (void *) 1 TSRMLS_CC); - EG(scope) = old_scope; - } + if (IS_CONSTANT_TYPE(Z_TYPE_PP(value))) { + zend_class_entry *old_scope = EG(scope); + + EG(scope) = ce; + zval_update_constant(value, (void *) 1 TSRMLS_CC); + EG(scope) = old_scope; } if (OP1_TYPE == IS_CONST) { CACHE_PTR(opline->op2.literal->cache_slot, value); @@ -5194,28 +5185,22 @@ ZEND_VM_HANDLER(143, ZEND_DECLARE_CONST, CONST, CONST) name = GET_OP1_ZVAL_PTR(BP_VAR_R); val = GET_OP2_ZVAL_PTR(BP_VAR_R); - switch (Z_TYPE_P(val) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zval tmp; - zval *tmp_ptr = &tmp; + if (IS_CONSTANT_TYPE(Z_TYPE_P(val))) { + zval tmp; + zval *tmp_ptr = &tmp; - ZVAL_COPY_VALUE(&tmp, val); - if (Z_TYPE_P(val) == IS_CONSTANT_ARRAY) { - zval_copy_ctor(&tmp); - } - INIT_PZVAL(&tmp); - zval_update_constant(&tmp_ptr, NULL TSRMLS_CC); - c.value = *tmp_ptr; + ZVAL_COPY_VALUE(&tmp, val); + if (Z_TYPE_P(val) == IS_CONSTANT_ARRAY) { + zval_copy_ctor(&tmp); } - break; - - default: - INIT_PZVAL_COPY(&c.value, val); - zval_copy_ctor(&c.value); - break; + INIT_PZVAL(&tmp); + zval_update_constant(&tmp_ptr, NULL TSRMLS_CC); + c.value = *tmp_ptr; + } else { + INIT_PZVAL_COPY(&c.value, val); + zval_copy_ctor(&c.value); } + c.flags = CONST_CS; /* non persistent, case sensetive */ c.name = str_strndup(Z_STRVAL_P(name), Z_STRLEN_P(name)); c.name_len = Z_STRLEN_P(name)+1; diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index a90f187..d99bcd1 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -1435,16 +1435,11 @@ static int ZEND_FASTCALL ZEND_RECV_INIT_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ if (param == NULL) { ALLOC_ZVAL(assignment_value); *assignment_value = *opline->op2.zv; - switch (Z_TYPE_P(assignment_value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: - Z_SET_REFCOUNT_P(assignment_value, 1); - zval_update_constant(&assignment_value, 0 TSRMLS_CC); - break; - default: - zval_copy_ctor(assignment_value); - break; + if (IS_CONSTANT_TYPE(Z_TYPE_P(assignment_value))) { + Z_SET_REFCOUNT_P(assignment_value, 1); + zval_update_constant(&assignment_value, 0 TSRMLS_CC); + } else { + zval_copy_ctor(assignment_value); } INIT_PZVAL(assignment_value); } else { @@ -3796,16 +3791,12 @@ static int ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_CONST_CONST_HANDLER(ZEND_OPCO } if (EXPECTED(zend_hash_quick_find(&ce->constants_table, Z_STRVAL_P(opline->op2.zv), Z_STRLEN_P(opline->op2.zv)+1, Z_HASH_P(opline->op2.zv), (void **) &value) == SUCCESS)) { - switch (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zend_class_entry *old_scope = EG(scope); + if (IS_CONSTANT_TYPE(Z_TYPE_PP(value))) { + zend_class_entry *old_scope = EG(scope); - EG(scope) = ce; - zval_update_constant(value, (void *) 1 TSRMLS_CC); - EG(scope) = old_scope; - } + EG(scope) = ce; + zval_update_constant(value, (void *) 1 TSRMLS_CC); + EG(scope) = old_scope; } if (IS_CONST == IS_CONST) { CACHE_PTR(opline->op2.literal->cache_slot, value); @@ -4096,28 +4087,22 @@ static int ZEND_FASTCALL ZEND_DECLARE_CONST_SPEC_CONST_CONST_HANDLER(ZEND_OPCOD name = opline->op1.zv; val = opline->op2.zv; - switch (Z_TYPE_P(val) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zval tmp; - zval *tmp_ptr = &tmp; + if (IS_CONSTANT_TYPE(Z_TYPE_P(val))) { + zval tmp; + zval *tmp_ptr = &tmp; - ZVAL_COPY_VALUE(&tmp, val); - if (Z_TYPE_P(val) == IS_CONSTANT_ARRAY) { - zval_copy_ctor(&tmp); - } - INIT_PZVAL(&tmp); - zval_update_constant(&tmp_ptr, NULL TSRMLS_CC); - c.value = *tmp_ptr; + ZVAL_COPY_VALUE(&tmp, val); + if (Z_TYPE_P(val) == IS_CONSTANT_ARRAY) { + zval_copy_ctor(&tmp); } - break; - - default: - INIT_PZVAL_COPY(&c.value, val); - zval_copy_ctor(&c.value); - break; + INIT_PZVAL(&tmp); + zval_update_constant(&tmp_ptr, NULL TSRMLS_CC); + c.value = *tmp_ptr; + } else { + INIT_PZVAL_COPY(&c.value, val); + zval_copy_ctor(&c.value); } + c.flags = CONST_CS; /* non persistent, case sensetive */ c.name = str_strndup(Z_STRVAL_P(name), Z_STRLEN_P(name)); c.name_len = Z_STRLEN_P(name)+1; @@ -15649,16 +15634,12 @@ static int ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_VAR_CONST_HANDLER(ZEND_OPCODE } if (EXPECTED(zend_hash_quick_find(&ce->constants_table, Z_STRVAL_P(opline->op2.zv), Z_STRLEN_P(opline->op2.zv)+1, Z_HASH_P(opline->op2.zv), (void **) &value) == SUCCESS)) { - switch (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zend_class_entry *old_scope = EG(scope); + if (IS_CONSTANT_TYPE(Z_TYPE_PP(value))) { + zend_class_entry *old_scope = EG(scope); - EG(scope) = ce; - zval_update_constant(value, (void *) 1 TSRMLS_CC); - EG(scope) = old_scope; - } + EG(scope) = ce; + zval_update_constant(value, (void *) 1 TSRMLS_CC); + EG(scope) = old_scope; } if (IS_VAR == IS_CONST) { CACHE_PTR(opline->op2.literal->cache_slot, value); @@ -25188,16 +25169,12 @@ static int ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_UNUSED_CONST_HANDLER(ZEND_OPC } if (EXPECTED(zend_hash_quick_find(&ce->constants_table, Z_STRVAL_P(opline->op2.zv), Z_STRLEN_P(opline->op2.zv)+1, Z_HASH_P(opline->op2.zv), (void **) &value) == SUCCESS)) { - switch (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zend_class_entry *old_scope = EG(scope); + if (IS_CONSTANT_TYPE(Z_TYPE_PP(value))) { + zend_class_entry *old_scope = EG(scope); - EG(scope) = ce; - zval_update_constant(value, (void *) 1 TSRMLS_CC); - EG(scope) = old_scope; - } + EG(scope) = ce; + zval_update_constant(value, (void *) 1 TSRMLS_CC); + EG(scope) = old_scope; } if (IS_UNUSED == IS_CONST) { CACHE_PTR(opline->op2.literal->cache_slot, value); diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index abebc21..bff5e66 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2599,14 +2599,8 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) *return_value = *precv->op2.zv; INIT_PZVAL(return_value); - switch (Z_TYPE_P(return_value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: - break; - - default: - zval_copy_ctor(return_value); + if (!IS_CONSTANT_TYPE(Z_TYPE_P(return_value))) { + zval_copy_ctor(return_value); } zval_update_constant_ex(&return_value, (void*)0, param->fptr->common.scope TSRMLS_CC); } @@ -3419,11 +3413,8 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value /* this is necessary to make it able to work with default array * properties, returned to user */ - switch (Z_TYPE_P(prop_copy) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: - zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); + if (IS_CONSTANT_TYPE(Z_TYPE_P(prop_copy))) { + zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); } add_assoc_zval(return_value, key, prop_copy);
diff --git a/Zend/zend.h b/Zend/zend.h index 7ccd081..8154277 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -600,6 +600,8 @@ typedef int (*zend_write_func_t)(const char *str, uint str_length); #define IS_LEXICAL_REF 0x040 #define IS_CONSTANT_IN_NAMESPACE 0x100 +#define IS_CONSTANT_TYPE(type) (((type) & IS_CONSTANT_TYPE_MASK) >= IS_CONSTANT && ((type) & IS_CONSTANT_TYPE_MASK) <= IS_CONSTANT_AST) + /* overloaded elements data types */ #define OE_IS_ARRAY (1<<0) #define OE_IS_OBJECT (1<<1) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 3051d19..b414b52 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1053,37 +1053,33 @@ ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destro static int zval_update_class_constant(zval **pp, int is_static, int offset TSRMLS_DC) /* {{{ */ { - switch (Z_TYPE_PP(pp) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zend_class_entry **scope = EG(in_execution)?&EG(scope):&CG(active_class_entry); - - if ((*scope)->parent) { - zend_class_entry *ce = *scope; - HashPosition pos; - zend_property_info *prop_info; - - do { - for (zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop_info, &pos) == SUCCESS; - zend_hash_move_forward_ex(&ce->properties_info, &pos)) { - if (is_static == ((prop_info->flags & ZEND_ACC_STATIC) != 0) && - offset == prop_info->offset) { - int ret; - zend_class_entry *old_scope = *scope; - *scope = prop_info->ce; - ret = zval_update_constant(pp, (void*)1 TSRMLS_CC); - *scope = old_scope; - return ret; - } - } - ce = ce->parent; - } while (ce); - + if (IS_CONSTANT_TYPE(Z_TYPE_PP(pp))) { + zend_class_entry **scope = EG(in_execution)?&EG(scope):&CG(active_class_entry); + + if ((*scope)->parent) { + zend_class_entry *ce = *scope; + HashPosition pos; + zend_property_info *prop_info; + + do { + for (zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); + zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop_info, &pos) == SUCCESS; + zend_hash_move_forward_ex(&ce->properties_info, &pos)) { + if (is_static == ((prop_info->flags & ZEND_ACC_STATIC) != 0) && + offset == prop_info->offset) { + int ret; + zend_class_entry *old_scope = *scope; + *scope = prop_info->ce; + ret = zval_update_constant(pp, (void*)1 TSRMLS_CC); + *scope = old_scope; + return ret; + } + } + ce = ce->parent; + } while (ce); + } - return zval_update_constant(pp, (void*)1 TSRMLS_CC); - } + return zval_update_constant(pp, (void*)1 TSRMLS_CC); } return 0; } diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 7d85e24..21c08da 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -21,30 +21,6 @@ #include "zend_ast.h" #include "zend_execute.h" -#define OP_IS_CONST_THEN(op, do_code) \ - switch (op?Z_TYPE_P(op) & IS_CONSTANT_TYPE_MASK:-1) { \ - case -1: \ - case IS_CONSTANT: \ - case IS_CONSTANT_ARRAY: \ - case IS_CONSTANT_AST: { \ - do_code \ - } \ - } - -#define OP_IS_NOT_CONST_THEN(op, do_code) \ - if (op) { \ - switch (Z_TYPE_P(op) & IS_CONSTANT_TYPE_MASK) { \ - case IS_CONSTANT: \ - case IS_CONSTANT_ARRAY: \ - case IS_CONSTANT_AST: \ - break; \ -\ - default: { \ - do_code \ - } \ - } \ - } - #define COPY_ZVAL_TO_OP(nr) \ if (op##nr) { \ Z_AST_P(result)->ops[nr] = emalloc(sizeof(zval)); \ @@ -54,9 +30,9 @@ } void zend_ast_add(zval *result, intermediary_ast_function_type func, char op_count) { - zend_ast *ast = emalloc(sizeof(zend_ast)); + zend_ast *ast = emalloc(sizeof(zend_ast) + op_count * sizeof(zval *)); ast->op_count = op_count; - ast->ops = emalloc(op_count * sizeof(zval *)); + ast->ops = (zval **)(ast + 1); ast->refcount = 1; ast->func = func; Z_AST_P(result) = ast; @@ -66,23 +42,23 @@ void zend_ast_add(zval *result, intermediary_ast_function_type func, char op_cou /* Do operations on constant operators at compile time (AST building time) */ void zend_ast_add_unary(zval *result, unary_ast_func func, zval *op0 TSRMLS_DC) { - OP_IS_NOT_CONST_THEN(op0, + if (!op0 || !IS_CONSTANT_TYPE(Z_TYPE_P(op0))) { func(result, op0 TSRMLS_CC); - zval_dtor(op0); + if (op0) zval_dtor(op0); return; - ) + } zend_ast_add(result, (intermediary_ast_function_type)func, 1); COPY_ZVAL_TO_OP(0) } void zend_ast_add_binary(zval *result, binary_ast_func func, zval *op0, zval *op1 TSRMLS_DC) { - OP_IS_NOT_CONST_THEN(op0, OP_IS_NOT_CONST_THEN(op1, + if ((!op0 || !IS_CONSTANT_TYPE(Z_TYPE_P(op0))) && (!op1 || !IS_CONSTANT_TYPE(Z_TYPE_P(op1)))) { func(result, op0, op1 TSRMLS_CC); - zval_dtor(op0); - zval_dtor(op1); + if (op0) zval_dtor(op0); + if (op1) zval_dtor(op1); return; - )) + } zend_ast_add(result, (intermediary_ast_function_type)func, 2); COPY_ZVAL_TO_OP(0) @@ -90,13 +66,13 @@ void zend_ast_add_binary(zval *result, binary_ast_func func, zval *op0, zval *op } void zend_ast_add_ternary(zval *result, ternary_ast_func func, zval *op0, zval *op1, zval *op2 TSRMLS_DC) { - OP_IS_NOT_CONST_THEN(op0, OP_IS_NOT_CONST_THEN(op1, OP_IS_NOT_CONST_THEN(op2, + if ((!op0 || !IS_CONSTANT_TYPE(Z_TYPE_P(op0))) && (!op1 || !IS_CONSTANT_TYPE(Z_TYPE_P(op1))) && (!op2 || !IS_CONSTANT_TYPE(Z_TYPE_P(op2)))) { func(result, op0, op1, op2 TSRMLS_CC); - zval_dtor(op0); - zval_dtor(op1); - zval_dtor(op2); + if (op0) zval_dtor(op0); + if (op1) zval_dtor(op1); + if (op2) zval_dtor(op2); return; - ))) + } zend_ast_add(result, (intermediary_ast_function_type)func, 3); COPY_ZVAL_TO_OP(0) @@ -106,26 +82,38 @@ void zend_ast_add_ternary(zval *result, ternary_ast_func func, zval *op0, zval * void zend_ast_evaluate(zval *result, zend_ast *ast TSRMLS_DC) { int i; + zval **ops = emalloc((sizeof(zval *) + sizeof(zval)) * ast->op_count); for (i = ast->op_count; i--;) { - if (ast->ops[i]) { - OP_IS_CONST_THEN(ast->ops[i], - zval_update_constant_ex(&ast->ops[i], (void *)1, NULL TSRMLS_CC); - ) + if (ast->ops[i] && IS_CONSTANT_TYPE(Z_TYPE_P(ast->ops[i]))) { + ops[i] = ((zval *)(ops + ast->op_count)) + i; + *ops[i] = *ast->ops[i]; + zval_copy_ctor(ops[i]); + zval_update_constant_ex(&ops[i], (void *)1, NULL TSRMLS_CC); + } else { + ops[i] = ast->ops[i]; } } switch (ast->op_count) { case 1: - ((unary_ast_func)ast->func)(result, ast->ops[0] TSRMLS_CC); + ((unary_ast_func)ast->func)(result, ops[0] TSRMLS_CC); break; case 2: - ((binary_ast_func)ast->func)(result, ast->ops[0], ast->ops[1] TSRMLS_CC); + ((binary_ast_func)ast->func)(result, ops[0], ops[1] TSRMLS_CC); break; case 3: - ((ternary_ast_func)ast->func)(result, ast->ops[0], ast->ops[1], ast->ops[2] TSRMLS_CC); + ((ternary_ast_func)ast->func)(result, ops[0], ops[1], ops[2] TSRMLS_CC); break; } + + for (i = ast->op_count; i--;) { + if (ast->ops[i] != ops[i]) { + zval_dtor(ops[i]); + } + } + + efree(ops); } void zend_ast_destroy(zend_ast *ast TSRMLS_DC) { @@ -138,6 +126,5 @@ void zend_ast_destroy(zend_ast *ast TSRMLS_DC) { } } - efree(ast->ops); efree(ast); } diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index b3b7529..049864c 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -946,11 +946,8 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value /* this is necessary to make it able to work with default array * properties, returned to user */ - switch (Z_TYPE_P(prop_copy) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: - zval_update_constant(&prop_copy, 0 TSRMLS_CC); + switch (IS_CONSTANT_TYPE(Z_TYPE_P(prop_copy))) { + zval_update_constant(&prop_copy, 0 TSRMLS_CC); } add_assoc_zval(return_value, key, prop_copy); diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index f3bf5be..c51d173 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5529,9 +5529,7 @@ static zend_constant* zend_get_ct_const(const zval *const_name, int all_internal if (all_internal_constants_substitution && (c->flags & CONST_PERSISTENT) && !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION) && - Z_TYPE(c->value) != IS_CONSTANT && - Z_TYPE(c->value) != IS_CONSTANT_ARRAY && - Z_TYPE(c->value) != IS_CONSTANT_AST) { + !IS_CONSTANT_TYPE(Z_TYPE(c->value))) { return c; } return NULL; diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index e5b68c7..12047f0 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -520,8 +520,7 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco } if (actual[0] == '\\') { if (inline_change) { - memmove(Z_STRVAL_P(p), Z_STRVAL_P(p)+1, Z_STRLEN_P(p)); - --Z_STRLEN_P(p); + memmove(Z_STRVAL_P(p), Z_STRVAL_P(p)+1, Z_STRLEN_P(p)--); } else { ++actual; } @@ -626,7 +625,7 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco if ((str_index[str_index_len - 2] & IS_CONSTANT_UNQUALIFIED) == 0) { zend_error(E_ERROR, "Undefined constant '%s'", save); } - zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", str_index, str_index); + zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", str_index, str_index); } ZVAL_STRINGL(&const_value, str_index, str_index_len-3, 1); } @@ -640,7 +639,7 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco /* preserve this bit for inheritance */ Z_TYPE_PP(element) |= IS_CONSTANT_INDEX; - zval_ptr_dtor(element); + zval_ptr_dtor(element); *element = new_val; } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 4ee5a99..006f2ec 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -3252,16 +3252,11 @@ ZEND_VM_HANDLER(64, ZEND_RECV_INIT, ANY, CONST) if (param == NULL) { ALLOC_ZVAL(assignment_value); *assignment_value = *opline->op2.zv; - switch (Z_TYPE_P(assignment_value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: - Z_SET_REFCOUNT_P(assignment_value, 1); - zval_update_constant(&assignment_value, 0 TSRMLS_CC); - break; - default: - zval_copy_ctor(assignment_value); - break; + if (IS_CONSTANT_TYPE(Z_TYPE_P(assignment_value))) { + Z_SET_REFCOUNT_P(assignment_value, 1); + zval_update_constant(&assignment_value, 0 TSRMLS_CC); + } else { + zval_copy_ctor(assignment_value); } INIT_PZVAL(assignment_value); } else { @@ -3584,16 +3579,12 @@ ZEND_VM_HANDLER(99, ZEND_FETCH_CONSTANT, VAR|CONST|UNUSED, CONST) } if (EXPECTED(zend_hash_quick_find(&ce->constants_table, Z_STRVAL_P(opline->op2.zv), Z_STRLEN_P(opline->op2.zv)+1, Z_HASH_P(opline->op2.zv), (void **) &value) == SUCCESS)) { - switch (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zend_class_entry *old_scope = EG(scope); - - EG(scope) = ce; - zval_update_constant(value, (void *) 1 TSRMLS_CC); - EG(scope) = old_scope; - } + if (IS_CONSTANT_TYPE(Z_TYPE_PP(value))) { + zend_class_entry *old_scope = EG(scope); + + EG(scope) = ce; + zval_update_constant(value, (void *) 1 TSRMLS_CC); + EG(scope) = old_scope; } if (OP1_TYPE == IS_CONST) { CACHE_PTR(opline->op2.literal->cache_slot, value); @@ -5194,28 +5185,22 @@ ZEND_VM_HANDLER(143, ZEND_DECLARE_CONST, CONST, CONST) name = GET_OP1_ZVAL_PTR(BP_VAR_R); val = GET_OP2_ZVAL_PTR(BP_VAR_R); - switch (Z_TYPE_P(val) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zval tmp; - zval *tmp_ptr = &tmp; + if (IS_CONSTANT_TYPE(Z_TYPE_P(val))) { + zval tmp; + zval *tmp_ptr = &tmp; - ZVAL_COPY_VALUE(&tmp, val); - if (Z_TYPE_P(val) == IS_CONSTANT_ARRAY) { - zval_copy_ctor(&tmp); - } - INIT_PZVAL(&tmp); - zval_update_constant(&tmp_ptr, NULL TSRMLS_CC); - c.value = *tmp_ptr; + ZVAL_COPY_VALUE(&tmp, val); + if (Z_TYPE_P(val) == IS_CONSTANT_ARRAY) { + zval_copy_ctor(&tmp); } - break; - - default: - INIT_PZVAL_COPY(&c.value, val); - zval_copy_ctor(&c.value); - break; + INIT_PZVAL(&tmp); + zval_update_constant(&tmp_ptr, NULL TSRMLS_CC); + c.value = *tmp_ptr; + } else { + INIT_PZVAL_COPY(&c.value, val); + zval_copy_ctor(&c.value); } + c.flags = CONST_CS; /* non persistent, case sensetive */ c.name = str_strndup(Z_STRVAL_P(name), Z_STRLEN_P(name)); c.name_len = Z_STRLEN_P(name)+1; diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index a90f187..d99bcd1 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -1435,16 +1435,11 @@ static int ZEND_FASTCALL ZEND_RECV_INIT_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ if (param == NULL) { ALLOC_ZVAL(assignment_value); *assignment_value = *opline->op2.zv; - switch (Z_TYPE_P(assignment_value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: - Z_SET_REFCOUNT_P(assignment_value, 1); - zval_update_constant(&assignment_value, 0 TSRMLS_CC); - break; - default: - zval_copy_ctor(assignment_value); - break; + if (IS_CONSTANT_TYPE(Z_TYPE_P(assignment_value))) { + Z_SET_REFCOUNT_P(assignment_value, 1); + zval_update_constant(&assignment_value, 0 TSRMLS_CC); + } else { + zval_copy_ctor(assignment_value); } INIT_PZVAL(assignment_value); } else { @@ -3796,16 +3791,12 @@ static int ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_CONST_CONST_HANDLER(ZEND_OPCO } if (EXPECTED(zend_hash_quick_find(&ce->constants_table, Z_STRVAL_P(opline->op2.zv), Z_STRLEN_P(opline->op2.zv)+1, Z_HASH_P(opline->op2.zv), (void **) &value) == SUCCESS)) { - switch (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zend_class_entry *old_scope = EG(scope); + if (IS_CONSTANT_TYPE(Z_TYPE_PP(value))) { + zend_class_entry *old_scope = EG(scope); - EG(scope) = ce; - zval_update_constant(value, (void *) 1 TSRMLS_CC); - EG(scope) = old_scope; - } + EG(scope) = ce; + zval_update_constant(value, (void *) 1 TSRMLS_CC); + EG(scope) = old_scope; } if (IS_CONST == IS_CONST) { CACHE_PTR(opline->op2.literal->cache_slot, value); @@ -4096,28 +4087,22 @@ static int ZEND_FASTCALL ZEND_DECLARE_CONST_SPEC_CONST_CONST_HANDLER(ZEND_OPCOD name = opline->op1.zv; val = opline->op2.zv; - switch (Z_TYPE_P(val) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zval tmp; - zval *tmp_ptr = &tmp; + if (IS_CONSTANT_TYPE(Z_TYPE_P(val))) { + zval tmp; + zval *tmp_ptr = &tmp; - ZVAL_COPY_VALUE(&tmp, val); - if (Z_TYPE_P(val) == IS_CONSTANT_ARRAY) { - zval_copy_ctor(&tmp); - } - INIT_PZVAL(&tmp); - zval_update_constant(&tmp_ptr, NULL TSRMLS_CC); - c.value = *tmp_ptr; + ZVAL_COPY_VALUE(&tmp, val); + if (Z_TYPE_P(val) == IS_CONSTANT_ARRAY) { + zval_copy_ctor(&tmp); } - break; - - default: - INIT_PZVAL_COPY(&c.value, val); - zval_copy_ctor(&c.value); - break; + INIT_PZVAL(&tmp); + zval_update_constant(&tmp_ptr, NULL TSRMLS_CC); + c.value = *tmp_ptr; + } else { + INIT_PZVAL_COPY(&c.value, val); + zval_copy_ctor(&c.value); } + c.flags = CONST_CS; /* non persistent, case sensetive */ c.name = str_strndup(Z_STRVAL_P(name), Z_STRLEN_P(name)); c.name_len = Z_STRLEN_P(name)+1; @@ -15649,16 +15634,12 @@ static int ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_VAR_CONST_HANDLER(ZEND_OPCODE } if (EXPECTED(zend_hash_quick_find(&ce->constants_table, Z_STRVAL_P(opline->op2.zv), Z_STRLEN_P(opline->op2.zv)+1, Z_HASH_P(opline->op2.zv), (void **) &value) == SUCCESS)) { - switch (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zend_class_entry *old_scope = EG(scope); + if (IS_CONSTANT_TYPE(Z_TYPE_PP(value))) { + zend_class_entry *old_scope = EG(scope); - EG(scope) = ce; - zval_update_constant(value, (void *) 1 TSRMLS_CC); - EG(scope) = old_scope; - } + EG(scope) = ce; + zval_update_constant(value, (void *) 1 TSRMLS_CC); + EG(scope) = old_scope; } if (IS_VAR == IS_CONST) { CACHE_PTR(opline->op2.literal->cache_slot, value); @@ -25188,16 +25169,12 @@ static int ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_UNUSED_CONST_HANDLER(ZEND_OPC } if (EXPECTED(zend_hash_quick_find(&ce->constants_table, Z_STRVAL_P(opline->op2.zv), Z_STRLEN_P(opline->op2.zv)+1, Z_HASH_P(opline->op2.zv), (void **) &value) == SUCCESS)) { - switch (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: { - zend_class_entry *old_scope = EG(scope); + if (IS_CONSTANT_TYPE(Z_TYPE_PP(value))) { + zend_class_entry *old_scope = EG(scope); - EG(scope) = ce; - zval_update_constant(value, (void *) 1 TSRMLS_CC); - EG(scope) = old_scope; - } + EG(scope) = ce; + zval_update_constant(value, (void *) 1 TSRMLS_CC); + EG(scope) = old_scope; } if (IS_UNUSED == IS_CONST) { CACHE_PTR(opline->op2.literal->cache_slot, value); diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index abebc21..bff5e66 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2599,14 +2599,8 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) *return_value = *precv->op2.zv; INIT_PZVAL(return_value); - switch (Z_TYPE_P(return_value) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: - break; - - default: - zval_copy_ctor(return_value); + if (!IS_CONSTANT_TYPE(Z_TYPE_P(return_value))) { + zval_copy_ctor(return_value); } zval_update_constant_ex(&return_value, (void*)0, param->fptr->common.scope TSRMLS_CC); } @@ -3419,11 +3413,8 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value /* this is necessary to make it able to work with default array * properties, returned to user */ - switch (Z_TYPE_P(prop_copy) & IS_CONSTANT_TYPE_MASK) { - case IS_CONSTANT: - case IS_CONSTANT_ARRAY: - case IS_CONSTANT_AST: - zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); + if (IS_CONSTANT_TYPE(Z_TYPE_P(prop_copy))) { + zval_update_constant(&prop_copy, (void *) 1 TSRMLS_CC); } add_assoc_zval(return_value, key, prop_copy);