From: Marcus Boerger Date: Sat, 1 May 2004 20:34:15 +0000 (+0000) Subject: Don't load modules twice X-Git-Tag: RELEASE_0_1~312 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f571b188f9ac3159c54f7edf04c4848e587c8a55;p=php Don't load modules twice --- diff --git a/Zend/zend_API.c b/Zend/zend_API.c index a2bbf4c32c..f1fc7f8758 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1161,10 +1161,20 @@ ZEND_API int add_property_zval_ex(zval *arg, char *key, uint key_len, zval *valu ZEND_API int zend_startup_module(zend_module_entry *module) { if (module) { + int name_len; + char *lcname; + TSRMLS_FETCH(); + + name_len = strlen(module->name); + lcname = zend_str_tolower_dup(module->name, name_len); + if (zend_hash_exists(&module_registry, lcname, name_len+1)) { + efree(lcname); + zend_error(E_CORE_WARNING, "Module '%s' already loaded", module->name); + return FAILURE; + } + efree(lcname); module->module_number = zend_next_free_module(); if (module->module_startup_func) { - TSRMLS_FETCH(); - EG(current_module) = module; if (module->module_startup_func(MODULE_PERSISTENT, module->module_number TSRMLS_CC)==FAILURE) { zend_error(E_CORE_ERROR,"Unable to start %s module", module->name); @@ -1360,17 +1370,26 @@ ZEND_API int zend_register_module(zend_module_entry *module) int retval, name_len; char *lcname; TSRMLS_FETCH(); - + #if 0 zend_printf("%s: Registering module %d\n", module->name, module->module_number); #endif + name_len = strlen(module->name); + lcname = zend_str_tolower_dup(module->name, name_len); + + if (zend_hash_exists(&module_registry, lcname, name_len+1)) { + efree(lcname); + zend_error(E_CORE_WARNING, "Module '%s' already loaded", module->name); + return FAILURE; + } + if (module->functions && zend_register_functions(NULL, module->functions, NULL, module->type TSRMLS_CC)==FAILURE) { zend_error(E_CORE_WARNING,"%s: Unable to register functions, unable to load", module->name); + efree(lcname); return FAILURE; } module->module_started=1; - name_len = strlen(module->name); - lcname = zend_str_tolower_dup(module->name, name_len); + retval = zend_hash_add(&module_registry, lcname, name_len+1, (void *)module, sizeof(zend_module_entry), NULL); efree(lcname); return retval; diff --git a/ext/standard/dl.c b/ext/standard/dl.c index 6d810913ee..bbb0d69030 100644 --- a/ext/standard/dl.c +++ b/ext/standard/dl.c @@ -108,6 +108,8 @@ void php_dl(pval *file, int type, pval *return_value TSRMLS_DC) zend_module_entry *(*get_module)(void); int error_type; char *extension_dir; + int name_len; + char *lcname; if (type==MODULE_PERSISTENT) { /* Use the configuration hash directly, the INI mechanism is not yet initialized */ @@ -234,6 +236,15 @@ void php_dl(pval *file, int type, pval *return_value TSRMLS_DC) DL_UNLOAD(handle); RETURN_FALSE; } + name_len = strlen(module_entry->name); + lcname = zend_str_tolower_dup(module_entry->name, name_len); + if (zend_hash_exists(&module_registry, lcname, name_len+1)) { + efree(lcname); + php_error_docref(NULL TSRMLS_CC, error_type, "Module '%s' already loaded", module_entry->name); + DL_UNLOAD(handle); + RETURN_FALSE; + } + efree(lcname); Z_TYPE_P(module_entry) = type; module_entry->module_number = zend_next_free_module(); if (module_entry->module_startup_func) {