diff options
Diffstat (limited to 'Zend/zend_builtin_functions.c')
-rw-r--r-- | Zend/zend_builtin_functions.c | 822 |
1 files changed, 371 insertions, 451 deletions
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 6bfb888988..8139a443f7 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -349,7 +349,7 @@ int zend_startup_builtin_functions(TSRMLS_D) /* {{{ */ Get the version of the Zend Engine */ ZEND_FUNCTION(zend_version) { - RETURN_STRINGL(ZEND_VERSION, sizeof(ZEND_VERSION)-1, 1); + RETURN_STRINGL(ZEND_VERSION, sizeof(ZEND_VERSION)-1); } /* }}} */ @@ -374,7 +374,9 @@ ZEND_FUNCTION(gc_enabled) Activates the circular reference collector */ ZEND_FUNCTION(gc_enable) { - zend_alter_ini_entry("zend.enable_gc", sizeof("zend.enable_gc"), "1", sizeof("1")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); + zend_string *key = STR_INIT("zend.enable_gc", sizeof("zend.enable_gc")-1, 0); + zend_alter_ini_entry(key, "1", sizeof("1")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); + STR_FREE(key); } /* }}} */ @@ -382,7 +384,9 @@ ZEND_FUNCTION(gc_enable) Deactivates the circular reference collector */ ZEND_FUNCTION(gc_disable) { - zend_alter_ini_entry("zend.enable_gc", sizeof("zend.enable_gc"), "0", sizeof("0")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); + zend_string *key = STR_INIT("zend.enable_gc", sizeof("zend.enable_gc")-1, 0); + zend_alter_ini_entry(key, "0", sizeof("0")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); + STR_FREE(key); } /* }}} */ @@ -393,7 +397,7 @@ ZEND_FUNCTION(func_num_args) zend_execute_data *ex = EG(current_execute_data)->prev_execute_data; if (ex && ex->function_state.arguments) { - RETURN_LONG((long)(zend_uintptr_t)*(ex->function_state.arguments)); + RETURN_LONG(Z_LVAL_P(ex->function_state.arguments)); } else { zend_error(E_WARNING, "func_num_args(): Called from the global scope - no function context"); RETURN_LONG(-1); @@ -406,7 +410,7 @@ ZEND_FUNCTION(func_num_args) Get the $arg_num'th argument that was passed to the function */ ZEND_FUNCTION(func_get_arg) { - void **p; + zval *p; int arg_count; zval *arg; long requested_offset; @@ -427,14 +431,14 @@ ZEND_FUNCTION(func_get_arg) } p = ex->function_state.arguments; - arg_count = (int)(zend_uintptr_t) *p; /* this is the amount of arguments passed to func_get_arg(); */ + arg_count = Z_LVAL_P(p); /* this is the amount of arguments passed to func_get_arg(); */ if (requested_offset >= arg_count) { zend_error(E_WARNING, "func_get_arg(): Argument %ld not passed to function", requested_offset); RETURN_FALSE; } - arg = *(p-(arg_count-requested_offset)); + arg = p-(arg_count-requested_offset); RETURN_ZVAL_FAST(arg); } /* }}} */ @@ -444,7 +448,7 @@ ZEND_FUNCTION(func_get_arg) Get an array of the arguments that were passed to the function */ ZEND_FUNCTION(func_get_args) { - void **p; + zval *p; int arg_count; int i; zend_execute_data *ex = EG(current_execute_data)->prev_execute_data; @@ -455,22 +459,21 @@ ZEND_FUNCTION(func_get_args) } p = ex->function_state.arguments; - arg_count = (int)(zend_uintptr_t) *p; /* this is the amount of arguments passed to func_get_args(); */ + arg_count = Z_LVAL_P(p); /* this is the amount of arguments passed to func_get_args(); */ array_init_size(return_value, arg_count); for (i=0; i<arg_count; i++) { - zval *element, *arg; + zval *element, *arg, tmp; - arg = *((zval **) (p-(arg_count-i))); + arg = p-(arg_count-i); if (!Z_ISREF_P(arg)) { element = arg; Z_ADDREF_P(element); } else { - ALLOC_ZVAL(element); - INIT_PZVAL_COPY(element, arg); - zval_copy_ctor(element); + ZVAL_DUP(&tmp, Z_REFVAL_P(arg)); + element = &tmp; } - zend_hash_next_index_insert(return_value->value.ht, &element, sizeof(zval *), NULL); + zend_hash_next_index_insert(Z_ARRVAL_P(return_value), element); } } /* }}} */ @@ -572,12 +575,11 @@ ZEND_FUNCTION(strncasecmp) Return the currently pointed key..value pair in the passed array, and advance the pointer to the next element */ ZEND_FUNCTION(each) { - zval *array, *entry, **entry_ptr, *tmp; - char *string_key; - uint string_key_len; + zval *array, *entry, tmp; ulong num_key; - zval **inserted_pointer; + zval *inserted_pointer; HashTable *target_hash; + zend_string *key; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &array) == FAILURE) { return; @@ -588,37 +590,34 @@ ZEND_FUNCTION(each) zend_error(E_WARNING,"Variable passed to each() is not an array or object"); return; } - if (zend_hash_get_current_data(target_hash, (void **) &entry_ptr)==FAILURE) { + entry = zend_hash_get_current_data(target_hash); + if (!entry) { RETURN_FALSE; } array_init(return_value); - entry = *entry_ptr; /* add value elements */ if (Z_ISREF_P(entry)) { - ALLOC_ZVAL(tmp); - *tmp = *entry; - zval_copy_ctor(tmp); - Z_UNSET_ISREF_P(tmp); - Z_SET_REFCOUNT_P(tmp, 0); - entry=tmp; - } - zend_hash_index_update(return_value->value.ht, 1, &entry, sizeof(zval *), NULL); + ZVAL_DUP(&tmp, Z_REFVAL_P(entry)); + Z_SET_REFCOUNT(tmp, 0); + entry = &tmp; + } + zend_hash_index_update(Z_ARRVAL_P(return_value), 1, entry); Z_ADDREF_P(entry); - zend_hash_update(return_value->value.ht, "value", sizeof("value"), &entry, sizeof(zval *), NULL); + zend_hash_str_update(Z_ARRVAL_P(return_value), "value", sizeof("value")-1, entry); Z_ADDREF_P(entry); /* add the key elements */ - switch (zend_hash_get_current_key_ex(target_hash, &string_key, &string_key_len, &num_key, 0, NULL)) { + switch (zend_hash_get_current_key_ex(target_hash, &key, &num_key, 0, NULL)) { case HASH_KEY_IS_STRING: - add_get_index_stringl(return_value, 0, string_key, string_key_len-1, (void **) &inserted_pointer, !IS_INTERNED(string_key)); + inserted_pointer = add_get_index_str(return_value, 0, key); break; case HASH_KEY_IS_LONG: - add_get_index_long(return_value, 0, num_key, (void **) &inserted_pointer); + inserted_pointer = add_get_index_long(return_value, 0, num_key); break; } - zend_hash_update(return_value->value.ht, "key", sizeof("key"), inserted_pointer, sizeof(zval *), NULL); - Z_ADDREF_PP(inserted_pointer); + zend_hash_str_update(Z_ARRVAL_P(return_value), "key", sizeof("key")-1, inserted_pointer); + Z_ADDREF_P(inserted_pointer); zend_hash_move_forward(target_hash); } /* }}} */ @@ -638,7 +637,9 @@ ZEND_FUNCTION(error_reporting) old_error_reporting = EG(error_reporting); if(ZEND_NUM_ARGS() != 0) { - zend_alter_ini_entry("error_reporting", sizeof("error_reporting"), err, err_len, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); + zend_string *key = STR_INIT("error_reporting", sizeof("error_reporting")-1, 0); + zend_alter_ini_entry(key, err, err_len, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); + STR_FREE(key); } RETVAL_LONG(old_error_reporting); @@ -652,8 +653,7 @@ ZEND_FUNCTION(define) { char *name; int name_len; - zval *val; - zval *val_free = NULL; + zval *val, val_free; zend_bool non_cs = 0; int case_sensitive = CONST_CS; zend_constant c; @@ -672,6 +672,8 @@ ZEND_FUNCTION(define) RETURN_FALSE; } + ZVAL_UNDEF(&val_free); + repeat: switch (Z_TYPE_P(val)) { case IS_LONG: @@ -682,14 +684,14 @@ repeat: case IS_NULL: break; case IS_OBJECT: - if (!val_free) { + if (Z_TYPE(val_free) == IS_UNDEF) { if (Z_OBJ_HT_P(val)->get) { - val_free = val = Z_OBJ_HT_P(val)->get(val TSRMLS_CC); + val = Z_OBJ_HT_P(val)->get(val TSRMLS_CC); + ZVAL_COPY_VALUE(&val_free, val); goto repeat; } else if (Z_OBJ_HT_P(val)->cast_object) { - ALLOC_INIT_ZVAL(val_free); - if (Z_OBJ_HT_P(val)->cast_object(val, val_free, IS_STRING TSRMLS_CC) == SUCCESS) { - val = val_free; + if (Z_OBJ_HT_P(val)->cast_object(val, &val_free, IS_STRING TSRMLS_CC) == SUCCESS) { + val = &val_free; break; } } @@ -697,23 +699,17 @@ repeat: /* no break */ default: zend_error(E_WARNING,"Constants may only evaluate to scalar values"); - if (val_free) { - zval_ptr_dtor(&val_free); - } + zval_ptr_dtor(&val_free); RETURN_FALSE; } - c.value = *val; - zval_copy_ctor(&c.value); - if (val_free) { - zval_ptr_dtor(&val_free); - } + ZVAL_DUP(&c.value, val); + zval_ptr_dtor(&val_free); c.flags = case_sensitive; /* non persistent */ - c.name = str_strndup(name, name_len); + c.name = STR_INIT(name, name_len, 1); if(c.name == NULL) { RETURN_FALSE; } - c.name_len = name_len+1; c.module_number = PHP_USER_CONSTANT; if (zend_register_constant(&c TSRMLS_CC) == SUCCESS) { RETURN_TRUE; @@ -751,9 +747,6 @@ ZEND_FUNCTION(defined) ZEND_FUNCTION(get_class) { zval *obj = NULL; - const char *name = ""; - zend_uint name_len = 0; - int dup; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|o!", &obj) == FAILURE) { RETURN_FALSE; @@ -761,16 +754,14 @@ ZEND_FUNCTION(get_class) if (!obj) { if (EG(scope)) { - RETURN_STRINGL(EG(scope)->name, EG(scope)->name_length, 1); + RETURN_STR(STR_COPY(EG(scope)->name)); } else { zend_error(E_WARNING, "get_class() called without object from outside a class"); RETURN_FALSE; } } - dup = zend_get_object_classname(obj, &name, &name_len TSRMLS_CC); - - RETURN_STRINGL(name, name_len, dup); + RETURN_STR(zend_get_object_classname(obj TSRMLS_CC)); } /* }}} */ @@ -784,7 +775,7 @@ ZEND_FUNCTION(get_called_class) } if (EG(called_scope)) { - RETURN_STRINGL(EG(called_scope)->name, EG(called_scope)->name_length, 1); + RETURN_STR(STR_COPY(EG(called_scope)->name)); } else if (!EG(scope)) { zend_error(E_WARNING, "get_called_class() called from outside a class"); } @@ -799,8 +790,7 @@ ZEND_FUNCTION(get_parent_class) { zval *arg; zend_class_entry *ce = NULL; - const char *name; - zend_uint name_length; + zend_string *name; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &arg) == FAILURE) { return; @@ -809,7 +799,7 @@ ZEND_FUNCTION(get_parent_class) if (!ZEND_NUM_ARGS()) { ce = EG(scope); if (ce && ce->parent) { - RETURN_STRINGL(ce->parent->name, ce->parent->name_length, 1); + RETURN_STR(STR_COPY(ce->parent->name)); } else { RETURN_FALSE; } @@ -817,21 +807,17 @@ ZEND_FUNCTION(get_parent_class) if (Z_TYPE_P(arg) == IS_OBJECT) { if (Z_OBJ_HT_P(arg)->get_class_name - && Z_OBJ_HT_P(arg)->get_class_name(arg, &name, &name_length, 1 TSRMLS_CC) == SUCCESS) { - RETURN_STRINGL(name, name_length, 0); + && (name = Z_OBJ_HT_P(arg)->get_class_name(arg, 1 TSRMLS_CC)) != NULL) { + RETURN_STR(name); } else { ce = zend_get_class_entry(arg TSRMLS_CC); } } else if (Z_TYPE_P(arg) == IS_STRING) { - zend_class_entry **pce; - - if (zend_lookup_class(Z_STRVAL_P(arg), Z_STRLEN_P(arg), &pce TSRMLS_CC) == SUCCESS) { - ce = *pce; - } + ce = zend_lookup_class(Z_STR_P(arg) TSRMLS_CC); } if (ce && ce->parent) { - RETURN_STRINGL(ce->parent->name, ce->parent->name_length, 1); + RETURN_STR(STR_COPY(ce->parent->name)); } else { RETURN_FALSE; } @@ -842,14 +828,13 @@ ZEND_FUNCTION(get_parent_class) static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) { zval *obj; - char *class_name; - int class_name_len; + zend_string *class_name; zend_class_entry *instance_ce; - zend_class_entry **ce; + zend_class_entry *ce; zend_bool allow_string = only_subclass; zend_bool retval; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs|b", &obj, &class_name, &class_name_len, &allow_string) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zS|b", &obj, &class_name, &allow_string) == FAILURE) { return; } /* @@ -860,24 +845,24 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) */ if (allow_string && Z_TYPE_P(obj) == IS_STRING) { - zend_class_entry **the_ce; - if (zend_lookup_class(Z_STRVAL_P(obj), Z_STRLEN_P(obj), &the_ce TSRMLS_CC) == FAILURE) { + instance_ce = zend_lookup_class(Z_STR_P(obj) TSRMLS_CC); + if (!instance_ce) { RETURN_FALSE; } - instance_ce = *the_ce; } else if (Z_TYPE_P(obj) == IS_OBJECT && HAS_CLASS_ENTRY(*obj)) { instance_ce = Z_OBJCE_P(obj); } else { RETURN_FALSE; } - if (zend_lookup_class_ex(class_name, class_name_len, NULL, 0, &ce TSRMLS_CC) == FAILURE) { + ce = zend_lookup_class_ex(class_name, NULL, 0 TSRMLS_CC); + if (!ce) { retval = 0; } else { - if (only_subclass && instance_ce == *ce) { + if (only_subclass && instance_ce == ce) { retval = 0; } else { - retval = instanceof_function(instance_ce, *ce TSRMLS_CC); + retval = instanceof_function(instance_ce, ce TSRMLS_CC); } } @@ -908,14 +893,13 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value { HashPosition pos; zend_property_info *prop_info; - zval *prop, *prop_copy; - char *key; - uint key_len; + zval *prop, prop_copy; + zend_string *key; ulong num_index; zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop_info, &pos) == SUCCESS) { - zend_hash_get_current_key_ex(&ce->properties_info, &key, &key_len, &num_index, 0, &pos); + while ((prop_info = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) { + zend_hash_get_current_key_ex(&ce->properties_info, &key, &num_index, 0, &pos); zend_hash_move_forward_ex(&ce->properties_info, &pos); if (((prop_info->flags & ZEND_ACC_SHADOW) && prop_info->ce != EG(scope)) || @@ -929,28 +913,26 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value prop = NULL; if (prop_info->offset >= 0) { if (statics && (prop_info->flags & ZEND_ACC_STATIC) != 0) { - prop = ce->default_static_members_table[prop_info->offset]; + prop = &ce->default_static_members_table[prop_info->offset]; } else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) { - prop = ce->default_properties_table[prop_info->offset]; + prop = &ce->default_properties_table[prop_info->offset]; } } - if (!prop) { + if (!prop || Z_TYPE_P(prop) == IS_UNDEF) { continue; } /* copy: enforce read only access */ - ALLOC_ZVAL(prop_copy); - *prop_copy = *prop; - zval_copy_ctor(prop_copy); - INIT_PZVAL(prop_copy); + ZVAL_DUP(&prop_copy, prop); +//??? INIT_PZVAL(prop_copy); /* this is necessary to make it able to work with default array * properties, returned to user */ - if (IS_CONSTANT_TYPE(Z_TYPE_P(prop_copy))) { + if (IS_CONSTANT_TYPE(Z_TYPE(prop_copy))) { zval_update_constant(&prop_copy, 0 TSRMLS_CC); } - zend_hash_update(Z_ARRVAL_P(return_value), key, key_len, &prop_copy, sizeof(zval*), NULL); + zend_hash_update(Z_ARRVAL_P(return_value), key, &prop_copy); } } /* }}} */ @@ -960,21 +942,21 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value Returns an array of default properties of the class. */ ZEND_FUNCTION(get_class_vars) { - char *class_name; - int class_name_len; - zend_class_entry **pce; + zend_string *class_name; + zend_class_entry *ce; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &class_name, &class_name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &class_name) == FAILURE) { return; } - if (zend_lookup_class(class_name, class_name_len, &pce TSRMLS_CC) == FAILURE) { + ce = zend_lookup_class(class_name TSRMLS_CC); + if (!ce) { RETURN_FALSE; } else { array_init(return_value); - zend_update_class_constants(*pce TSRMLS_CC); - add_class_vars(*pce, 0, return_value TSRMLS_CC); - add_class_vars(*pce, 1, return_value TSRMLS_CC); + zend_update_class_constants(ce TSRMLS_CC); + add_class_vars(ce, 0, return_value TSRMLS_CC); + add_class_vars(ce, 1, return_value TSRMLS_CC); } } /* }}} */ @@ -985,12 +967,12 @@ ZEND_FUNCTION(get_class_vars) ZEND_FUNCTION(get_object_vars) { zval *obj; - zval **value; + zval *value; HashTable *properties; HashPosition pos; - char *key; + zend_string *key; const char *prop_name, *class_name; - uint key_len, prop_len; + uint prop_len; ulong num_index; zend_object *zobj; @@ -1008,26 +990,19 @@ ZEND_FUNCTION(get_object_vars) RETURN_FALSE; } - zobj = zend_objects_get_address(obj TSRMLS_CC); + zobj = Z_OBJ_P(obj); array_init(return_value); zend_hash_internal_pointer_reset_ex(properties, &pos); - while (zend_hash_get_current_data_ex(properties, (void **) &value, &pos) == SUCCESS) { - if (zend_hash_get_current_key_ex(properties, &key, &key_len, &num_index, 0, &pos) == HASH_KEY_IS_STRING) { - if (zend_check_property_access(zobj, key, key_len-1 TSRMLS_CC) == SUCCESS) { - zend_unmangle_property_name_ex(key, key_len - 1, &class_name, &prop_name, (int*) &prop_len); + while ((value = zend_hash_get_current_data_ex(properties, &pos)) != NULL) { + if (zend_hash_get_current_key_ex(properties, &key, &num_index, 0, &pos) == HASH_KEY_IS_STRING) { + if (zend_check_property_access(zobj, key TSRMLS_CC) == SUCCESS) { + zend_unmangle_property_name_ex(key->val, key->len, &class_name, &prop_name, (int*) &prop_len); /* Not separating references */ - Z_ADDREF_PP(value); - if (IS_INTERNED(key) && prop_name != key) { - /* we can't use substring of interned string as a new key */ - char *tmp = estrndup(prop_name, prop_len); - add_assoc_zval_ex(return_value, tmp, prop_len + 1, *value); - efree(tmp); - } else { - add_assoc_zval_ex(return_value, prop_name, prop_len + 1, *value); - } + Z_ADDREF_P(value); + add_assoc_zval_ex(return_value, prop_name, prop_len, value); } } zend_hash_move_forward_ex(properties, &pos); @@ -1048,8 +1023,8 @@ static int same_name(const char *key, const char *name, zend_uint name_len) ZEND_FUNCTION(get_class_methods) { zval *klass; - zval *method_name; - zend_class_entry *ce = NULL, **pce; + zval method_name; + zend_class_entry *ce = NULL; HashPosition pos; zend_function *mptr; @@ -1064,9 +1039,7 @@ ZEND_FUNCTION(get_class_methods) } ce = Z_OBJCE_P(klass); } else if (Z_TYPE_P(klass) == IS_STRING) { - if (zend_lookup_class(Z_STRVAL_P(klass), Z_STRLEN_P(klass), &pce TSRMLS_CC) == SUCCESS) { - ce = *pce; - } + ce = zend_lookup_class(Z_STR_P(klass) TSRMLS_CC); } if (!ce) { @@ -1076,38 +1049,34 @@ ZEND_FUNCTION(get_class_methods) array_init(return_value); zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos); - while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) { + while ((mptr = zend_hash_get_current_data_ptr_ex(&ce->function_table, &pos)) != NULL) { if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC) || (EG(scope) && (((mptr->common.fn_flags & ZEND_ACC_PROTECTED) && zend_check_protected(mptr->common.scope, EG(scope))) || ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) && EG(scope) == mptr->common.scope)))) { - char *key; - uint key_len; + zend_string *key; ulong num_index; - uint len = strlen(mptr->common.function_name); + uint len = mptr->common.function_name->len; /* Do not display old-style inherited constructors */ - if (zend_hash_get_current_key_ex(&ce->function_table, &key, &key_len, &num_index, 0, &pos) != HASH_KEY_IS_STRING) { - MAKE_STD_ZVAL(method_name); - ZVAL_STRINGL(method_name, mptr->common.function_name, len, 1); - zend_hash_next_index_insert(return_value->value.ht, &method_name, sizeof(zval *), NULL); + if (zend_hash_get_current_key_ex(&ce->function_table, &key, &num_index, 0, &pos) != HASH_KEY_IS_STRING) { + ZVAL_STR(&method_name, STR_COPY(mptr->common.function_name)); + zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &method_name); } else if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 || mptr->common.scope == ce || - zend_binary_strcasecmp(key, key_len-1, mptr->common.function_name, len) == 0) { + zend_binary_strcasecmp(key->val, key->len, mptr->common.function_name->val, len) == 0) { if (mptr->type == ZEND_USER_FUNCTION && *mptr->op_array.refcount > 1 && - (len != key_len - 1 || - !same_name(key, mptr->common.function_name, len))) { - MAKE_STD_ZVAL(method_name); - ZVAL_STRINGL(method_name, zend_find_alias_name(mptr->common.scope, key, key_len - 1), key_len - 1, 1); - zend_hash_next_index_insert(return_value->value.ht, &method_name, sizeof(zval *), NULL); + (len != key->len || + !same_name(key->val, mptr->common.function_name->val, len))) { + ZVAL_STR(&method_name, STR_COPY(zend_find_alias_name(mptr->common.scope, key))); + zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &method_name); } else { - MAKE_STD_ZVAL(method_name); - ZVAL_STRINGL(method_name, mptr->common.function_name, len, 1); - zend_hash_next_index_insert(return_value->value.ht, &method_name, sizeof(zval *), NULL); + ZVAL_STR(&method_name, STR_COPY(mptr->common.function_name)); + zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &method_name); } } } @@ -1122,46 +1091,43 @@ ZEND_FUNCTION(get_class_methods) ZEND_FUNCTION(method_exists) { zval *klass; - char *method_name; - int method_len; - char *lcname; - zend_class_entry * ce, **pce; + zend_string *method_name; + zend_string *lcname; + zend_class_entry * ce; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &klass, &method_name, &method_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zS", &klass, &method_name) == FAILURE) { return; } if (Z_TYPE_P(klass) == IS_OBJECT) { ce = Z_OBJCE_P(klass); } else if (Z_TYPE_P(klass) == IS_STRING) { - if (zend_lookup_class(Z_STRVAL_P(klass), Z_STRLEN_P(klass), &pce TSRMLS_CC) == FAILURE) { - RETURN_FALSE; - } - ce = *pce; + ce = zend_lookup_class(Z_STR_P(klass) TSRMLS_CC); } else { RETURN_FALSE; } - lcname = zend_str_tolower_dup(method_name, method_len); - if (zend_hash_exists(&ce->function_table, lcname, method_len+1)) { - efree(lcname); + lcname = STR_ALLOC(method_name->len, 0); + zend_str_tolower_copy(lcname->val, method_name->val, method_name->len); + if (zend_hash_exists(&ce->function_table, lcname)) { + STR_FREE(lcname); RETURN_TRUE; } else { union _zend_function *func = NULL; if (Z_TYPE_P(klass) == IS_OBJECT && Z_OBJ_HT_P(klass)->get_method != NULL - && (func = Z_OBJ_HT_P(klass)->get_method(&klass, method_name, method_len, NULL TSRMLS_CC)) != NULL + && (func = Z_OBJ_HT_P(klass)->get_method(klass, method_name, NULL TSRMLS_CC)) != NULL ) { if (func->type == ZEND_INTERNAL_FUNCTION && (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_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) - && memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0) ? 1 : 0); + && (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); - efree(lcname); - efree((char*)((zend_internal_function*)func)->function_name); + STR_FREE(lcname); + STR_FREE(func->common.function_name); efree(func); return; } @@ -1179,26 +1145,21 @@ ZEND_FUNCTION(method_exists) ZEND_FUNCTION(property_exists) { zval *object; - char *property; - int property_len; - zend_class_entry *ce, **pce; + zend_string *property; + zend_class_entry *ce; zend_property_info *property_info; zval property_z; - ulong h; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &object, &property, &property_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zS", &object, &property) == FAILURE) { return; } - if (property_len == 0) { + if (property == NULL) { RETURN_FALSE; } if (Z_TYPE_P(object) == IS_STRING) { - if (zend_lookup_class(Z_STRVAL_P(object), Z_STRLEN_P(object), &pce TSRMLS_CC) == FAILURE) { - RETURN_FALSE; - } - ce = *pce; + ce = zend_lookup_class(Z_STR_P(object) TSRMLS_CC); } else if (Z_TYPE_P(object) == IS_OBJECT) { ce = Z_OBJCE_P(object); } else { @@ -1206,13 +1167,12 @@ ZEND_FUNCTION(property_exists) RETURN_NULL(); } - h = zend_get_hash_value(property, property_len+1); - if (zend_hash_quick_find(&ce->properties_info, property, property_len+1, h, (void **) &property_info) == SUCCESS + if ((property_info = zend_hash_find_ptr(&ce->properties_info, property)) != NULL && (property_info->flags & ZEND_ACC_SHADOW) == 0) { RETURN_TRUE; } - ZVAL_STRINGL(&property_z, property, property_len, 0); + ZVAL_STR(&property_z, property); if (Z_TYPE_P(object) == IS_OBJECT && Z_OBJ_HANDLER_P(object, has_property) && @@ -1228,39 +1188,32 @@ ZEND_FUNCTION(property_exists) Checks if the class exists */ ZEND_FUNCTION(class_exists) { - char *class_name, *lc_name; - zend_class_entry **ce; - int class_name_len; - int found; + zend_string *class_name; + zend_string *lc_name; + zend_class_entry *ce; zend_bool autoload = 1; - ALLOCA_FLAG(use_heap) - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &class_name, &class_name_len, &autoload) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|b", &class_name, &autoload) == FAILURE) { return; } if (!autoload) { - char *name; - int len; - - lc_name = do_alloca(class_name_len + 1, use_heap); - zend_str_tolower_copy(lc_name, class_name, class_name_len); - - /* Ignore leading "\" */ - name = lc_name; - len = class_name_len; - if (lc_name[0] == '\\') { - name = &lc_name[1]; - len--; + if (class_name->val[0] == '\\') { + /* Ignore leading "\" */ + lc_name = STR_ALLOC(class_name->len - 1, 0); + zend_str_tolower_copy(lc_name->val, class_name->val + 1, class_name->len - 1); + } else { + lc_name = STR_ALLOC(class_name->len, 0); + zend_str_tolower_copy(lc_name->val, class_name->val, class_name->len); } - - found = zend_hash_find(EG(class_table), name, len+1, (void **) &ce); - free_alloca(lc_name, use_heap); - RETURN_BOOL(found == SUCCESS && !(((*ce)->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT)) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)); + ce = zend_hash_find_ptr(EG(class_table), lc_name); + STR_FREE(lc_name); + RETURN_BOOL(ce && !((ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT)) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)); } - if (zend_lookup_class(class_name, class_name_len, &ce TSRMLS_CC) == SUCCESS) { - RETURN_BOOL(((*ce)->ce_flags & (ZEND_ACC_INTERFACE | (ZEND_ACC_TRAIT - ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) == 0); + ce = zend_lookup_class(class_name TSRMLS_CC); + if (ce) { + RETURN_BOOL((ce->ce_flags & (ZEND_ACC_INTERFACE | (ZEND_ACC_TRAIT - ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) == 0); } else { RETURN_FALSE; } @@ -1271,39 +1224,31 @@ ZEND_FUNCTION(class_exists) Checks if the class exists */ ZEND_FUNCTION(interface_exists) { - char *iface_name, *lc_name; - zend_class_entry **ce; - int iface_name_len; - int found; + zend_string *iface_name, *lc_name; + zend_class_entry *ce; zend_bool autoload = 1; - ALLOCA_FLAG(use_heap) - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &iface_name, &iface_name_len, &autoload) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|b", &iface_name, &autoload) == FAILURE) { return; } if (!autoload) { - char *name; - int len; - - lc_name = do_alloca(iface_name_len + 1, use_heap); - zend_str_tolower_copy(lc_name, iface_name, iface_name_len); - - /* Ignore leading "\" */ - name = lc_name; - len = iface_name_len; - if (lc_name[0] == '\\') { - name = &lc_name[1]; - len--; + if (iface_name->val[0] == '\\') { + /* Ignore leading "\" */ + lc_name = STR_ALLOC(iface_name->len - 1, 0); + zend_str_tolower_copy(lc_name->val, iface_name->val + 1, iface_name->len - 1); + } else { + lc_name = STR_ALLOC(iface_name->len, 0); + zend_str_tolower_copy(lc_name->val, iface_name->val, iface_name->len); } - - found = zend_hash_find(EG(class_table), name, len+1, (void **) &ce); - free_alloca(lc_name, use_heap); - RETURN_BOOL(found == SUCCESS && (*ce)->ce_flags & ZEND_ACC_INTERFACE); + ce = zend_hash_find_ptr(EG(class_table), lc_name); + STR_FREE(lc_name); + RETURN_BOOL(ce && ce->ce_flags & ZEND_ACC_INTERFACE); } - if (zend_lookup_class(iface_name, iface_name_len, &ce TSRMLS_CC) == SUCCESS) { - RETURN_BOOL(((*ce)->ce_flags & ZEND_ACC_INTERFACE) > 0); + ce = zend_lookup_class(iface_name TSRMLS_CC); + if (ce) { + RETURN_BOOL((ce->ce_flags & ZEND_ACC_INTERFACE) > 0); } else { RETURN_FALSE; } @@ -1314,39 +1259,31 @@ ZEND_FUNCTION(interface_exists) Checks if the trait exists */ ZEND_FUNCTION(trait_exists) { - char *trait_name, *lc_name; - zend_class_entry **ce; - int trait_name_len; - int found; + zend_string *trait_name, *lc_name; + zend_class_entry *ce; zend_bool autoload = 1; - ALLOCA_FLAG(use_heap) - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &trait_name, &trait_name_len, &autoload) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|b", &trait_name, &autoload) == FAILURE) { return; } if (!autoload) { - char *name; - int len; - - lc_name = do_alloca(trait_name_len + 1, use_heap); - zend_str_tolower_copy(lc_name, trait_name, trait_name_len); - - /* Ignore leading "\" */ - name = lc_name; - len = trait_name_len; - if (lc_name[0] == '\\') { - name = &lc_name[1]; - len--; + if (trait_name->val[0] == '\\') { + /* Ignore leading "\" */ + lc_name = STR_ALLOC(trait_name->len - 1, 0); + zend_str_tolower_copy(lc_name->val, trait_name->val + 1, trait_name->len - 1); + } else { + lc_name = STR_ALLOC(trait_name->len, 0); + zend_str_tolower_copy(lc_name->val, trait_name->val, trait_name->len); } - - found = zend_hash_find(EG(class_table), name, len+1, (void **) &ce); - free_alloca(lc_name, use_heap); - RETURN_BOOL(found == SUCCESS && (((*ce)->ce_flags & ZEND_ACC_TRAIT) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)); + ce = zend_hash_find_ptr(EG(class_table), lc_name); + STR_FREE(lc_name); + RETURN_BOOL(ce && ((ce->ce_flags & ZEND_ACC_TRAIT) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)); } - if (zend_lookup_class(trait_name, trait_name_len, &ce TSRMLS_CC) == SUCCESS) { - RETURN_BOOL(((*ce)->ce_flags & ZEND_ACC_TRAIT) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + ce = zend_lookup_class(trait_name TSRMLS_CC); + if (ce) { + RETURN_BOOL((ce->ce_flags & ZEND_ACC_TRAIT) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); } else { RETURN_FALSE; } @@ -1361,36 +1298,30 @@ ZEND_FUNCTION(function_exists) char *name; int name_len; zend_function *func; - char *lcname; - zend_bool retval; + zend_string *lcname; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; } - lcname = zend_str_tolower_dup(name, name_len); - - /* Ignore leading "\" */ - name = lcname; - if (lcname[0] == '\\') { - name = &lcname[1]; - name_len--; + if (name[0] == '\\') { + /* Ignore leading "\" */ + lcname = STR_ALLOC(name_len - 1, 0); + zend_str_tolower_copy(lcname->val, name + 1, name_len - 1); + } else { + lcname = STR_ALLOC(name_len, 0); + zend_str_tolower_copy(lcname->val, name, name_len); } - - retval = (zend_hash_find(EG(function_table), name, name_len+1, (void **)&func) == SUCCESS); - efree(lcname); + func = zend_hash_find_ptr(EG(function_table), lcname); + STR_FREE(lcname); /* * A bit of a hack, but not a bad one: we see if the handler of the function * is actually one that displays "function is disabled" message. */ - if (retval && func->type == ZEND_INTERNAL_FUNCTION && - func->internal_function.handler == zif_display_disabled_function) { - retval = 0; - } - - RETURN_BOOL(retval); + RETURN_BOOL(func && (func->type != ZEND_INTERNAL_FUNCTION || + func->internal_function.handler != zif_display_disabled_function)); } /* }}} */ @@ -1398,21 +1329,21 @@ ZEND_FUNCTION(function_exists) Creates an alias for user defined class */ ZEND_FUNCTION(class_alias) { - char *class_name, *alias_name; - zend_class_entry **ce; - int class_name_len, alias_name_len; - int found; + zend_string *class_name; + char *alias_name; + zend_class_entry *ce; + int alias_name_len; zend_bool autoload = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &class_name, &class_name_len, &alias_name, &alias_name_len, &autoload) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ss|b", &class_name, &alias_name, &alias_name_len, &autoload) == FAILURE) { return; } - found = zend_lookup_class_ex(class_name, class_name_len, NULL, autoload, &ce TSRMLS_CC); + ce = zend_lookup_class_ex(class_name, NULL, autoload TSRMLS_CC); - if (found == SUCCESS) { - if ((*ce)->type == ZEND_USER_CLASS) { - if (zend_register_class_alias_ex(alias_name, alias_name_len, *ce TSRMLS_CC) == SUCCESS) { + if (ce) { + if (ce->type == ZEND_USER_CLASS) { + if (zend_register_class_alias_ex(alias_name, alias_name_len, ce TSRMLS_CC) == SUCCESS) { RETURN_TRUE; } else { zend_error(E_WARNING, "Cannot redeclare class %s", alias_name); @@ -1423,7 +1354,7 @@ ZEND_FUNCTION(class_alias) RETURN_FALSE; } } else { - zend_error(E_WARNING, "Class '%s' not found", class_name); + zend_error(E_WARNING, "Class '%s' not found", class_name->val); RETURN_FALSE; } } @@ -1455,11 +1386,11 @@ ZEND_FUNCTION(leak_variable) } if (!leak_data) { - zval_add_ref(&zv); + Z_ADDREF_P(zv); } else if (Z_TYPE_P(zv) == IS_RESOURCE) { - zend_list_addref(Z_RESVAL_P(zv)); + Z_ADDREF_P(zv); } else if (Z_TYPE_P(zv) == IS_OBJECT) { - Z_OBJ_HANDLER_P(zv, add_ref)(zv TSRMLS_CC); + Z_ADDREF_P(zv); } else { zend_error(E_WARNING, "Leaking non-zval data is only applicable to resources and objects"); } @@ -1482,8 +1413,7 @@ ZEND_FUNCTION(crash) Returns an array with the file names that were include_once()'d */ ZEND_FUNCTION(get_included_files) { - char *entry; - uint entry_len; + zend_string *entry; if (zend_parse_parameters_none() == FAILURE) { return; @@ -1491,8 +1421,8 @@ ZEND_FUNCTION(get_included_files) array_init(return_value); zend_hash_internal_pointer_reset(&EG(included_files)); - while (zend_hash_get_current_key_ex(&EG(included_files), &entry, &entry_len, NULL, 0, NULL) == HASH_KEY_IS_STRING) { - add_next_index_stringl(return_value, entry, entry_len-1, !IS_INTERNED(entry)); + while (zend_hash_get_current_key_ex(&EG(included_files), &entry, NULL, 0, NULL) == HASH_KEY_IS_STRING) { + add_next_index_str(return_value, entry); zend_hash_move_forward(&EG(included_files)); } } @@ -1551,20 +1481,19 @@ ZEND_FUNCTION(set_error_handler) efree(error_handler_name); } - if (EG(user_error_handler)) { - RETVAL_ZVAL(EG(user_error_handler), 1, 0); + if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) { + RETVAL_ZVAL(&EG(user_error_handler), 1, 0); zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting), sizeof(EG(user_error_handler_error_reporting))); - zend_ptr_stack_push(&EG(user_error_handlers), EG(user_error_handler)); + zend_stack_push(&EG(user_error_handlers), &EG(user_error_handler), sizeof(zval)); } if (Z_TYPE_P(error_handler) == IS_NULL) { /* unset user-defined handler */ - EG(user_error_handler) = NULL; + ZVAL_UNDEF(&EG(user_error_handler)); return; } - ALLOC_ZVAL(EG(user_error_handler)); - MAKE_COPY_ZVAL(&error_handler, EG(user_error_handler)); + ZVAL_DUP(&EG(user_error_handler), error_handler); EG(user_error_handler_error_reporting) = (int)error_type; } /* }}} */ @@ -1574,19 +1503,23 @@ ZEND_FUNCTION(set_error_handler) Restores the previously defined error handler function */ ZEND_FUNCTION(restore_error_handler) { - if (EG(user_error_handler)) { - zval *zeh = EG(user_error_handler); - - EG(user_error_handler) = NULL; + if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) { + zval zeh; + + ZVAL_COPY_VALUE(&zeh, &EG(user_error_handler)); + ZVAL_UNDEF(&EG(user_error_handler)); zval_ptr_dtor(&zeh); } - if (zend_ptr_stack_num_elements(&EG(user_error_handlers))==0) { - EG(user_error_handler) = NULL; + if (zend_stack_is_empty(&EG(user_error_handlers))) { + ZVAL_UNDEF(&EG(user_error_handler)); } else { + zval *tmp; EG(user_error_handler_error_reporting) = zend_stack_int_top(&EG(user_error_handlers_error_reporting)); zend_stack_del_top(&EG(user_error_handlers_error_reporting)); - EG(user_error_handler) = zend_ptr_stack_pop(&EG(user_error_handlers)); + zend_stack_top(&EG(user_error_handlers), (void**)&tmp); + ZVAL_COPY_VALUE(&EG(user_error_handler), tmp); + zend_stack_del_top(&EG(user_error_handlers)); } RETURN_TRUE; } @@ -1614,19 +1547,18 @@ ZEND_FUNCTION(set_exception_handler) efree(exception_handler_name); } - if (EG(user_exception_handler)) { - RETVAL_ZVAL(EG(user_exception_handler), 1, 0); + if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { + RETVAL_ZVAL(&EG(user_exception_handler), 1, 0); - zend_ptr_stack_push(&EG(user_exception_handlers), EG(user_exception_handler)); + zend_stack_push(&EG(user_exception_handlers), &EG(user_exception_handler), sizeof(zval)); } if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined handler */ - EG(user_exception_handler) = NULL; + ZVAL_UNDEF(&EG(user_exception_handler)); return; } - ALLOC_ZVAL(EG(user_exception_handler)); - MAKE_COPY_ZVAL(&exception_handler, EG(user_exception_handler)) + ZVAL_DUP(&EG(user_exception_handler), exception_handler); } /* }}} */ @@ -1635,13 +1567,17 @@ ZEND_FUNCTION(set_exception_handler) Restores the previously defined exception handler function */ ZEND_FUNCTION(restore_exception_handler) { - if (EG(user_exception_handler)) { + if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { zval_ptr_dtor(&EG(user_exception_handler)); } - if (zend_ptr_stack_num_elements(&EG(user_exception_handlers))==0) { - EG(user_exception_handler) = NULL; + if (zend_stack_is_empty(&EG(user_exception_handlers))) { + ZVAL_UNDEF(&EG(user_exception_handler)); } else { - EG(user_exception_handler) = zend_ptr_stack_pop(&EG(user_exception_handlers)); + zval *tmp; + + zend_stack_top(&EG(user_exception_handlers), (void**)&tmp); + ZVAL_COPY_VALUE(&EG(user_exception_handler), tmp); + zend_stack_del_top(&EG(user_exception_handlers)); } RETURN_TRUE; } @@ -1655,14 +1591,14 @@ static int copy_class_or_interface_name(zend_class_entry **pce TSRMLS_DC, int nu zend_uint comply_mask = (comply)? mask:0; zend_class_entry *ce = *pce; - if ((hash_key->nKeyLength==0 || hash_key->arKey[0]!=0) + if ((hash_key->key && hash_key->key->val[0] != 0) && (comply_mask == (ce->ce_flags & mask))) { if (ce->refcount > 1 && - (ce->name_length != hash_key->nKeyLength - 1 || - !same_name(hash_key->arKey, ce->name, ce->name_length))) { - add_next_index_stringl(array, hash_key->arKey, hash_key->nKeyLength - 1, 1); + (ce->name->len != hash_key->key->len - 1 || + !same_name(hash_key->key->val, ce->name->val, ce->name->len))) { + add_next_index_str(array, hash_key->key); } else { - add_next_index_stringl(array, ce->name, ce->name_length, 1); + add_next_index_str(array, ce->name); } } return ZEND_HASH_APPLY_KEEP; @@ -1723,14 +1659,14 @@ static int copy_function_name(zend_function *func TSRMLS_DC, int num_args, va_li zval *internal_ar = va_arg(args, zval *), *user_ar = va_arg(args, zval *); - if (hash_key->nKeyLength == 0 || hash_key->arKey[0] == 0) { + if (hash_key->key == NULL || hash_key->key->val[0] == 0) { return 0; } if (func->type == ZEND_INTERNAL_FUNCTION) { - add_next_index_stringl(internal_ar, hash_key->arKey, hash_key->nKeyLength-1, 1); + add_next_index_str(internal_ar, hash_key->key); } else if (func->type == ZEND_USER_FUNCTION) { - add_next_index_stringl(user_ar, hash_key->arKey, hash_key->nKeyLength-1, 1); + add_next_index_str(user_ar, hash_key->key); } return 0; @@ -1741,23 +1677,21 @@ static int copy_function_name(zend_function *func TSRMLS_DC, int num_args, va_li Returns an array of all defined functions */ ZEND_FUNCTION(get_defined_functions) { - zval *internal; - zval *user; + zval internal, user, *ret; if (zend_parse_parameters_none() == FAILURE) { return; } - MAKE_STD_ZVAL(internal); - MAKE_STD_ZVAL(user); - - array_init(internal); - array_init(user); + array_init(&internal); + array_init(&user); array_init(return_value); - zend_hash_apply_with_arguments(EG(function_table) TSRMLS_CC, (apply_func_args_t) copy_function_name, 2, internal, user); + zend_hash_apply_with_arguments(EG(function_table) TSRMLS_CC, (apply_func_args_t) copy_function_name, 2, &internal, &user); - if (zend_hash_add(Z_ARRVAL_P(return_value), "internal", sizeof("internal"), (void **)&internal, sizeof(zval *), NULL) == FAILURE) { + ret = zend_hash_str_add(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal); + + if (!ret) { zval_ptr_dtor(&internal); zval_ptr_dtor(&user); zval_dtor(return_value); @@ -1765,7 +1699,8 @@ ZEND_FUNCTION(get_defined_functions) RETURN_FALSE; } - if (zend_hash_add(Z_ARRVAL_P(return_value), "user", sizeof("user"), (void **)&user, sizeof(zval *), NULL) == FAILURE) { + ret = zend_hash_str_add(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user); + if (!ret) { zval_ptr_dtor(&user); zval_dtor(return_value); zend_error(E_WARNING, "Cannot add user functions to return value from get_defined_functions()"); @@ -1785,8 +1720,7 @@ ZEND_FUNCTION(get_defined_vars) array_init_size(return_value, zend_hash_num_elements(EG(active_symbol_table))); - zend_hash_copy(Z_ARRVAL_P(return_value), EG(active_symbol_table), - (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval *)); + zend_hash_copy(Z_ARRVAL_P(return_value), EG(active_symbol_table), zval_add_ref); } /* }}} */ @@ -1796,8 +1730,9 @@ ZEND_FUNCTION(get_defined_vars) Creates an anonymous function, and returns its name (funny, eh?) */ ZEND_FUNCTION(create_function) { - char *eval_code, *function_name, *function_args, *function_code; - int eval_code_length, function_name_length, function_args_len, function_code_len; + zend_string *function_name; + char *eval_code, *function_args, *function_code; + int eval_code_length, function_args_len, function_code_len; int retval; char *eval_name; @@ -1834,23 +1769,24 @@ ZEND_FUNCTION(create_function) if (retval==SUCCESS) { zend_function new_function, *func; - if (zend_hash_find(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME), (void **) &func)==FAILURE) { + func = zend_hash_str_find_ptr(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1); + if (!func) { zend_error(E_ERROR, "Unexpected inconsistency in create_function()"); RETURN_FALSE; } new_function = *func; function_add_ref(&new_function); - function_name = (char *) emalloc(sizeof("0lambda_")+MAX_LENGTH_OF_LONG); - function_name[0] = '\0'; + function_name = STR_ALLOC(sizeof("0lambda_")+MAX_LENGTH_OF_LONG, 0); + function_name->val[0] = '\0'; do { - function_name_length = 1 + snprintf(function_name + 1, sizeof("lambda_")+MAX_LENGTH_OF_LONG, "lambda_%d", ++EG(lambda_count)); - } while (zend_hash_add(EG(function_table), function_name, function_name_length+1, &new_function, sizeof(zend_function), NULL)==FAILURE); - zend_hash_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)); - RETURN_STRINGL(function_name, function_name_length, 0); + function_name->len = snprintf(function_name->val + 1, sizeof("lambda_")+MAX_LENGTH_OF_LONG, "lambda_%d", ++EG(lambda_count)); + } while (zend_hash_add_mem(EG(function_table), function_name, &new_function, sizeof(zend_function)) == NULL); + zend_hash_str_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1); + RETURN_STR(function_name); } else { - zend_hash_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)); + zend_hash_str_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1); RETURN_FALSE; } } @@ -1862,7 +1798,7 @@ ZEND_FUNCTION(zend_test_func) { zval *arg1, *arg2; - zend_get_parameters(ht, 2, &arg1, &arg2); + zend_get_parameters(ZEND_NUM_ARGS(), 2, &arg1, &arg2); } @@ -1885,11 +1821,11 @@ ZEND_FUNCTION(get_resource_type) return; } - resource_type = zend_rsrc_list_get_rsrc_type(Z_LVAL_P(z_resource_type) TSRMLS_CC); + resource_type = zend_rsrc_list_get_rsrc_type(Z_RES_P(z_resource_type) TSRMLS_CC); if (resource_type) { - RETURN_STRING(resource_type, 1); + RETURN_STRING(resource_type); } else { - RETURN_STRING("Unknown", 1); + RETURN_STRING("Unknown"); } } /* }}} */ @@ -1912,18 +1848,15 @@ static int add_zendext_info(zend_extension *ext, void *arg TSRMLS_DC) static int add_constant_info(zend_constant *constant, void *arg TSRMLS_DC) { zval *name_array = (zval *)arg; - zval *const_val; + zval const_val; if (!constant->name) { /* skip special constants */ return 0; } - MAKE_STD_ZVAL(const_val); - *const_val = constant->value; - zval_copy_ctor(const_val); - INIT_PZVAL(const_val); - add_assoc_zval_ex(name_array, constant->name, constant->name_len, const_val); + ZVAL_DUP(&const_val, &constant->value); + add_assoc_zval_ex(name_array, constant->name->val, constant->name->len, &const_val); return 0; } @@ -1965,17 +1898,17 @@ ZEND_FUNCTION(get_defined_constants) HashPosition pos; zend_constant *val; int module_number; - zval **modules; + zval *modules; char **module_names; zend_module_entry *module; int i = 1; - modules = ecalloc(zend_hash_num_elements(&module_registry) + 2, sizeof(zval *)); + modules = ecalloc(zend_hash_num_elements(&module_registry) + 2, sizeof(zval)); module_names = emalloc((zend_hash_num_elements(&module_registry) + 2) * sizeof(char *)); module_names[0] = "internal"; zend_hash_internal_pointer_reset_ex(&module_registry, &pos); - while (zend_hash_get_current_data_ex(&module_registry, (void *) &module, &pos) != FAILURE) { + while ((module = zend_hash_get_current_data_ptr_ex(&module_registry, &pos)) != NULL) { module_names[module->module_number] = (char *)module->name; i++; zend_hash_move_forward_ex(&module_registry, &pos); @@ -1983,8 +1916,8 @@ ZEND_FUNCTION(get_defined_constants) module_names[i] = "user"; zend_hash_internal_pointer_reset_ex(EG(zend_constants), &pos); - while (zend_hash_get_current_data_ex(EG(zend_constants), (void **) &val, &pos) != FAILURE) { - zval *const_val; + while ((val = zend_hash_get_current_data_ptr_ex(EG(zend_constants), &pos)) != NULL) { + zval const_val; if (!val->name) { /* skip special constants */ @@ -2000,18 +1933,15 @@ ZEND_FUNCTION(get_defined_constants) module_number = val->module_number; } - if (!modules[module_number]) { - MAKE_STD_ZVAL(modules[module_number]); - array_init(modules[module_number]); - add_assoc_zval(return_value, module_names[module_number], modules[module_number]); + if (Z_TYPE(modules[module_number]) == IS_UNDEF) { + array_init(&modules[module_number]); + add_assoc_zval(return_value, module_names[module_number], &modules[module_number]); } - MAKE_STD_ZVAL(const_val); - *const_val = val->value; - zval_copy_ctor(const_val); - INIT_PZVAL(const_val); + ZVAL_DUP(&const_val, &val->value); +//??? INIT_PZVAL(const_val); - add_assoc_zval_ex(modules[module_number], val->name, val->name_len, const_val); + add_assoc_zval_ex(&modules[module_number], val->name->val, val->name->len, &const_val); next_constant: zend_hash_move_forward_ex(EG(zend_constants), &pos); } @@ -2024,45 +1954,42 @@ next_constant: /* }}} */ -static zval *debug_backtrace_get_args(void **curpos TSRMLS_DC) +static void debug_backtrace_get_args(zval *curpos, zval *arg_array TSRMLS_DC) { - void **p = curpos; - zval *arg_array, **arg; - int arg_count = (int)(zend_uintptr_t) *p; + zval *p = curpos; + zval *arg; + int arg_count = Z_LVAL_P(p); - MAKE_STD_ZVAL(arg_array); array_init_size(arg_array, arg_count); p -= arg_count; while (--arg_count >= 0) { - arg = (zval **) p++; - if (*arg) { - if (Z_TYPE_PP(arg) != IS_OBJECT) { + arg = p++; + if (arg) { + if (Z_TYPE_P(arg) != IS_OBJECT) { SEPARATE_ZVAL_TO_MAKE_IS_REF(arg); } - Z_ADDREF_PP(arg); - add_next_index_zval(arg_array, *arg); + Z_ADDREF_P(arg); + add_next_index_zval(arg_array, arg); } else { add_next_index_null(arg_array); } } - - return arg_array; } void debug_print_backtrace_args(zval *arg_array TSRMLS_DC) { - zval **tmp; + zval *tmp; HashPosition iterator; int i = 0; - zend_hash_internal_pointer_reset_ex(arg_array->value.ht, &iterator); - while (zend_hash_get_current_data_ex(arg_array->value.ht, (void **) &tmp, &iterator) == SUCCESS) { + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arg_array), &iterator); + while ((tmp = zend_hash_get_current_data_ex(Z_ARRVAL_P(arg_array), &iterator)) != NULL) { if (i++) { ZEND_PUTS(", "); } - zend_print_flat_zval_r(*tmp TSRMLS_CC); - zend_hash_move_forward_ex(arg_array->value.ht, &iterator); + zend_print_flat_zval_r(tmp TSRMLS_CC); + zend_hash_move_forward_ex(Z_ARRVAL_P(arg_array), &iterator); } } @@ -2073,10 +2000,10 @@ ZEND_FUNCTION(debug_print_backtrace) int lineno, frameno = 0; const char *function_name; const char *filename; - const char *class_name = NULL; + zend_string *class_name = NULL; char *call_type; const char *include_filename = NULL; - zval *arg_array = NULL; + zval arg_array; int indent = 0; long options = 0; long limit = 0; @@ -2085,17 +2012,19 @@ ZEND_FUNCTION(debug_print_backtrace) return; } + ZVAL_UNDEF(&arg_array); ptr = EG(current_execute_data); /* skip debug_backtrace() */ ptr = ptr->prev_execute_data; while (ptr && (limit == 0 || frameno < limit)) { - const char *free_class_name = NULL; +//??? const char *free_class_name = NULL; frameno++; - class_name = call_type = NULL; - arg_array = NULL; + class_name = NULL; + call_type = NULL; + ZVAL_UNDEF(&arg_array); skip = ptr; /* skip internal handler */ @@ -2109,7 +2038,7 @@ ZEND_FUNCTION(debug_print_backtrace) } if (skip->op_array) { - filename = skip->op_array->filename; + filename = skip->op_array->filename->val; lineno = skip->opline->lineno; } else { filename = NULL; @@ -2119,24 +2048,18 @@ ZEND_FUNCTION(debug_print_backtrace) function_name = (ptr->function_state.function->common.scope && ptr->function_state.function->common.scope->trait_aliases) ? zend_resolve_method_name( - ptr->object ? - Z_OBJCE_P(ptr->object) : + Z_TYPE(ptr->object) != IS_UNDEF ? + Z_OBJCE(ptr->object) : ptr->function_state.function->common.scope, - ptr->function_state.function) : - ptr->function_state.function->common.function_name; + ptr->function_state.function)->val : + ptr->function_state.function->common.function_name->val; if (function_name) { - if (ptr->object) { + if (Z_TYPE(ptr->object) != IS_UNDEF) { if (ptr->function_state.function->common.scope) { class_name = ptr->function_state.function->common.scope->name; } else { - zend_uint class_name_len; - int dup; - - dup = zend_get_object_classname(ptr->object, &class_name, &class_name_len TSRMLS_CC); - if(!dup) { - free_class_name = class_name; - } + class_name = zend_get_object_classname(&ptr->object TSRMLS_CC); } call_type = "->"; @@ -2149,7 +2072,7 @@ ZEND_FUNCTION(debug_print_backtrace) } if ((! ptr->opline) || ((ptr->opline->opcode == ZEND_DO_FCALL_BY_NAME) || (ptr->opline->opcode == ZEND_DO_FCALL))) { if (ptr->function_state.arguments && (options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0) { - arg_array = debug_backtrace_get_args(ptr->function_state.arguments TSRMLS_CC); + debug_backtrace_get_args(ptr->function_state.arguments, &arg_array TSRMLS_CC); } } } else { @@ -2187,20 +2110,19 @@ ZEND_FUNCTION(debug_print_backtrace) } if (build_filename_arg && include_filename) { - MAKE_STD_ZVAL(arg_array); - array_init(arg_array); - add_next_index_string(arg_array, (char*)include_filename, 1); + array_init(&arg_array); + add_next_index_string(&arg_array, (char*)include_filename, 1); } call_type = NULL; } zend_printf("#%-2d ", indent); if (class_name) { - ZEND_PUTS(class_name); + ZEND_PUTS(class_name->val); ZEND_PUTS(call_type); } zend_printf("%s(", function_name); - if (arg_array) { - debug_print_backtrace_args(arg_array TSRMLS_CC); + if (Z_TYPE(arg_array) != IS_UNDEF) { + debug_print_backtrace_args(&arg_array TSRMLS_CC); zval_ptr_dtor(&arg_array); } if (filename) { @@ -2215,7 +2137,7 @@ ZEND_FUNCTION(debug_print_backtrace) break; } if (prev->op_array) { - zend_printf(") called at [%s:%d]\n", prev->op_array->filename, prev->opline->lineno); + zend_printf(") called at [%s:%d]\n", prev->op_array->filename->val, prev->opline->lineno); break; } prev = prev->prev_execute_data; @@ -2227,9 +2149,9 @@ ZEND_FUNCTION(debug_print_backtrace) include_filename = filename; ptr = skip->prev_execute_data; ++indent; - if (free_class_name) { - efree((char*)free_class_name); - } +//??? if (free_class_name) { +//??? efree((char*)free_class_name); +//??? } } } @@ -2241,9 +2163,9 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int int lineno, frameno = 0; const char *function_name; const char *filename; - const char *class_name; + zend_string *class_name; const char *include_filename = NULL; - zval *stack_frame; + zval stack_frame; ptr = EG(current_execute_data); @@ -2261,8 +2183,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int while (ptr && (limit == 0 || frameno < limit)) { frameno++; - MAKE_STD_ZVAL(stack_frame); - array_init(stack_frame); + array_init(&stack_frame); skip = ptr; /* skip internal handler */ @@ -2276,10 +2197,10 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int } if (skip->op_array) { - filename = skip->op_array->filename; + filename = skip->op_array->filename->val; lineno = skip->opline->lineno; - add_assoc_string_ex(stack_frame, "file", sizeof("file"), (char*)filename, 1); - add_assoc_long_ex(stack_frame, "line", sizeof("line"), lineno); + add_assoc_string_ex(&stack_frame, "file", sizeof("file")-1, (char*)filename, 1); + add_assoc_long_ex(&stack_frame, "line", sizeof("line")-1, lineno); /* try to fetch args only if an FCALL was just made - elsewise we're in the middle of a function * and debug_baktrace() might have been called by the error_handler. in this case we don't @@ -2295,8 +2216,8 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int break; } if (prev->op_array) { - add_assoc_string_ex(stack_frame, "file", sizeof("file"), (char*)prev->op_array->filename, 1); - add_assoc_long_ex(stack_frame, "line", sizeof("line"), prev->opline->lineno); + add_assoc_str_ex(&stack_frame, "file", sizeof("file")-1, prev->op_array->filename); + add_assoc_long_ex(&stack_frame, "line", sizeof("line")-1, prev->opline->lineno); break; } prev = prev->prev_execute_data; @@ -2307,41 +2228,40 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int function_name = (ptr->function_state.function->common.scope && ptr->function_state.function->common.scope->trait_aliases) ? zend_resolve_method_name( - ptr->object ? - Z_OBJCE_P(ptr->object) : + Z_TYPE(ptr->object) != IS_UNDEF ? + Z_OBJCE(ptr->object) : ptr->function_state.function->common.scope, - ptr->function_state.function) : - ptr->function_state.function->common.function_name; + ptr->function_state.function)->val : + ptr->function_state.function->common.function_name->val; if (function_name) { - add_assoc_string_ex(stack_frame, "function", sizeof("function"), (char*)function_name, 1); + add_assoc_string_ex(&stack_frame, "function", sizeof("function")-1, (char*)function_name, 1); - if (ptr->object && Z_TYPE_P(ptr->object) == IS_OBJECT) { + if (Z_TYPE(ptr->object) == IS_OBJECT) { if (ptr->function_state.function->common.scope) { - add_assoc_string_ex(stack_frame, "class", sizeof("class"), (char*)ptr->function_state.function->common.scope->name, 1); + add_assoc_str_ex(&stack_frame, "class", sizeof("class")-1, ptr->function_state.function->common.scope->name); } else { - zend_uint class_name_len; - int dup; - - dup = zend_get_object_classname(ptr->object, &class_name, &class_name_len TSRMLS_CC); - add_assoc_string_ex(stack_frame, "class", sizeof("class"), (char*)class_name, dup); + class_name = zend_get_object_classname(&ptr->object TSRMLS_CC); + add_assoc_str_ex(&stack_frame, "class", sizeof("class")-1, class_name); } if ((options & DEBUG_BACKTRACE_PROVIDE_OBJECT) != 0) { - add_assoc_zval_ex(stack_frame, "object", sizeof("object"), ptr->object); - Z_ADDREF_P(ptr->object); + add_assoc_zval_ex(&stack_frame, "object", sizeof("object")-1, &ptr->object); + Z_ADDREF(ptr->object); } - add_assoc_string_ex(stack_frame, "type", sizeof("type"), "->", 1); + add_assoc_string_ex(&stack_frame, "type", sizeof("type")-1, "->", 1); } else if (ptr->function_state.function->common.scope) { - add_assoc_string_ex(stack_frame, "class", sizeof("class"), (char*)ptr->function_state.function->common.scope->name, 1); - add_assoc_string_ex(stack_frame, "type", sizeof("type"), "::", 1); + add_assoc_str_ex(&stack_frame, "class", sizeof("class")-1, ptr->function_state.function->common.scope->name); + add_assoc_string_ex(&stack_frame, "type", sizeof("type")-1, "::", 1); } if ((options & DEBUG_BACKTRACE_IGNORE_ARGS) == 0 && ((! ptr->opline) || ((ptr->opline->opcode == ZEND_DO_FCALL_BY_NAME) || (ptr->opline->opcode == ZEND_DO_FCALL)))) { if (ptr->function_state.arguments) { - add_assoc_zval_ex(stack_frame, "args", sizeof("args"), debug_backtrace_get_args(ptr->function_state.arguments TSRMLS_CC)); + zval args; + debug_backtrace_get_args(ptr->function_state.arguments, &args TSRMLS_CC); + add_assoc_zval_ex(&stack_frame, "args", sizeof("args")-1, &args TSRMLS_CC); } } } else { @@ -2379,23 +2299,22 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int } if (build_filename_arg && include_filename) { - zval *arg_array; + zval arg_array; - MAKE_STD_ZVAL(arg_array); - array_init(arg_array); + array_init(&arg_array); /* include_filename always points to the last filename of the last last called-function. if we have called include in the frame above - this is the file we have included. */ - add_next_index_string(arg_array, (char*)include_filename, 1); - add_assoc_zval_ex(stack_frame, "args", sizeof("args"), arg_array); + add_next_index_string(&arg_array, (char*)include_filename, 1); + add_assoc_zval_ex(&stack_frame, "args", sizeof("args")-1, &arg_array); } - add_assoc_string_ex(stack_frame, "function", sizeof("function"), (char*)function_name, 1); + add_assoc_string_ex(&stack_frame, "function", sizeof("function")-1, (char*)function_name, 1); } - add_next_index_zval(return_value, stack_frame); + add_next_index_zval(return_value, &stack_frame); include_filename = filename; @@ -2426,19 +2345,20 @@ ZEND_FUNCTION(extension_loaded) { char *extension_name; int extension_name_len; - char *lcname; + zend_string *lcname; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &extension_name, &extension_name_len) == FAILURE) { return; } - lcname = zend_str_tolower_dup(extension_name, extension_name_len); - if (zend_hash_exists(&module_registry, lcname, extension_name_len+1)) { + lcname = STR_ALLOC(extension_name_len, 0); + zend_str_tolower_copy(lcname->val, extension_name, extension_name_len); + if (zend_hash_exists(&module_registry, lcname)) { RETVAL_TRUE; } else { RETVAL_FALSE; } - efree(lcname); + STR_FREE(lcname); } /* }}} */ @@ -2447,7 +2367,8 @@ ZEND_FUNCTION(extension_loaded) Returns an array with the names of functions belonging to the named extension */ ZEND_FUNCTION(get_extension_funcs) { - char *extension_name, *lcname; + char *extension_name; + zend_string *lcname; int extension_name_len, array; zend_module_entry *module; HashPosition iterator; @@ -2456,13 +2377,14 @@ ZEND_FUNCTION(get_extension_funcs) return; } if (strncasecmp(extension_name, "zend", sizeof("zend"))) { - lcname = zend_str_tolower_dup(extension_name, extension_name_len); + lcname = STR_ALLOC(extension_name_len, 0); + zend_str_tolower_copy(lcname->val, extension_name, extension_name_len); } else { - lcname = estrdup("core"); + lcname = STR_INIT("core", sizeof("core")-1, 0); } - if (zend_hash_find(&module_registry, lcname, - extension_name_len+1, (void**)&module) == FAILURE) { - efree(lcname); + module = zend_hash_find_ptr(&module_registry, lcname); + STR_FREE(lcname); + if (!module) { RETURN_FALSE; } @@ -2474,20 +2396,18 @@ ZEND_FUNCTION(get_extension_funcs) } else { array = 0; } - while (zend_hash_get_current_data_ex(CG(function_table), (void **) &zif, &iterator) == SUCCESS) { + while ((zif = zend_hash_get_current_data_ptr_ex(CG(function_table), &iterator)) == SUCCESS) { if (zif->common.type==ZEND_INTERNAL_FUNCTION && zif->internal_function.module == module) { if (!array) { array_init(return_value); array = 1; } - add_next_index_string(return_value, zif->common.function_name, 1); + add_next_index_str(return_value, zif->common.function_name); } zend_hash_move_forward_ex(CG(function_table), &iterator); } - efree(lcname); - if (!array) { RETURN_FALSE; } |