diff options
Diffstat (limited to 'Zend/zend_builtin_functions.c')
| -rw-r--r-- | Zend/zend_builtin_functions.c | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 81c78f2a97..987d70ab3e 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -361,7 +361,7 @@ ZEND_FUNCTION(gc_collect_cycles) Returns status of the circular reference collector */ ZEND_FUNCTION(gc_enabled) { - RETURN_BOOL(GC_G(gc_enabled)); + RETURN_BOOL(gc_enabled()); } /* }}} */ @@ -472,10 +472,10 @@ ZEND_FUNCTION(func_get_args) arg_count = ZEND_CALL_NUM_ARGS(ex); - array_init_size(return_value, arg_count); if (arg_count) { + array_init_size(return_value, arg_count); first_extra_arg = ex->func->op_array.num_args; - zend_hash_real_init(Z_ARRVAL_P(return_value), 1); + zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { i = 0; p = ZEND_CALL_ARG(ex, 1); @@ -484,7 +484,7 @@ ZEND_FUNCTION(func_get_args) q = p; if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) { ZVAL_DEREF(q); - if (Z_OPT_REFCOUNTED_P(q)) { + if (Z_OPT_REFCOUNTED_P(q)) { Z_ADDREF_P(q); } } else { @@ -500,7 +500,7 @@ ZEND_FUNCTION(func_get_args) q = p; if (EXPECTED(Z_TYPE_INFO_P(q) != IS_UNDEF)) { ZVAL_DEREF(q); - if (Z_OPT_REFCOUNTED_P(q)) { + if (Z_OPT_REFCOUNTED_P(q)) { Z_ADDREF_P(q); } } else { @@ -512,6 +512,8 @@ ZEND_FUNCTION(func_get_args) } } ZEND_HASH_FILL_END(); Z_ARRVAL_P(return_value)->nNumOfElements = arg_count; + } else { + ZVAL_EMPTY_ARRAY(return_value); } } /* }}} */ @@ -642,16 +644,12 @@ ZEND_FUNCTION(each) break; } array_init_size(return_value, 4); - zend_hash_real_init(Z_ARRVAL_P(return_value), 0); + zend_hash_real_init_mixed(Z_ARRVAL_P(return_value)); /* add value elements */ - if (Z_ISREF_P(entry)) { - ZVAL_DUP(&tmp, Z_REFVAL_P(entry)); - entry = &tmp; - if (Z_REFCOUNTED_P(entry)) Z_ADDREF_P(entry); - } else { - if (Z_REFCOUNTED_P(entry)) Z_ADDREF_P(entry); - if (Z_REFCOUNTED_P(entry)) Z_ADDREF_P(entry); + ZVAL_DEREF(entry); + if (Z_REFCOUNTED_P(entry)) { + GC_ADDREF_EX(Z_COUNTED_P(entry), 2); } zend_hash_index_add_new(Z_ARRVAL_P(return_value), 1, entry); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_VALUE), entry); @@ -659,7 +657,7 @@ ZEND_FUNCTION(each) /* add the key elements */ if (zend_hash_get_current_key(target_hash, &key, &num_key) == HASH_KEY_IS_STRING) { ZVAL_STR_COPY(&tmp, key); - if (Z_REFCOUNTED(tmp)) Z_ADDREF(tmp); + Z_TRY_ADDREF(tmp); } else { ZVAL_LONG(&tmp, num_key); } @@ -688,9 +686,9 @@ ZEND_FUNCTION(error_reporting) zend_ini_entry *p = EG(error_reporting_ini_entry); if (!p) { - p = zend_hash_find_ptr(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING)); - if (p) { - EG(error_reporting_ini_entry) = p; + zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1); + if (zv) { + p = EG(error_reporting_ini_entry) = (zend_ini_entry*)Z_PTR_P(zv); } else { break; } @@ -727,13 +725,13 @@ static int validate_constant_array(HashTable *ht) /* {{{ */ int ret = 1; zval *val; - ht->u.v.nApplyCount++; + GC_PROTECT_RECURSION(ht); ZEND_HASH_FOREACH_VAL_IND(ht, val) { ZVAL_DEREF(val); if (Z_REFCOUNTED_P(val)) { if (Z_TYPE_P(val) == IS_ARRAY) { if (Z_REFCOUNTED_P(val)) { - if (Z_ARRVAL_P(val)->u.v.nApplyCount > 0) { + if (Z_IS_RECURSIVE_P(val)) { zend_error(E_WARNING, "Constants cannot be recursive arrays"); ret = 0; break; @@ -749,7 +747,7 @@ static int validate_constant_array(HashTable *ht) /* {{{ */ } } } ZEND_HASH_FOREACH_END(); - ht->u.v.nApplyCount--; + GC_UNPROTECT_RECURSION(ht); return ret; } /* }}} */ @@ -773,14 +771,14 @@ static void copy_constant_array(zval *dst, zval *src) /* {{{ */ if (Z_REFCOUNTED_P(val)) { copy_constant_array(new_val, val); } - } else if (Z_REFCOUNTED_P(val)) { - Z_ADDREF_P(val); + } else { + Z_TRY_ADDREF_P(val); } } ZEND_HASH_FOREACH_END(); } /* }}} */ -/* {{{ proto bool define(string constant_name, mixed value[, boolean case_insensitive]) +/* {{{ proto bool define(string constant_name, mixed value[, bool case_insensitive]) Define a new constant */ ZEND_FUNCTION(define) { @@ -1062,16 +1060,12 @@ static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, int st /* copy: enforce read only access */ ZVAL_DEREF(prop); - if (UNEXPECTED(Z_COPYABLE_P(prop))) { - ZVAL_DUP(&prop_copy, prop); - prop = &prop_copy; - } else { - Z_TRY_ADDREF_P(prop); - } + ZVAL_COPY_OR_DUP(&prop_copy, prop); + prop = &prop_copy; /* this is necessary to make it able to work with default array * properties, returned to user */ - if (Z_OPT_CONSTANT_P(prop)) { + if (Z_OPT_TYPE_P(prop) == IS_CONSTANT_AST) { if (UNEXPECTED(zval_update_constant_ex(prop, NULL) != SUCCESS)) { return; } @@ -1137,7 +1131,7 @@ ZEND_FUNCTION(get_object_vars) zobj = Z_OBJ_P(obj); - if (!zobj->ce->default_properties_count && properties == zobj->properties && !ZEND_HASH_GET_APPLY_COUNT(properties)) { + if (!zobj->ce->default_properties_count && properties == zobj->properties && !GC_IS_RECURSIVE(properties)) { /* fast copy */ if (EXPECTED(zobj->handlers == &std_object_handlers)) { RETURN_ARR(zend_proptable_to_symtable(properties, 0)); @@ -1279,7 +1273,7 @@ ZEND_FUNCTION(method_exists) Z_PARAM_ZVAL(klass) Z_PARAM_STR(method_name) ZEND_PARSE_PARAMETERS_END(); - + if (Z_TYPE_P(klass) == IS_OBJECT) { ce = Z_OBJCE_P(klass); } else if (Z_TYPE_P(klass) == IS_STRING) { @@ -1527,7 +1521,7 @@ ZEND_FUNCTION(class_alias) if (ce) { if (ce->type == ZEND_USER_CLASS) { - if (zend_register_class_alias_ex(alias_name, alias_name_len, ce) == SUCCESS) { + if (zend_register_class_alias_ex(alias_name, alias_name_len, ce, 0) == SUCCESS) { RETURN_TRUE; } else { zend_error(E_WARNING, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), alias_name); @@ -2030,7 +2024,7 @@ static int add_constant_info(zval *item, void *arg) /* {{{ */ return 0; } - ZVAL_DUP(&const_val, &constant->value); + ZVAL_COPY_OR_DUP(&const_val, &constant->value); zend_hash_add_new(Z_ARRVAL_P(name_array), constant->name, &const_val); return 0; } @@ -2106,7 +2100,7 @@ ZEND_FUNCTION(get_defined_constants) add_assoc_zval(return_value, module_names[module_number], &modules[module_number]); } - ZVAL_DUP(&const_val, &val->value); + ZVAL_COPY_OR_DUP(&const_val, &val->value); zend_hash_add_new(Z_ARRVAL(modules[module_number]), val->name, &const_val); } ZEND_HASH_FOREACH_END(); @@ -2122,12 +2116,12 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) / { uint32_t num_args = ZEND_CALL_NUM_ARGS(call); - array_init_size(arg_array, num_args); if (num_args) { uint32_t i = 0; zval *p = ZEND_CALL_ARG(call, 1); - zend_hash_real_init(Z_ARRVAL_P(arg_array), 1); + array_init_size(arg_array, num_args); + zend_hash_real_init_packed(Z_ARRVAL_P(arg_array)); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(arg_array)) { if (call->func->type == ZEND_USER_FUNCTION) { uint32_t first_extra_arg = MIN(num_args, call->func->op_array.num_args); @@ -2142,7 +2136,7 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) / while (i < first_extra_arg) { arg_name = call->func->op_array.vars[i]; - arg = zend_hash_find_ind(call->symbol_table, arg_name); + arg = zend_hash_find_ex_ind(call->symbol_table, arg_name, 1); if (arg) { if (Z_OPT_REFCOUNTED_P(arg)) { Z_ADDREF_P(arg); @@ -2184,6 +2178,8 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) / } } ZEND_HASH_FILL_END(); Z_ARRVAL_P(arg_array)->nNumOfElements = num_args; + } else { + ZVAL_EMPTY_ARRAY(arg_array); } } /* }}} */ |
