Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Recode delayed loading in a much simpler way (switched back to php_in…

…i.c 1.49)
  • Loading branch information...
commit 9db55891619a41ab82b5f2a3c44adac9927bf66d 1 parent 3b8140e
Zeev Suraski zsuraski authored
Showing with 41 additions and 69 deletions.
  1. +1 −4 main/main.c
  2. +39 −64 main/php_ini.c
  3. +1 −1  main/php_ini.h
5 main/main.c
View
@@ -870,10 +870,7 @@ int php_module_startup(sapi_module_struct *sf)
which is always an internal extension and to be initialized
ahead of all other internals
*/
- if (php_startup_loaded_extensions() == FAILURE) {
- php_printf("Unable to start loaded modules\n");
- return FAILURE;
- }
+ php_ini_delayed_modules_startup();
/* disable certain functions as requested by php.ini */
php_disable_functions();
103 main/php_ini.c
View
@@ -1,18 +1,18 @@
/*
+----------------------------------------------------------------------+
- | PHP version 4.0 |
+ | PHP version 4.0 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
+ | Copyright (c) 1997-2001 The PHP Group |
+----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
| If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
- | Author: Zeev Suraski <zeev@zend.com> |
+ | Author: Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
@@ -24,15 +24,19 @@
#include "ext/standard/dl.h"
#include "zend_extensions.h"
-/* True globals */
-static HashTable configuration_hash;
-PHPAPI char *php_ini_opened_path=NULL;
typedef struct _php_extension_lists {
zend_llist engine;
zend_llist functions;
} php_extension_lists;
+
+/* True globals */
+static HashTable configuration_hash;
+PHPAPI char *php_ini_opened_path=NULL;
+static php_extension_lists extension_lists;
+
+
static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type)
{
if (ini_entry->displayer) {
@@ -121,9 +125,8 @@ static void pvalue_config_destructor(zval *pvalue)
}
}
-static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, void *arg_list)
+static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, void *arg)
{
- php_extension_lists *extension_lists =(php_extension_lists * )arg_list;
switch (callback_type) {
case ZEND_INI_PARSER_ENTRY: {
zval *entry;
@@ -132,12 +135,16 @@ static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
break;
}
if (!strcasecmp(Z_STRVAL_P(arg1), "extension")) { /* load function module */
- char *extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
- zend_llist_add_element(&extension_lists->functions, &extension_name);
+ zval copy;
+
+ copy = *arg2;
+ zval_copy_ctor(&copy);
+ copy.refcount = 0;
+ zend_llist_add_element(&extension_lists.functions, &copy);
} else if (!strcasecmp(Z_STRVAL_P(arg1), ZEND_EXTENSION_TOKEN)) { /* load Zend extension */
char *extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
- zend_llist_add_element(&extension_lists->engine, &extension_name);
+ zend_llist_add_element(&extension_lists.engine, &extension_name);
} else {
zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, arg2, sizeof(zval), (void **) &entry);
Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry));
@@ -150,35 +157,12 @@ static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
}
-static zend_llist *php_load_extension_list = NULL;
-
-static void php_startup_loaded_extension_cb(void *arg){
- zval *extension, ret;
-
- MAKE_STD_ZVAL(extension);
- ZVAL_STRING(extension,*((char **) arg),0);
- php_dl(extension, MODULE_PERSISTENT, &ret);
- FREE_ZVAL(extension);
-}
-
-int php_startup_loaded_extensions(void)
-{
- if(php_load_extension_list) {
- zend_llist_apply(php_load_extension_list, php_startup_loaded_extension_cb);
- }
- return SUCCESS;
-}
-
static void php_load_function_extension_cb(void *arg)
{
- char *extension = estrdup(*((char **)arg));
+ zval *extension = (zval *) arg;
+ zval zval;
- if(! php_load_extension_list) {
- php_load_extension_list=(zend_llist*)malloc(sizeof(zend_llist));
- zend_llist_init(php_load_extension_list, sizeof(char **), (void(*)(void *))free_estring, 1);
- }
-
- zend_llist_add_element(php_load_extension_list, &extension);
+ php_dl(extension, MODULE_PERSISTENT, &zval);
}
@@ -195,24 +179,14 @@ int php_init_config(char *php_ini_path_override)
char *open_basedir;
int free_ini_search_path=0;
zend_file_handle fh;
- php_extension_lists extension_lists;
PLS_FETCH();
if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) {
return FAILURE;
}
- /* some extensions may be configured by ini entries
- if we would load them right away upon finding an extension
- entry we would have to use the config cache directly as
- the ini mechanism is not finaly initialized yet and we
- would introduce a order dependency in the ini file.
- to avoid this we temporarily store the extensions to
- be loaded in linked lists and process theese immediately
- *after* we have finished setting up the ini mechanism
- */
- zend_llist_init(&extension_lists.engine , sizeof(char **), (void(*)(void *))free_estring, 1);
- zend_llist_init(&extension_lists.functions, sizeof(char **), (void(*)(void *))free_estring, 1);
+ zend_llist_init(&extension_lists.engine, sizeof(zval), free_estring, 1);
+ zend_llist_init(&extension_lists.functions, sizeof(zval), ZVAL_DESTRUCTOR, 1);
safe_mode_state = PG(safe_mode);
open_basedir = PG(open_basedir);
@@ -268,15 +242,6 @@ int php_init_config(char *php_ini_path_override)
fh.filename = php_ini_opened_path;
zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
-
- /* now that we are done with the configuration settings
- we can load all requested extensions
- */
- zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb);
- zend_llist_apply(&extension_lists.functions, php_load_function_extension_cb);
-
- zend_llist_destroy(&extension_lists.engine);
- zend_llist_destroy(&extension_lists.functions);
if (php_ini_opened_path) {
zval tmp;
@@ -302,6 +267,16 @@ int php_shutdown_config(void)
}
+void php_ini_delayed_modules_startup(void)
+{
+ zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb);
+ zend_llist_apply(&extension_lists.functions, php_load_function_extension_cb);
+
+ zend_llist_destroy(&extension_lists.engine);
+ zend_llist_destroy(&extension_lists.functions);
+}
+
+
zval *cfg_get_entry(char *name, uint name_length)
{
zval *tmp;
2  main/php_ini.h
View
@@ -23,7 +23,7 @@
int php_init_config(char *php_ini_path_override);
int php_shutdown_config(void);
-int php_startup_loaded_extensions(void);
+void php_ini_delayed_modules_startup(void);
zval *cfg_get_entry(char *name, uint name_length);
#define PHP_INI_USER ZEND_INI_USER
Please sign in to comment.
Something went wrong with that request. Please try again.