diff options
Diffstat (limited to 'Zend/zend_execute_API.c')
-rw-r--r-- | Zend/zend_execute_API.c | 173 |
1 files changed, 68 insertions, 105 deletions
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index e46d0d84ee..ab0459507c 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -47,7 +47,7 @@ ZEND_API void (*zend_execute_internal)(zend_execute_data *execute_data, zval *re /* true globals */ ZEND_API const zend_fcall_info empty_fcall_info = { 0, {{0}, {{0}}, {0}}, NULL, NULL, NULL, 0, 0 }; -ZEND_API const zend_fcall_info_cache empty_fcall_info_cache = { 0, NULL, NULL, NULL, NULL }; +ZEND_API const zend_fcall_info_cache empty_fcall_info_cache = { NULL, NULL, NULL, NULL }; #ifdef ZEND_WIN32 ZEND_TLS HANDLE tq_timer = NULL; @@ -302,7 +302,7 @@ void shutdown_executor(void) /* {{{ */ zend_hash_graceful_reverse_destroy(&EG(symbol_table)); #if ZEND_DEBUG - if (GC_G(gc_enabled) && !CG(unclean_shutdown)) { + if (gc_enabled() && !CG(unclean_shutdown)) { gc_collect_cycles(); } #endif @@ -335,7 +335,7 @@ void shutdown_executor(void) /* {{{ */ if (c->flags & CONST_PERSISTENT) { break; } - zval_ptr_dtor(&c->value); + zval_ptr_dtor_nogc(&c->value); if (c->name) { zend_string_release(c->name); } @@ -544,90 +544,64 @@ ZEND_API void _zval_internal_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ * } /* }}} */ -ZEND_API int zval_update_constant_ex(zval *p, zend_class_entry *scope) /* {{{ */ +ZEND_API int zend_use_undefined_constant(zend_string *name, zend_ast_attr attr, zval *result) /* {{{ */ { - zval *const_value; char *colon; - zend_bool inline_change; - if (Z_TYPE_P(p) == IS_CONSTANT) { - if (IS_CONSTANT_VISITED(p)) { - zend_throw_error(NULL, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p)); + if (UNEXPECTED(EG(exception))) { + return FAILURE; + } else if ((colon = (char*)zend_memrchr(ZSTR_VAL(name), ':', ZSTR_LEN(name)))) { + zend_throw_error(NULL, "Undefined class constant '%s'", ZSTR_VAL(name)); + return FAILURE; + } else if ((attr & IS_CONSTANT_UNQUALIFIED) == 0) { + zend_throw_error(NULL, "Undefined constant '%s'", ZSTR_VAL(name)); + return FAILURE; + } else { + char *actual = ZSTR_VAL(name); + size_t actual_len = ZSTR_LEN(name); + char *slash = (char *) zend_memrchr(actual, '\\', actual_len); + + if (slash) { + actual = slash + 1; + actual_len -= (actual - ZSTR_VAL(name)); + } + + zend_error(E_WARNING, "Use of undefined constant %s - assumed '%s' (this will throw an Error in a future version of PHP)", actual, actual); + if (EG(exception)) { return FAILURE; + } else { + zend_string *result_str = zend_string_init(actual, actual_len, 0); + zval_ptr_dtor_nogc(result); + ZVAL_NEW_STR(result, result_str); } - inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_REFCOUNTED) != 0; - SEPARATE_ZVAL_NOREF(p); - MARK_CONSTANT_VISITED(p); - if (Z_CONST_FLAGS_P(p) & IS_CONSTANT_CLASS) { - ZEND_ASSERT(EG(current_execute_data)); - if (inline_change) { - zend_string_release(Z_STR_P(p)); - } - if (scope && scope->name) { - ZVAL_STR_COPY(p, scope->name); - } else { - ZVAL_EMPTY_STRING(p); - } - } else if (UNEXPECTED((const_value = zend_get_constant_ex(Z_STR_P(p), scope, Z_CONST_FLAGS_P(p))) == NULL)) { - if (UNEXPECTED(EG(exception))) { - RESET_CONSTANT_VISITED(p); - return FAILURE; - } else if ((colon = (char*)zend_memrchr(Z_STRVAL_P(p), ':', Z_STRLEN_P(p)))) { - zend_throw_error(NULL, "Undefined class constant '%s'", Z_STRVAL_P(p)); - RESET_CONSTANT_VISITED(p); - return FAILURE; - } else { - if ((Z_CONST_FLAGS_P(p) & IS_CONSTANT_UNQUALIFIED) == 0) { - zend_throw_error(NULL, "Undefined constant '%s'", Z_STRVAL_P(p)); - RESET_CONSTANT_VISITED(p); - return FAILURE; - } else { - zend_string *save = Z_STR_P(p); - char *actual = Z_STRVAL_P(p); - size_t actual_len = Z_STRLEN_P(p); - char *slash = (char *) zend_memrchr(actual, '\\', actual_len); - if (slash) { - actual = slash + 1; - actual_len -= (actual - Z_STRVAL_P(p)); - } + } + return SUCCESS; +} +/* }}} */ - zend_error(E_WARNING, "Use of undefined constant %s - assumed '%s' (this will throw an Error in a future version of PHP)", actual, actual); - if (EG(exception)) { - RESET_CONSTANT_VISITED(p); - return FAILURE; - } +ZEND_API int zval_update_constant_ex(zval *p, zend_class_entry *scope) /* {{{ */ +{ + if (Z_TYPE_P(p) == IS_CONSTANT_AST) { + zend_ast *ast = Z_ASTVAL_P(p); - if (!inline_change) { - ZVAL_STRINGL(p, actual, actual_len); - } else { - if (slash) { - ZVAL_STRINGL(p, actual, actual_len); - zend_string_release(save); - } else { - Z_TYPE_INFO_P(p) = Z_REFCOUNTED_P(p) ? - IS_STRING_EX : IS_INTERNED_STRING_EX; - } - } - } + if (ast->kind == ZEND_AST_CONSTANT) { + zend_string *name = zend_ast_get_constant_name(ast); + zval *zv = zend_get_constant_ex(name, scope, ast->attr); + + if (UNEXPECTED(zv == NULL)) { + return zend_use_undefined_constant(name, ast->attr, p); } + zval_ptr_dtor_nogc(p); + ZVAL_COPY_OR_DUP(p, zv); } else { - if (inline_change) { - zend_string_release(Z_STR_P(p)); - } - ZVAL_COPY_VALUE(p, const_value); - zval_opt_copy_ctor(p); - } - } else if (Z_TYPE_P(p) == IS_CONSTANT_AST) { - zval tmp; + zval tmp; - inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_REFCOUNTED) != 0; - if (UNEXPECTED(zend_ast_evaluate(&tmp, Z_ASTVAL_P(p), scope) != SUCCESS)) { - return FAILURE; - } - if (inline_change) { - zval_ptr_dtor(p); + if (UNEXPECTED(zend_ast_evaluate(&tmp, ast, scope) != SUCCESS)) { + return FAILURE; + } + zval_ptr_dtor_nogc(p); + ZVAL_COPY_VALUE(p, &tmp); } - ZVAL_COPY_VALUE(p, &tmp); } return SUCCESS; } @@ -672,13 +646,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) / return FAILURE; /* we would result in an instable executor otherwise */ } - switch (fci->size) { - case sizeof(zend_fcall_info): - break; /* nothing to do currently */ - default: - zend_error_noreturn(E_CORE_ERROR, "Corrupted fcall_info provided to zend_call_function()"); - break; - } + ZEND_ASSERT(fci->size == sizeof(zend_fcall_info)); /* Initialize execute_data */ if (!EG(current_execute_data)) { @@ -703,7 +671,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) / EG(current_execute_data) = &dummy_execute_data; } - if (!fci_cache || !fci_cache->initialized) { + if (!fci_cache || !fci_cache->function_handler) { char *error = NULL; if (!fci_cache) { @@ -802,8 +770,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) / if (UNEXPECTED(func->op_array.fn_flags & ZEND_ACC_CLOSURE)) { uint32_t call_info; - ZEND_ASSERT(GC_TYPE((zend_object*)func->op_array.prototype) == IS_OBJECT); - GC_REFCOUNT((zend_object*)func->op_array.prototype)++; + GC_ADDREF(ZEND_CLOSURE_OBJECT(func)); call_info = ZEND_CALL_CLOSURE; if (func->common.fn_flags & ZEND_ACC_FAKE_CLOSURE) { call_info |= ZEND_CALL_FAKE_CLOSURE; @@ -811,7 +778,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) / ZEND_ADD_CALL_FLAG(call, call_info); } - if (func->type == ZEND_USER_FUNCTION) { + if (func->type == ZEND_USER_FUNCTION) { int call_via_handler = (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0; const zend_op *current_opline_before_exception = EG(opline_before_exception); @@ -820,7 +787,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) / EG(opline_before_exception) = current_opline_before_exception; if (call_via_handler) { /* We must re-initialize function again */ - fci_cache->initialized = 0; + fci_cache->function_handler = NULL; } } else if (func->type == ZEND_INTERNAL_FUNCTION) { int call_via_handler = (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0; @@ -844,7 +811,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) / if (call_via_handler) { /* We must re-initialize function again */ - fci_cache->initialized = 0; + fci_cache->function_handler = NULL; } } else { /* ZEND_OVERLOADED_FUNCTION */ ZVAL_NULL(fci->retval); @@ -894,7 +861,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) / ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload) /* {{{ */ { zend_class_entry *ce = NULL; - zval args[1]; + zval args[1], *zv; zval local_retval; zend_string *lc_name; zend_fcall_info fcall_info; @@ -915,12 +882,12 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k } } - ce = zend_hash_find_ptr(EG(class_table), lc_name); - if (ce) { + zv = zend_hash_find(EG(class_table), lc_name); + if (zv) { if (!key) { zend_string_release(lc_name); } - return ce; + return (zend_class_entry*)Z_PTR_P(zv); } /* The compiler is not-reentrant. Make sure we __autoload() only during run-time @@ -934,9 +901,9 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k } if (!EG(autoload_func)) { - zend_function *func = zend_hash_find_ptr(EG(function_table), ZSTR_KNOWN(ZEND_STR_MAGIC_AUTOLOAD)); - if (func) { - EG(autoload_func) = func; + zval *zv = zend_hash_find_ex(EG(function_table), ZSTR_KNOWN(ZEND_STR_MAGIC_AUTOLOAD), 1); + if (zv) { + EG(autoload_func) = (zend_function*)Z_PTR_P(zv); } else { if (!key) { zend_string_release(lc_name); @@ -980,9 +947,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k fcall_info.object = NULL; fcall_info.no_separation = 1; - fcall_cache.initialized = 1; fcall_cache.function_handler = EG(autoload_func); - fcall_cache.calling_scope = NULL; fcall_cache.called_scope = NULL; fcall_cache.object = NULL; @@ -1054,7 +1019,7 @@ ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char int retval; if (retval_ptr) { - ZVAL_NEW_STR(&pv, zend_string_alloc(str_len + sizeof("return ;")-1, 1)); + ZVAL_NEW_STR(&pv, zend_string_alloc(str_len + sizeof("return ;")-1, 0)); memcpy(Z_STRVAL(pv), "return ", sizeof("return ") - 1); memcpy(Z_STRVAL(pv) + sizeof("return ") - 1, str, str_len); Z_STRVAL(pv)[Z_STRLEN(pv) - 1] = ';'; @@ -1529,12 +1494,11 @@ ZEND_API zend_array *zend_rebuild_symbol_table(void) /* {{{ */ } zend_hash_extend(symbol_table, ex->func->op_array.last_var, 0); } else { - symbol_table = ex->symbol_table = emalloc(sizeof(zend_array)); - zend_hash_init(symbol_table, ex->func->op_array.last_var, NULL, ZVAL_PTR_DTOR, 0); + symbol_table = ex->symbol_table = zend_new_array(ex->func->op_array.last_var); if (!ex->func->op_array.last_var) { return symbol_table; } - zend_hash_real_init(symbol_table, 0); + zend_hash_real_init_mixed(symbol_table); /*printf("Cache miss! Initialized %x\n", EG(active_symbol_table));*/ } if (EXPECTED(ex->func->op_array.last_var)) { @@ -1565,7 +1529,7 @@ ZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data) /* {{{ * zval *var = EX_VAR_NUM(0); do { - zval *zv = zend_hash_find(ht, *str); + zval *zv = zend_hash_find_ex(ht, *str, 1); if (zv) { if (Z_TYPE_P(zv) == IS_INDIRECT) { @@ -1631,8 +1595,7 @@ ZEND_API int zend_set_local_var(zend_string *name, zval *value, int force) /* {{ do { if (ZSTR_H(*str) == h && - ZSTR_LEN(*str) == ZSTR_LEN(name) && - memcmp(ZSTR_VAL(*str), ZSTR_VAL(name), ZSTR_LEN(name)) == 0) { + zend_string_equal_content(*str, name)) { zval *var = EX_VAR_NUM(str - op_array->vars); ZVAL_COPY_VALUE(var, value); return SUCCESS; |