]> granicus.if.org Git - php/commitdiff
Remove autoload_running flag
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 10 Jun 2020 07:41:58 +0000 (09:41 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 10 Jun 2020 07:41:58 +0000 (09:41 +0200)
This was only used to decide between a hash clean and a hash
destroyed in spl_autoload_remove(). But now that
spl_autoload_functions() no longer distinguishes between NULL and
an empty array here, there's really no need to try and destroy
the hashtable here.

ext/spl/php_spl.c
ext/spl/php_spl.h

index e38a15582fbabd0d50fd43a2e060a7706ff79c8e..f55e337ab2df01089444435aa1b1f9960e6410a8 100644 (file)
@@ -53,7 +53,6 @@ static PHP_GINIT_FUNCTION(spl)
 {
        spl_globals->autoload_extensions = NULL;
        spl_globals->autoload_functions = NULL;
-       spl_globals->autoload_running = 0;
 }
 /* }}} */
 
@@ -405,9 +404,6 @@ static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_stri
        zval retval;
        zend_string *func_name;
        zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
-       int l_autoload_running = SPL_G(autoload_running);
-
-       SPL_G(autoload_running) = 1;
 
        fci.size = sizeof(fci);
        fci.retval = &retval;
@@ -418,6 +414,8 @@ static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_stri
 
        ZVAL_UNDEF(&fci.function_name); /* Unused */
 
+       /* We don't use ZEND_HASH_FOREACH here,
+        * because autoloaders may be added/removed during autoloading. */
        zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &pos);
        while (zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &num_idx, &pos) == HASH_KEY_IS_STRING) {
                autoload_func_info *alfi =
@@ -455,13 +453,11 @@ static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_stri
 
                zend_class_entry *ce = zend_hash_find_ptr(EG(class_table), lc_name);
                if (ce) {
-                       SPL_G(autoload_running) = l_autoload_running;
                        return ce;
                }
 
                zend_hash_move_forward_ex(SPL_G(autoload_functions), &pos);
        }
-       SPL_G(autoload_running) = l_autoload_running;
        return NULL;
 }
 
@@ -661,14 +657,8 @@ PHP_FUNCTION(spl_autoload_unregister)
 
        if (SPL_G(autoload_functions)) {
                if (zend_string_equals_literal(lc_name, "spl_autoload_call")) {
-                       /* remove all */
-                       if (!SPL_G(autoload_running)) {
-                               zend_hash_destroy(SPL_G(autoload_functions));
-                               FREE_HASHTABLE(SPL_G(autoload_functions));
-                               SPL_G(autoload_functions) = NULL;
-                       } else {
-                               zend_hash_clean(SPL_G(autoload_functions));
-                       }
+                       /* Don't destroy the hash table, as we might be iterating over it right now. */
+                       zend_hash_clean(SPL_G(autoload_functions));
                        success = SUCCESS;
                } else {
                        /* remove specific */
index a4aaba46903f4ab22dc9baa54bddd725cc6de95c..aebf23ed390cd931252a806cfb6eca2be74137ff 100644 (file)
@@ -57,7 +57,6 @@ ZEND_BEGIN_MODULE_GLOBALS(spl)
        intptr_t     hash_mask_handle;
        intptr_t     hash_mask_handlers;
        int          hash_mask_init;
-       int          autoload_running;
 ZEND_END_MODULE_GLOBALS(spl)
 
 ZEND_EXTERN_MODULE_GLOBALS(spl)