]> granicus.if.org Git - php/commitdiff
Don't load modules twice
authorMarcus Boerger <helly@php.net>
Sat, 1 May 2004 20:34:15 +0000 (20:34 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 1 May 2004 20:34:15 +0000 (20:34 +0000)
Zend/zend_API.c
ext/standard/dl.c

index a2bbf4c32cd7b3307c172174e026ecb19ae92951..f1fc7f87585807b247d15196fa773387b8a54849 100644 (file)
@@ -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;
index 6d810913eee835e5ce4759eb0e557375bdccb62c..bbb0d69030c09dc35a263fdbc4ff2d636033d62b 100644 (file)
@@ -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) {