Skip to content

Commit e0e4a61

Browse files
committed
Remove autoload_running flag
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.
1 parent 5b59d49 commit e0e4a61

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

ext/spl/php_spl.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ static PHP_GINIT_FUNCTION(spl)
5353
{
5454
spl_globals->autoload_extensions = NULL;
5555
spl_globals->autoload_functions = NULL;
56-
spl_globals->autoload_running = 0;
5756
}
5857
/* }}} */
5958

@@ -405,9 +404,6 @@ static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_stri
405404
zval retval;
406405
zend_string *func_name;
407406
zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
408-
int l_autoload_running = SPL_G(autoload_running);
409-
410-
SPL_G(autoload_running) = 1;
411407

412408
fci.size = sizeof(fci);
413409
fci.retval = &retval;
@@ -418,6 +414,8 @@ static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_stri
418414

419415
ZVAL_UNDEF(&fci.function_name); /* Unused */
420416

417+
/* We don't use ZEND_HASH_FOREACH here,
418+
* because autoloaders may be added/removed during autoloading. */
421419
zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &pos);
422420
while (zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &num_idx, &pos) == HASH_KEY_IS_STRING) {
423421
autoload_func_info *alfi =
@@ -455,13 +453,11 @@ static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_stri
455453

456454
zend_class_entry *ce = zend_hash_find_ptr(EG(class_table), lc_name);
457455
if (ce) {
458-
SPL_G(autoload_running) = l_autoload_running;
459456
return ce;
460457
}
461458

462459
zend_hash_move_forward_ex(SPL_G(autoload_functions), &pos);
463460
}
464-
SPL_G(autoload_running) = l_autoload_running;
465461
return NULL;
466462
}
467463

@@ -661,14 +657,8 @@ PHP_FUNCTION(spl_autoload_unregister)
661657

662658
if (SPL_G(autoload_functions)) {
663659
if (zend_string_equals_literal(lc_name, "spl_autoload_call")) {
664-
/* remove all */
665-
if (!SPL_G(autoload_running)) {
666-
zend_hash_destroy(SPL_G(autoload_functions));
667-
FREE_HASHTABLE(SPL_G(autoload_functions));
668-
SPL_G(autoload_functions) = NULL;
669-
} else {
670-
zend_hash_clean(SPL_G(autoload_functions));
671-
}
660+
/* Don't destroy the hash table, as we might be iterating over it right now. */
661+
zend_hash_clean(SPL_G(autoload_functions));
672662
success = SUCCESS;
673663
} else {
674664
/* remove specific */

ext/spl/php_spl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ ZEND_BEGIN_MODULE_GLOBALS(spl)
5757
intptr_t hash_mask_handle;
5858
intptr_t hash_mask_handlers;
5959
int hash_mask_init;
60-
int autoload_running;
6160
ZEND_END_MODULE_GLOBALS(spl)
6261

6362
ZEND_EXTERN_MODULE_GLOBALS(spl)

0 commit comments

Comments
 (0)