]> granicus.if.org Git - php/commitdiff
Replace zend_hash_apply... with ZEND_HASH_FOREACH...
authorDmitry Stogov <dmitry@zend.com>
Tue, 18 Dec 2018 23:49:56 +0000 (02:49 +0300)
committerDmitry Stogov <dmitry@zend.com>
Tue, 18 Dec 2018 23:49:56 +0000 (02:49 +0300)
16 files changed:
Zend/zend_API.c
Zend/zend_builtin_functions.c
Zend/zend_inheritance.c
Zend/zend_ini.c
Zend/zend_list.c
ext/opcache/zend_persist.c
ext/spl/php_spl.c
ext/standard/basic_functions.c
ext/standard/browscap.c
ext/standard/info.c
main/php_ini.c
main/rfc1867.c
main/streams/streams.c
sapi/cgi/cgi_main.c
sapi/cli/php_cli.c
sapi/fpm/fpm/fpm_main.c

index d1cb145c50d12061826446ff8ea7783f5fd706b9..51e477b2ef1f21afc9a3efc07cf2aeaf1be8df83 100644 (file)
@@ -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;
 
index c020c98b20793eb6e5fa655194bb636bf302e5b2..3fce84d6a47d21e73ecd6e2a6b686ad5e76d1b82 100644 (file)
@@ -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();
        }
 }
 /* }}} */
index b116a7fbee71f7b127fb7f38834a480f73cef388..387c1ca4d781037383eb7eb62262336a9bc47789 100644 (file)
@@ -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;
 }
 /* }}} */
 
index 6ae963f3b7faf891a8b7e7f0210dd5ff81c2d0ad..07af7b223c7030c035f34608d58ad30f02cb1587 100644 (file)
@@ -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
index cf878ef4302cfe3a1343bf7e0fbd5f309df7f84e..cd6b6073a956c8bf2d51b1bd6f2b2c5d753b0caf 100644 (file)
@@ -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();
 }
 
 
index 9ab4cd6d33b648503fa22290caa70d217b6e0a49..b66d83e05cb68b6013a8557798b6de93b03da358 100644 (file)
@@ -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)
index c80adaed9440481354059570380871e8c5853eda..da520d62e011d567f9cf60897ce1aa939f31af5e 100644 (file)
@@ -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);
index 68aa7e1ef3de7c03e4a6fccc462228ee6ec297a2..9026cacc7967eca6583a734194790e506637ae7f 100644 (file)
@@ -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
index 8a2272fe00f6aa6b9d95c4853ad1156d87b5c9a5..cb6b98fe7bb95304872f3b49d210e688eb19fcef 100644 (file)
@@ -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,
index a51bd01969a1a937e87314e817c1e3022237b398..1ddd1d80c2cef9be5c28fb04f13ef32fe55e94ff 100644 (file)
@@ -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);
index 9bf2f6fc53722570962d94ace164b2c2412d4f69..cc31d1af189db57c41376446dcc160b9982e480a 100644 (file)
@@ -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();
        }
 }
index e1167ebf50948cb18c02c3c543b255128ce89ff7..47822a4229d629a0286f70a88a8adbf77859edd2 100644 (file)
@@ -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));
 }
index df98bdace68d10784a858d04894bfe6e189772a9..709f96948a8358e398c0576101491bcca503833f 100644 (file)
@@ -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;
 }
 
index a30fa84d916b8f10cf0a2915305ba84f631e475d..29f8c1a9b8c80122f024ee4940ea88adce7a5f75 100644 (file)
@@ -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);
 }
 
index 3b053e223ab76ee9c9dccb4f8747e5631f2b29ce..be0f11e43167ac0e4501d27488eb7b588e1c5a02 100644 (file)
@@ -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);
 }
 /* }}} */
index b8b338dd51c6784e1e94b4fd2135d8ec317e7cb4..e149eeb2ed7d403a869698c424e09c2c5004dcd7 100644 (file)
@@ -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);
 }
 /* }}} */