diff options
-rw-r--r-- | Zend/zend_API.c | 63 | ||||
-rw-r--r-- | Zend/zend_builtin_functions.c | 152 | ||||
-rw-r--r-- | Zend/zend_inheritance.c | 4 | ||||
-rw-r--r-- | Zend/zend_ini.c | 34 | ||||
-rw-r--r-- | Zend/zend_list.c | 19 | ||||
-rw-r--r-- | ext/opcache/zend_persist.c | 12 | ||||
-rw-r--r-- | ext/spl/php_spl.c | 13 | ||||
-rw-r--r-- | ext/standard/basic_functions.c | 140 | ||||
-rw-r--r-- | ext/standard/browscap.c | 16 | ||||
-rw-r--r-- | ext/standard/info.c | 33 | ||||
-rw-r--r-- | main/php_ini.c | 85 | ||||
-rw-r--r-- | main/rfc1867.c | 16 | ||||
-rw-r--r-- | main/streams/streams.c | 6 | ||||
-rw-r--r-- | sapi/cgi/cgi_main.c | 12 | ||||
-rw-r--r-- | sapi/cli/php_cli.c | 13 | ||||
-rw-r--r-- | sapi/fpm/fpm/fpm_main.c | 13 |
16 files changed, 274 insertions, 357 deletions
diff --git a/Zend/zend_API.c b/Zend/zend_API.c index d1cb145c50..51e477b2ef 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2626,28 +2626,22 @@ ZEND_API void zend_activate_modules(void) /* {{{ */ } /* }}} */ -/* call request shutdown for all modules */ -static int module_registry_cleanup(zval *zv) /* {{{ */ -{ - zend_module_entry *module = Z_PTR_P(zv); - - if (module->request_shutdown_func) { -#if 0 - zend_printf("%s: Request shutdown\n", module->name); -#endif - module->request_shutdown_func(module->type, module->module_number); - } - return 0; -} -/* }}} */ - ZEND_API void zend_deactivate_modules(void) /* {{{ */ { EG(current_execute_data) = NULL; /* we're no longer executing anything */ zend_try { if (EG(full_tables_cleanup)) { - zend_hash_reverse_apply(&module_registry, module_registry_cleanup); + zend_module_entry *module; + + ZEND_HASH_REVERSE_FOREACH_PTR(&module_registry, module) { + if (module->request_shutdown_func) { +#if 0 + zend_printf("%s: Request shutdown\n", module->name); +#endif + module->request_shutdown_func(module->type, module->module_number); + } + } ZEND_HASH_FOREACH_END(); } else { zend_module_entry **p = module_request_shutdown_handlers; @@ -2673,34 +2667,21 @@ ZEND_API void zend_cleanup_internal_classes(void) /* {{{ */ } /* }}} */ -int module_registry_unload_temp(const zend_module_entry *module) /* {{{ */ -{ - return (module->type == MODULE_TEMPORARY) ? ZEND_HASH_APPLY_REMOVE : ZEND_HASH_APPLY_STOP; -} -/* }}} */ - -static int module_registry_unload_temp_wrapper(zval *el) /* {{{ */ -{ - zend_module_entry *module = (zend_module_entry *)Z_PTR_P(el); - return module_registry_unload_temp((const zend_module_entry *)module); -} -/* }}} */ - -static int exec_done_cb(zval *el) /* {{{ */ -{ - zend_module_entry *module = (zend_module_entry *)Z_PTR_P(el); - if (module->post_deactivate_func) { - module->post_deactivate_func(); - } - return 0; -} -/* }}} */ - ZEND_API void zend_post_deactivate_modules(void) /* {{{ */ { if (EG(full_tables_cleanup)) { - zend_hash_apply(&module_registry, exec_done_cb); - zend_hash_reverse_apply(&module_registry, module_registry_unload_temp_wrapper); + zend_module_entry *module; + + ZEND_HASH_FOREACH_PTR(&module_registry, module) { + if (module->post_deactivate_func) { + module->post_deactivate_func(); + } + } ZEND_HASH_FOREACH_END(); + ZEND_HASH_REVERSE_FOREACH_PTR(&module_registry, module) { + if (module->type != MODULE_TEMPORARY) { + break; + } + } ZEND_HASH_FOREACH_END_DEL(); } else { zend_module_entry **p = module_post_deactivate_handlers; diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index c020c98b20..3fce84d6a4 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1759,24 +1759,13 @@ ZEND_FUNCTION(restore_exception_handler) } /* }}} */ -static int copy_class_or_interface_name(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ -{ - zend_class_entry *ce = (zend_class_entry *)Z_PTR_P(el); - zval *array = va_arg(args, zval *); - uint32_t mask = va_arg(args, uint32_t); - uint32_t comply = va_arg(args, uint32_t); - uint32_t comply_mask = (comply)? mask:0; - - if ((hash_key->key && ZSTR_VAL(hash_key->key)[0] != 0) - && (comply_mask == (ce->ce_flags & mask))) { - if ((ce->refcount > 1 || (ce->ce_flags & ZEND_ACC_IMMUTABLE)) && - !same_name(hash_key->key, ce->name)) { - add_next_index_str(array, zend_string_copy(hash_key->key)); - } else { - add_next_index_str(array, zend_string_copy(ce->name)); - } +static void copy_class_or_interface_name(zval *array, zend_string *key, zend_class_entry *ce) /* {{{ */ +{ + if ((ce->refcount == 1 && !(ce->ce_flags & ZEND_ACC_IMMUTABLE)) || + same_name(key, ce->name)) { + key = ce->name; } - return ZEND_HASH_APPLY_KEEP; + add_next_index_str(array, zend_string_copy(key)); } /* }}} */ @@ -1784,15 +1773,21 @@ static int copy_class_or_interface_name(zval *el, int num_args, va_list args, ze Returns an array of all declared traits. */ ZEND_FUNCTION(get_declared_traits) { - uint32_t mask = ZEND_ACC_TRAIT; - uint32_t comply = 1; + zend_string *key; + zend_class_entry *ce; if (zend_parse_parameters_none() == FAILURE) { return; } array_init(return_value); - zend_hash_apply_with_arguments(EG(class_table), copy_class_or_interface_name, 3, return_value, mask, comply); + ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) { + if (key + && ZSTR_VAL(key)[0] != 0 + && (ce->ce_flags & ZEND_ACC_TRAIT)) { + copy_class_or_interface_name(return_value, key, ce); + } + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -1800,15 +1795,21 @@ ZEND_FUNCTION(get_declared_traits) Returns an array of all declared classes. */ ZEND_FUNCTION(get_declared_classes) { - uint32_t mask = ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT; - uint32_t comply = 0; + zend_string *key; + zend_class_entry *ce; if (zend_parse_parameters_none() == FAILURE) { return; } array_init(return_value); - zend_hash_apply_with_arguments(EG(class_table), copy_class_or_interface_name, 3, return_value, mask, comply); + ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) { + if (key + && ZSTR_VAL(key)[0] != 0 + && !(ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT))) { + copy_class_or_interface_name(return_value, key, ce); + } + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -1816,44 +1817,21 @@ ZEND_FUNCTION(get_declared_classes) Returns an array of all declared interfaces. */ ZEND_FUNCTION(get_declared_interfaces) { - uint32_t mask = ZEND_ACC_INTERFACE; - uint32_t comply = 1; + zend_string *key; + zend_class_entry *ce; if (zend_parse_parameters_none() == FAILURE) { return; } array_init(return_value); - zend_hash_apply_with_arguments(EG(class_table), copy_class_or_interface_name, 3, return_value, mask, comply); -} -/* }}} */ - -static int copy_function_name(zval *zv, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ -{ - zend_function *func = Z_PTR_P(zv); - zval *internal_ar = va_arg(args, zval *), - *user_ar = va_arg(args, zval *); - zend_bool *exclude_disabled = va_arg(args, zend_bool *); - - if (hash_key->key == NULL || ZSTR_VAL(hash_key->key)[0] == 0) { - return 0; - } - - if (func->type == ZEND_INTERNAL_FUNCTION) { - char *disable_functions = INI_STR("disable_functions"); - - if ((*exclude_disabled == 1) && (disable_functions != NULL)) { - if (strstr(disable_functions, func->common.function_name->val) == NULL) { - add_next_index_str(internal_ar, zend_string_copy(hash_key->key)); - } - } else { - add_next_index_str(internal_ar, zend_string_copy(hash_key->key)); + ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) { + if (key + && ZSTR_VAL(key)[0] != 0 + && (ce->ce_flags & ZEND_ACC_INTERFACE)) { + copy_class_or_interface_name(return_value, key, ce); } - } else if (func->type == ZEND_USER_FUNCTION) { - add_next_index_str(user_ar, zend_string_copy(hash_key->key)); - } - - return 0; + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -1862,7 +1840,10 @@ static int copy_function_name(zval *zv, int num_args, va_list args, zend_hash_ke ZEND_FUNCTION(get_defined_functions) { zval internal, user; + zend_string *key; + zend_function *func; zend_bool exclude_disabled = 0; + char *disable_functions = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &exclude_disabled) == FAILURE) { return; @@ -1872,7 +1853,24 @@ ZEND_FUNCTION(get_defined_functions) array_init(&user); array_init(return_value); - zend_hash_apply_with_arguments(EG(function_table), copy_function_name, 3, &internal, &user, &exclude_disabled); + if (exclude_disabled) { + disable_functions = INI_STR("disable_functions"); + } + ZEND_HASH_FOREACH_STR_KEY_PTR(EG(function_table), key, func) { + if (key && ZSTR_VAL(key)[0] != 0) { + if (func->type == ZEND_INTERNAL_FUNCTION) { + if (disable_functions != NULL) { + if (strstr(disable_functions, func->common.function_name->val) == NULL) { + add_next_index_str(&internal, zend_string_copy(key)); + } + } else { + add_next_index_str(&internal, zend_string_copy(key)); + } + } else if (func->type == ZEND_USER_FUNCTION) { + add_next_index_str(&user, zend_string_copy(key)); + } + } + } ZEND_HASH_FOREACH_END(); zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal); zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user); @@ -2044,15 +2042,6 @@ ZEND_FUNCTION(get_resources) } /* }}} */ -static int add_extension_info(zval *item, void *arg) /* {{{ */ -{ - zval *name_array = (zval *)arg; - zend_module_entry *module = (zend_module_entry*)Z_PTR_P(item); - add_next_index_string(name_array, module->name); - return 0; -} -/* }}} */ - static int add_zendext_info(zend_extension *ext, void *arg) /* {{{ */ { zval *name_array = (zval *)arg; @@ -2061,23 +2050,6 @@ static int add_zendext_info(zend_extension *ext, void *arg) /* {{{ */ } /* }}} */ -static int add_constant_info(zval *item, void *arg) /* {{{ */ -{ - zval *name_array = (zval *)arg; - zend_constant *constant = (zend_constant*)Z_PTR_P(item); - zval const_val; - - if (!constant->name) { - /* skip special constants */ - return 0; - } - - ZVAL_COPY_OR_DUP(&const_val, &constant->value); - zend_hash_add_new(Z_ARRVAL_P(name_array), constant->name, &const_val); - return 0; -} -/* }}} */ - /* {{{ proto array get_loaded_extensions([bool zend_extensions]) Return an array containing names of loaded extensions */ ZEND_FUNCTION(get_loaded_extensions) @@ -2093,7 +2065,11 @@ ZEND_FUNCTION(get_loaded_extensions) if (zendext) { zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t)add_zendext_info, return_value); } else { - zend_hash_apply_with_argument(&module_registry, add_extension_info, return_value); + zend_module_entry *module; + + ZEND_HASH_FOREACH_PTR(&module_registry, module) { + add_next_index_string(return_value, module->name); + } ZEND_HASH_FOREACH_END(); } } /* }}} */ @@ -2155,7 +2131,17 @@ ZEND_FUNCTION(get_defined_constants) efree(module_names); efree(modules); } else { - zend_hash_apply_with_argument(EG(zend_constants), add_constant_info, return_value); + zend_constant *constant; + zval const_val; + + ZEND_HASH_FOREACH_PTR(EG(zend_constants), constant) { + if (!constant->name) { + /* skip special constants */ + continue; + } + ZVAL_COPY_OR_DUP(&const_val, &constant->value); + zend_hash_add_new(Z_ARRVAL_P(return_value), constant->name, &const_val); + } ZEND_HASH_FOREACH_END(); } } /* }}} */ diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index b116a7fbee..387c1ca4d7 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -1333,7 +1333,7 @@ static void zend_fixup_trait_method(zend_function *fn, zend_class_entry *ce) /* } /* }}} */ -static int zend_traits_copy_functions(zend_string *fnname, zend_function *fn, zend_class_entry *ce, HashTable **overridden, HashTable *exclude_table, zend_class_entry **aliases) /* {{{ */ +static void zend_traits_copy_functions(zend_string *fnname, zend_function *fn, zend_class_entry *ce, HashTable **overridden, HashTable *exclude_table, zend_class_entry **aliases) /* {{{ */ { zend_trait_alias *alias, **alias_ptr; zend_string *lcname; @@ -1413,8 +1413,6 @@ static int zend_traits_copy_functions(zend_string *fnname, zend_function *fn, ze zend_add_trait_method(ce, ZSTR_VAL(fn->common.function_name), fnname, &fn_copy, overridden); } - - return ZEND_HASH_APPLY_KEEP; } /* }}} */ diff --git a/Zend/zend_ini.c b/Zend/zend_ini.c index 6ae963f3b7..07af7b223c 100644 --- a/Zend/zend_ini.c +++ b/Zend/zend_ini.c @@ -71,14 +71,6 @@ static int zend_restore_ini_entry_cb(zend_ini_entry *ini_entry, int stage) /* {{ } /* }}} */ -static int zend_restore_ini_entry_wrapper(zval *el) /* {{{ */ -{ - zend_ini_entry *ini_entry = (zend_ini_entry *)Z_PTR_P(el); - zend_restore_ini_entry_cb(ini_entry, ZEND_INI_STAGE_DEACTIVATE); - return 1; -} -/* }}} */ - static void free_ini_entry(zval *zv) /* {{{ */ { zend_ini_entry *entry = (zend_ini_entry*)Z_PTR_P(zv); @@ -134,7 +126,11 @@ ZEND_API int zend_ini_global_shutdown(void) /* {{{ */ ZEND_API int zend_ini_deactivate(void) /* {{{ */ { if (EG(modified_ini_directives)) { - zend_hash_apply(EG(modified_ini_directives), zend_restore_ini_entry_wrapper); + zend_ini_entry *ini_entry; + + ZEND_HASH_FOREACH_PTR(EG(modified_ini_directives), ini_entry) { + zend_restore_ini_entry_cb(ini_entry, ZEND_INI_STAGE_DEACTIVATE); + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(EG(modified_ini_directives)); FREE_HASHTABLE(EG(modified_ini_directives)); EG(modified_ini_directives) = NULL; @@ -277,21 +273,15 @@ ZEND_API void zend_unregister_ini_entries(int module_number) /* {{{ */ /* }}} */ #ifdef ZTS -static int zend_ini_refresh_cache(zval *el, void *arg) /* {{{ */ -{ - zend_ini_entry *p = (zend_ini_entry *)Z_PTR_P(el); - int stage = (int)(zend_intptr_t)arg; - - if (p->on_modify) { - p->on_modify(p, p->value, p->mh_arg1, p->mh_arg2, p->mh_arg3, stage); - } - return 0; -} -/* }}} */ - ZEND_API void zend_ini_refresh_caches(int stage) /* {{{ */ { - zend_hash_apply_with_argument(EG(ini_directives), zend_ini_refresh_cache, (void *)(zend_intptr_t) stage); + zend_ini_entry *p; + + ZEND_HASH_FOREACH_PTR(EG(ini_directives), p) { + if (p->on_modify) { + p->on_modify(p, p->value, p->mh_arg1, p->mh_arg2, p->mh_arg3, stage); + } + } ZEND_HASH_FOREACH_END(); } /* }}} */ #endif diff --git a/Zend/zend_list.c b/Zend/zend_list.c index cf878ef430..cd6b6073a9 100644 --- a/Zend/zend_list.c +++ b/Zend/zend_list.c @@ -220,20 +220,15 @@ int zend_init_rsrc_plist(void) } -static int zend_close_rsrc(zval *zv) -{ - zend_resource *res = Z_PTR_P(zv); - - if (res->type >= 0) { - zend_resource_dtor(res); - } - return ZEND_HASH_APPLY_KEEP; -} - - void zend_close_rsrc_list(HashTable *ht) { - zend_hash_reverse_apply(ht, zend_close_rsrc); + zend_resource *res; + + ZEND_HASH_REVERSE_FOREACH_PTR(ht, res) { + if (res->type >= 0) { + zend_resource_dtor(res); + } + } ZEND_HASH_FOREACH_END(); } diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index 9ab4cd6d33..b66d83e05c 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -929,10 +929,8 @@ static void zend_persist_class_entry(zval *zv) // return 0; //} -static int zend_update_parent_ce(zval *zv) +static void zend_update_parent_ce(zend_class_entry *ce) { - zend_class_entry *ce = Z_PTR_P(zv); - if (ce->ce_flags & ZEND_ACC_LINKED) { if (ce->parent) { int i, end; @@ -1067,14 +1065,16 @@ static int zend_update_parent_ce(zval *zv) ce->__debugInfo = tmp; } } -// zend_hash_apply(&ce->properties_info, (apply_func_t) zend_update_property_info_ce); - return 0; } static void zend_accel_persist_class_table(HashTable *class_table) { + zend_class_entry *ce; + zend_hash_persist(class_table, zend_persist_class_entry); - zend_hash_apply(class_table, (apply_func_t) zend_update_parent_ce); + ZEND_HASH_FOREACH_PTR(class_table, ce) { + zend_update_parent_ce(ce); + } ZEND_HASH_FOREACH_END(); } zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, const char **key, unsigned int key_length, int for_shm) diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index c80adaed94..da520d62e0 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -855,21 +855,20 @@ PHPAPI zend_string *php_spl_object_hash(zval *obj) /* {{{*/ } /* }}} */ -int spl_build_class_list_string(zval *entry, char **list) /* {{{ */ +static void spl_build_class_list_string(zval *entry, char **list) /* {{{ */ { char *res; spprintf(&res, 0, "%s, %s", *list, Z_STRVAL_P(entry)); efree(*list); *list = res; - return ZEND_HASH_APPLY_KEEP; } /* }}} */ /* {{{ PHP_MINFO(spl) */ PHP_MINFO_FUNCTION(spl) { - zval list; + zval list, *zv; char *strg; php_info_print_table_start(); @@ -878,7 +877,9 @@ PHP_MINFO_FUNCTION(spl) array_init(&list); SPL_LIST_CLASSES(&list, 0, 1, ZEND_ACC_INTERFACE) strg = estrdup(""); - zend_hash_apply_with_argument(Z_ARRVAL_P(&list), (apply_func_arg_t)spl_build_class_list_string, &strg); + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { + spl_build_class_list_string(zv, &strg); + } ZEND_HASH_FOREACH_END(); zend_array_destroy(Z_ARR(list)); php_info_print_table_row(2, "Interfaces", strg + 2); efree(strg); @@ -886,7 +887,9 @@ PHP_MINFO_FUNCTION(spl) array_init(&list); SPL_LIST_CLASSES(&list, 0, -1, ZEND_ACC_INTERFACE) strg = estrdup(""); - zend_hash_apply_with_argument(Z_ARRVAL_P(&list), (apply_func_arg_t)spl_build_class_list_string, &strg); + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { + spl_build_class_list_string(zv, &strg); + } ZEND_HASH_FOREACH_END(); zend_array_destroy(Z_ARR(list)); php_info_print_table_row(2, "Classes", strg + 2); efree(strg); diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 68aa7e1ef3..9026cacc79 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4688,25 +4688,41 @@ PHP_FUNCTION(get_current_user) } /* }}} */ -/* {{{ add_config_entry_cb +/* {{{ add_config_entry */ -static int add_config_entry_cb(zval *entry, int num_args, va_list args, zend_hash_key *hash_key) +static void add_config_entry(zend_ulong h, zend_string *key, zval *entry, zval *retval) { - zval *retval = (zval *)va_arg(args, zval*); - zval tmp; - if (Z_TYPE_P(entry) == IS_STRING) { - if (hash_key->key) { - add_assoc_str_ex(retval, ZSTR_VAL(hash_key->key), ZSTR_LEN(hash_key->key), zend_string_copy(Z_STR_P(entry))); + if (key) { + add_assoc_str_ex(retval, ZSTR_VAL(key), ZSTR_LEN(key), zend_string_copy(Z_STR_P(entry))); } else { - add_index_str(retval, hash_key->h, zend_string_copy(Z_STR_P(entry))); + add_index_str(retval, h, zend_string_copy(Z_STR_P(entry))); } } else if (Z_TYPE_P(entry) == IS_ARRAY) { + zend_ulong h; + zend_string *key; + zval *zv, tmp; + array_init(&tmp); - zend_hash_apply_with_arguments(Z_ARRVAL_P(entry), add_config_entry_cb, 1, tmp); - zend_hash_update(Z_ARRVAL_P(retval), hash_key->key, &tmp); + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(entry), h, key, zv) + add_config_entry(h, key, zv, &tmp); + ZEND_HASH_FOREACH_END(); + zend_hash_update(Z_ARRVAL_P(retval), key, &tmp); } - return 0; +} +/* }}} */ + +/* {{{ add_config_entries + */ +static void add_config_entries(HashTable *hash, zval *return_value) /* {{{ */ +{ + zend_ulong h; + zend_string *key; + zval *zv; + + ZEND_HASH_FOREACH_KEY_VAL(hash, h, key, zv) + add_config_entry(h, key, zv, return_value); + ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -4727,7 +4743,7 @@ PHP_FUNCTION(get_cfg_var) if (retval) { if (Z_TYPE_P(retval) == IS_ARRAY) { array_init(return_value); - zend_hash_apply_with_arguments(Z_ARRVAL_P(retval), add_config_entry_cb, 1, return_value); + add_config_entries(Z_ARRVAL_P(retval), return_value); return; } else { RETURN_STRING(Z_STRVAL_P(retval)); @@ -5407,64 +5423,17 @@ PHP_FUNCTION(ini_get) } /* }}} */ -static int php_ini_get_option(zval *zv, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ -{ - zend_ini_entry *ini_entry = Z_PTR_P(zv); - zval *ini_array = va_arg(args, zval *); - int module_number = va_arg(args, int); - int details = va_arg(args, int); - zval option; - - if (module_number != 0 && ini_entry->module_number != module_number) { - return 0; - } - - if (hash_key->key == NULL || - ZSTR_VAL(hash_key->key)[0] != 0 - ) { - if (details) { - array_init(&option); - - if (ini_entry->orig_value) { - add_assoc_str(&option, "global_value", zend_string_copy(ini_entry->orig_value)); - } else if (ini_entry->value) { - add_assoc_str(&option, "global_value", zend_string_copy(ini_entry->value)); - } else { - add_assoc_null(&option, "global_value"); - } - - if (ini_entry->value) { - add_assoc_str(&option, "local_value", zend_string_copy(ini_entry->value)); - } else { - add_assoc_null(&option, "local_value"); - } - - add_assoc_long(&option, "access", ini_entry->modifiable); - - zend_symtable_update(Z_ARRVAL_P(ini_array), ini_entry->name, &option); - } else { - if (ini_entry->value) { - zval zv; - - ZVAL_STR_COPY(&zv, ini_entry->value); - zend_symtable_update(Z_ARRVAL_P(ini_array), ini_entry->name, &zv); - } else { - zend_symtable_update(Z_ARRVAL_P(ini_array), ini_entry->name, &EG(uninitialized_zval)); - } - } - } - return 0; -} -/* }}} */ - /* {{{ proto array ini_get_all([string extension[, bool details = true]]) Get all configuration options */ PHP_FUNCTION(ini_get_all) { char *extname = NULL; - size_t extname_len = 0, extnumber = 0; + size_t extname_len = 0, module_number = 0; zend_module_entry *module; zend_bool details = 1; + zend_string *key; + zend_ini_entry *ini_entry; + ZEND_PARSE_PARAMETERS_START(0, 2) Z_PARAM_OPTIONAL @@ -5479,11 +5448,50 @@ PHP_FUNCTION(ini_get_all) php_error_docref(NULL, E_WARNING, "Unable to find extension '%s'", extname); RETURN_FALSE; } - extnumber = module->module_number; + module_number = module->module_number; } array_init(return_value); - zend_hash_apply_with_arguments(EG(ini_directives), php_ini_get_option, 2, return_value, extnumber, details); + ZEND_HASH_FOREACH_STR_KEY_PTR(EG(ini_directives), key, ini_entry) { + zval option; + + if (module_number != 0 && ini_entry->module_number != module_number) { + continue; + } + + if (key == NULL || ZSTR_VAL(key)[0] != 0) { + if (details) { + array_init(&option); + + if (ini_entry->orig_value) { + add_assoc_str(&option, "global_value", zend_string_copy(ini_entry->orig_value)); + } else if (ini_entry->value) { + add_assoc_str(&option, "global_value", zend_string_copy(ini_entry->value)); + } else { + add_assoc_null(&option, "global_value"); + } + + if (ini_entry->value) { + add_assoc_str(&option, "local_value", zend_string_copy(ini_entry->value)); + } else { + add_assoc_null(&option, "local_value"); + } + + add_assoc_long(&option, "access", ini_entry->modifiable); + + zend_symtable_update(Z_ARRVAL_P(return_value), ini_entry->name, &option); + } else { + if (ini_entry->value) { + zval zv; + + ZVAL_STR_COPY(&zv, ini_entry->value); + zend_symtable_update(Z_ARRVAL_P(return_value), ini_entry->name, &zv); + } else { + zend_symtable_update(Z_ARRVAL_P(return_value), ini_entry->name, &EG(uninitialized_zval)); + } + } + } + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -6142,7 +6150,7 @@ PHP_FUNCTION(config_get_hash) /* {{{ */ HashTable *hash = php_ini_get_configuration_hash(); array_init(return_value); - zend_hash_apply_with_arguments(hash, add_config_entry_cb, 1, return_value); + add_config_entries(hash, return_value); } /* }}} */ #endif diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c index 8a2272fe00..cb6b98fe7b 100644 --- a/ext/standard/browscap.c +++ b/ext/standard/browscap.c @@ -563,12 +563,8 @@ static inline size_t browscap_get_minimum_length(browscap_entry *entry) { return len; } -static int browser_reg_compare( - zval *entry_zv, int num_args, va_list args, zend_hash_key *key) /* {{{ */ +static int browser_reg_compare(browscap_entry *entry, zend_string *agent_name, browscap_entry **found_entry_ptr) /* {{{ */ { - browscap_entry *entry = Z_PTR_P(entry_zv); - zend_string *agent_name = va_arg(args, zend_string *); - browscap_entry **found_entry_ptr = va_arg(args, browscap_entry **); browscap_entry *found_entry = *found_entry_ptr; ALLOCA_FLAG(use_heap) zend_string *pattern_lc, *regex; @@ -616,7 +612,7 @@ static int browser_reg_compare( if (zend_string_equals(agent_name, pattern_lc)) { *found_entry_ptr = entry; ZSTR_ALLOCA_FREE(pattern_lc, use_heap); - return ZEND_HASH_APPLY_STOP; + return 1; } regex = browscap_convert_pattern(entry->pattern, 0); @@ -749,7 +745,13 @@ PHP_FUNCTION(get_browser) lookup_browser_name = zend_string_tolower(agent_name); found_entry = zend_hash_find_ptr(bdata->htab, lookup_browser_name); if (found_entry == NULL) { - zend_hash_apply_with_arguments(bdata->htab, browser_reg_compare, 2, lookup_browser_name, &found_entry); + browscap_entry *entry; + + ZEND_HASH_FOREACH_PTR(bdata->htab, entry) { + if (browser_reg_compare(entry, lookup_browser_name, &found_entry)) { + break; + } + } ZEND_HASH_FOREACH_END(); if (found_entry == NULL) { found_entry = zend_hash_str_find_ptr(bdata->htab, diff --git a/ext/standard/info.c b/ext/standard/info.c index a51bd01969..1ddd1d80c2 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -164,26 +164,6 @@ PHPAPI void php_info_print_module(zend_module_entry *zend_module) /* {{{ */ } /* }}} */ -static int _display_module_info_func(zval *el) /* {{{ */ -{ - zend_module_entry *module = (zend_module_entry*)Z_PTR_P(el); - if (module->info_func || module->version) { - php_info_print_module(module); - } - return ZEND_HASH_APPLY_KEEP; -} -/* }}} */ - -static int _display_module_info_def(zval *el) /* {{{ */ -{ - zend_module_entry *module = (zend_module_entry*)Z_PTR_P(el); - if (!module->info_func && !module->version) { - php_info_print_module(module); - } - return ZEND_HASH_APPLY_KEEP; -} -/* }}} */ - /* {{{ php_print_gpcse_array */ static void php_print_gpcse_array(char *name, uint32_t name_length) @@ -945,17 +925,26 @@ PHPAPI void php_print_info(int flag) if (flag & PHP_INFO_MODULES) { HashTable sorted_registry; + zend_module_entry *module; zend_hash_init(&sorted_registry, zend_hash_num_elements(&module_registry), NULL, NULL, 1); zend_hash_copy(&sorted_registry, &module_registry, NULL); zend_hash_sort(&sorted_registry, module_name_cmp, 0); - zend_hash_apply(&sorted_registry, _display_module_info_func); + ZEND_HASH_FOREACH_PTR(&sorted_registry, module) { + if (module->info_func || module->version) { + php_info_print_module(module); + } + } ZEND_HASH_FOREACH_END(); SECTION("Additional Modules"); php_info_print_table_start(); php_info_print_table_header(1, "Module Name"); - zend_hash_apply(&sorted_registry, _display_module_info_def); + ZEND_HASH_FOREACH_PTR(&sorted_registry, module) { + if (!module->info_func && !module->version) { + php_info_print_module(module); + } + } ZEND_HASH_FOREACH_END(); php_info_print_table_end(); zend_hash_destroy(&sorted_registry); diff --git a/main/php_ini.c b/main/php_ini.c index 9bf2f6fc53..cc31d1af18 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -115,69 +115,48 @@ static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type) } /* }}} */ -/* {{{ php_ini_displayer - */ -static int php_ini_displayer(zval *el, void *arg) -{ - zend_ini_entry *ini_entry = (zend_ini_entry*)Z_PTR_P(el); - int module_number = *(int *)arg; - - if (ini_entry->module_number != module_number) { - return 0; - } - if (!sapi_module.phpinfo_as_text) { - PUTS("<tr>"); - PUTS("<td class=\"e\">"); - PHPWRITE(ZSTR_VAL(ini_entry->name), ZSTR_LEN(ini_entry->name)); - PUTS("</td><td class=\"v\">"); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); - PUTS("</td><td class=\"v\">"); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); - PUTS("</td></tr>\n"); - } else { - PHPWRITE(ZSTR_VAL(ini_entry->name), ZSTR_LEN(ini_entry->name)); - PUTS(" => "); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); - PUTS(" => "); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); - PUTS("\n"); - } - return 0; -} -/* }}} */ - -/* {{{ php_ini_available - */ -static int php_ini_available(zval *el, void *arg) -{ - zend_ini_entry *ini_entry = (zend_ini_entry *)Z_PTR_P(el); - int *module_number_available = (int *)arg; - if (ini_entry->module_number == *(int *)module_number_available) { - *(int *)module_number_available = -1; - return ZEND_HASH_APPLY_STOP; - } else { - return ZEND_HASH_APPLY_KEEP; - } -} -/* }}} */ - /* {{{ display_ini_entries */ PHPAPI void display_ini_entries(zend_module_entry *module) { - int module_number, module_number_available; + int module_number; + zend_ini_entry *ini_entry; + zend_bool first = 1; if (module) { module_number = module->module_number; } else { module_number = 0; } - module_number_available = module_number; - zend_hash_apply_with_argument(EG(ini_directives), php_ini_available, &module_number_available); - if (module_number_available == -1) { - php_info_print_table_start(); - php_info_print_table_header(3, "Directive", "Local Value", "Master Value"); - zend_hash_apply_with_argument(EG(ini_directives), php_ini_displayer, (void *)&module_number); + + ZEND_HASH_FOREACH_PTR(EG(ini_directives), ini_entry) { + if (ini_entry->module_number != module_number) { + continue; + } + if (first) { + php_info_print_table_start(); + php_info_print_table_header(3, "Directive", "Local Value", "Master Value"); + first = 0; + } + if (!sapi_module.phpinfo_as_text) { + PUTS("<tr>"); + PUTS("<td class=\"e\">"); + PHPWRITE(ZSTR_VAL(ini_entry->name), ZSTR_LEN(ini_entry->name)); + PUTS("</td><td class=\"v\">"); + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); + PUTS("</td><td class=\"v\">"); + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); + PUTS("</td></tr>\n"); + } else { + PHPWRITE(ZSTR_VAL(ini_entry->name), ZSTR_LEN(ini_entry->name)); + PUTS(" => "); + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); + PUTS(" => "); + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); + PUTS("\n"); + } + } ZEND_HASH_FOREACH_END(); + if (!first) { php_info_print_table_end(); } } diff --git a/main/rfc1867.c b/main/rfc1867.c index e1167ebf50..47822a4229 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -190,15 +190,6 @@ static void register_http_post_files_variable_ex(char *var, zval *val, zval *htt } /* }}} */ -static int unlink_filename(zval *el) /* {{{ */ -{ - zend_string *filename = Z_STR_P(el); - VCWD_UNLINK(ZSTR_VAL(filename)); - return 0; -} -/* }}} */ - - static void free_filename(zval *el) { zend_string *filename = Z_STR_P(el); zend_string_release_ex(filename, 0); @@ -206,7 +197,12 @@ static void free_filename(zval *el) { PHPAPI void destroy_uploaded_files_hash(void) /* {{{ */ { - zend_hash_apply(SG(rfc1867_uploaded_files), unlink_filename); + zval *el; + + ZEND_HASH_FOREACH_VAL(SG(rfc1867_uploaded_files), el) { + zend_string *filename = Z_STR_P(el); + VCWD_UNLINK(ZSTR_VAL(filename)); + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(SG(rfc1867_uploaded_files)); FREE_HASHTABLE(SG(rfc1867_uploaded_files)); } diff --git a/main/streams/streams.c b/main/streams/streams.c index df98bdace6..709f96948a 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -91,7 +91,11 @@ fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream); PHP_RSHUTDOWN_FUNCTION(streams) { - zend_hash_apply(&EG(persistent_list), forget_persistent_resource_id_numbers); + zval *el; + + ZEND_HASH_FOREACH_VAL(&EG(persistent_list), el) { + forget_persistent_resource_id_numbers(el); + } ZEND_HASH_FOREACH_END(); return SUCCESS; } diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index a30fa84d91..29f8c1a9b8 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -244,13 +244,6 @@ static void fcgi_log(int type, const char *format, ...) { } #endif -static int print_module_info(zval *element) -{ - zend_module_entry *module = Z_PTR_P(element); - php_printf("%s\n", module->name); - return ZEND_HASH_APPLY_KEEP; -} - static int module_name_cmp(const void *a, const void *b) { Bucket *f = (Bucket *) a; @@ -263,11 +256,14 @@ static int module_name_cmp(const void *a, const void *b) static void print_modules(void) { HashTable sorted_registry; + zend_module_entry *module; zend_hash_init(&sorted_registry, 64, NULL, NULL, 1); zend_hash_copy(&sorted_registry, &module_registry, NULL); zend_hash_sort(&sorted_registry, module_name_cmp, 0); - zend_hash_apply(&sorted_registry, print_module_info); + ZEND_HASH_FOREACH_PTR(&sorted_registry, module) { + php_printf("%s\n", module->name); + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&sorted_registry); } diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 3b053e223a..be0f11e431 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -182,14 +182,6 @@ const opt_struct OPTIONS[] = { {'-', 0, NULL} /* end of args */ }; -static int print_module_info(zval *element) /* {{{ */ -{ - zend_module_entry *module = (zend_module_entry*)Z_PTR_P(element); - php_printf("%s\n", module->name); - return ZEND_HASH_APPLY_KEEP; -} -/* }}} */ - static int module_name_cmp(const void *a, const void *b) /* {{{ */ { Bucket *f = (Bucket *) a; @@ -203,11 +195,14 @@ static int module_name_cmp(const void *a, const void *b) /* {{{ */ static void print_modules(void) /* {{{ */ { HashTable sorted_registry; + zend_module_entry *module; zend_hash_init(&sorted_registry, 50, NULL, NULL, 0); zend_hash_copy(&sorted_registry, &module_registry, NULL); zend_hash_sort(&sorted_registry, module_name_cmp, 0); - zend_hash_apply(&sorted_registry, print_module_info); + ZEND_HASH_FOREACH_PTR(&sorted_registry, module) { + php_printf("%s\n", module->name); + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&sorted_registry); } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index b8b338dd51..e149eeb2ed 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -188,14 +188,6 @@ static php_cgi_globals_struct php_cgi_globals; #define CGIG(v) (php_cgi_globals.v) #endif -static int print_module_info(zval *zv) /* {{{ */ -{ - zend_module_entry *module = Z_PTR_P(zv); - php_printf("%s\n", module->name); - return 0; -} -/* }}} */ - static int module_name_cmp(const void *a, const void *b) /* {{{ */ { Bucket *f = (Bucket *) a; @@ -209,11 +201,14 @@ static int module_name_cmp(const void *a, const void *b) /* {{{ */ static void print_modules(void) /* {{{ */ { HashTable sorted_registry; + zend_module_entry *module; zend_hash_init(&sorted_registry, 50, NULL, NULL, 1); zend_hash_copy(&sorted_registry, &module_registry, NULL); zend_hash_sort(&sorted_registry, module_name_cmp, 0); - zend_hash_apply(&sorted_registry, print_module_info); + ZEND_HASH_FOREACH_PTR(&sorted_registry, module) { + php_printf("%s\n", module->name); + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&sorted_registry); } /* }}} */ |