Permalink
Browse files

Improved PHP extension loading mechanism with support for module depe…

…ndencies and conflicts
  • Loading branch information...
Dmitry Stogov
Dmitry Stogov committed Jun 17, 2005
1 parent c0c7a9f commit f47c78487bda814ccb1de09fe44fe9a6b4082c30
View
@@ -1,6 +1,6 @@
#! /bin/sh
-# $Id: genif.sh,v 1.4 2004-07-18 12:03:51 wez Exp $
+# $Id: genif.sh,v 1.5 2005-06-17 09:39:20 dmitry Exp $
# replacement for genif.pl
infile=$1
@@ -17,13 +17,13 @@ if test -z "$infile" || test -z "$srcdir"; then
exit 1
fi
+module_ptrs=$extra_module_ptrs
header_list=
olddir=`pwd`
cd $srcdir
-module_ptrs="$extra_module_ptrs`echo $@ | $awk -f ./build/order_by_dep.awk`"
-
for ext in ${1+"$@"} ; do
+ module_ptrs=" phpext_${ext}_ptr,@NEWLINE@$module_ptrs"
header_list="$header_list ext/$ext/*.h"
done
View
@@ -404,8 +404,18 @@ static zend_object_handlers* dom_get_obj_handlers(TSRMLS_D) {
}
}
+static zend_module_dep dom_deps[] = {
+ ZEND_MOD_REQUIRED("libxml")
+ ZEND_MOD_CONFLICTS("domxml")
+#ifdef HAVE_SIMPLEXML
+ ZEND_MOD_REQUIRED("simplexml")
+#endif
+ {NULL, NULL, NULL}
+};
+
zend_module_entry dom_module_entry = {
- STANDARD_MODULE_HEADER,
+ STANDARD_MODULE_HEADER_EX, NULL,
+ dom_deps,
"dom",
dom_functions,
PHP_MINIT(dom),
View
@@ -86,9 +86,20 @@ function_entry pdo_functions[] = {
};
/* }}} */
+/* {{{ pdo_functions[] */
+static zend_module_dep pdo_deps[] = {
+#ifdef HAVE_SPL
+ ZEND_MOD_REQUIRED("spl")
+#endif
+ {NULL, NULL, NULL}
+};
+
+/* }}} */
+
/* {{{ pdo_module_entry */
zend_module_entry pdo_module_entry = {
- STANDARD_MODULE_HEADER,
+ STANDARD_MODULE_HEADER_EX, NULL,
+ pdo_deps,
"PDO",
pdo_functions,
PHP_MINIT(pdo),
View
@@ -36,9 +36,17 @@ function_entry pdo_mysql_functions[] = {
};
/* }}} */
+/* {{{ pdo_mysql_functions[] */
+static zend_module_dep pdo_mysql_deps[] = {
+ ZEND_MOD_REQUIRED("pdo")
+ {NULL, NULL, NULL}
+};
+/* }}} */
+
/* {{{ pdo_mysql_module_entry */
zend_module_entry pdo_mysql_module_entry = {
- STANDARD_MODULE_HEADER,
+ STANDARD_MODULE_HEADER_EX, NULL,
+ pdo_mysql_deps,
"pdo_mysql",
pdo_mysql_functions,
PHP_MINIT(pdo_mysql),
@@ -39,10 +39,19 @@ function_entry pdo_sqlite_functions[] = {
};
/* }}} */
+/* {{{ pdo_sqlite_deps
+ */
+static zend_module_dep pdo_sqlite_deps[] = {
+ ZEND_MOD_REQUIRED("pdo")
+ {NULL, NULL, NULL}
+};
+/* }}} */
+
/* {{{ pdo_sqlite_module_entry
*/
zend_module_entry pdo_sqlite_module_entry = {
- STANDARD_MODULE_HEADER,
+ STANDARD_MODULE_HEADER_EX, NULL,
+ pdo_sqlite_deps,
"pdo_sqlite",
pdo_sqlite_functions,
PHP_MINIT(pdo_sqlite),
View
@@ -267,8 +267,25 @@ function_entry sqlite_funcs_exception[] = {
{NULL, NULL, NULL}
};
+/* Dependancies */
+static zend_module_dep sqlite_deps[] = {
+#if defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1))
+ ZEND_MOD_REQUIRED("spl")
+#endif
+#if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
+ ZEND_MOD_REQUIRED("session")
+#endif
+#if PHP_SQLITE2_HAVE_PDO
+ ZEND_MOD_REQUIRED("pdo")
+#endif
+ {NULL, NULL, NULL}
+};
+
zend_module_entry sqlite_module_entry = {
-#if ZEND_MODULE_API_NO >= 20010901
+#if ZEND_MODULE_API_NO >= 20050608
+ STANDARD_MODULE_HEADER_EX, NULL,
+ sqlite_deps,
+#elif ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"SQLite",
View
@@ -54,7 +54,7 @@
Load a PHP extension at runtime */
PHP_FUNCTION(dl)
{
- pval **file;
+ zval **file;
/* obtain arguments */
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
@@ -99,7 +99,7 @@ PHP_FUNCTION(dl)
/* {{{ php_dl
*/
-void php_dl(pval *file, int type, pval *return_value TSRMLS_DC)
+void php_dl(zval *file, int type, zval *return_value TSRMLS_DC)
{
void *handle;
char *libpath;
@@ -224,14 +224,18 @@ void php_dl(pval *file, int type, pval *return_value TSRMLS_DC)
RETURN_FALSE;
}
+ if (type == MODULE_TEMPORARY && zend_startup_module(module_entry TSRMLS_CC) == FAILURE) {
+ DL_UNLOAD(handle);
+ RETURN_FALSE;
+ }
+
if ((type == MODULE_TEMPORARY) && module_entry->request_startup_func) {
- if (module_entry->request_startup_func(type, module_entry->module_number TSRMLS_CC)) {
+ if (module_entry->request_startup_func(type, module_entry->module_number TSRMLS_CC) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, error_type, "Unable to initialize module '%s'", module_entry->name);
DL_UNLOAD(handle);
RETURN_FALSE;
}
}
-
RETURN_TRUE;
}
/* }}} */
@@ -243,7 +247,7 @@ PHP_MINFO_FUNCTION(dl)
#else
-void php_dl(pval *file, int type, pval *return_value TSRMLS_DC)
+void php_dl(zval *file, int type, zval *return_value TSRMLS_DC)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot dynamically load %s - dynamic modules are not supported", Z_STRVAL_P(file));
RETURN_FALSE;
View
@@ -23,8 +23,7 @@
#ifndef DL_H
#define DL_H
-PHPAPI void php_dl(pval *file,int type,pval *return_value TSRMLS_DC);
-
+PHPAPI void php_dl(zval *file,int type, zval *return_value TSRMLS_DC);
/* dynamic loading functions */
PHP_FUNCTION(dl);
@@ -36,9 +36,9 @@ zend_module_entry *php_builtin_extensions[] = {
#define EXTCOUNT (sizeof(php_builtin_extensions)/sizeof(zend_module_entry *))
-int php_startup_internal_extensions(void)
+int php_register_internal_extensions(TSRMLS_D)
{
- return php_startup_extensions(php_builtin_extensions, EXTCOUNT);
+ return php_register_extensions(php_builtin_extensions, EXTCOUNT TSRMLS_CC);
}
/*
@@ -85,9 +85,9 @@ zend_module_entry *php_builtin_extensions[] = {
#define EXTCOUNT (sizeof(php_builtin_extensions)/sizeof(zend_module_entry *))
-int php_startup_internal_extensions(void)
+int php_register_internal_extensions(TSRMLS_D)
{
- return php_startup_extensions(php_builtin_extensions, EXTCOUNT);
+ return php_register_extensions(php_builtin_extensions, EXTCOUNT TSRMLS_CC);
}
@@ -158,9 +158,9 @@ zend_module_entry *php_builtin_extensions[] = {
#define EXTCOUNT (sizeof(php_builtin_extensions)/sizeof(zend_module_entry *))
-int php_startup_internal_extensions(void)
+int php_register_internal_extensions(TSRMLS_D)
{
- return php_startup_extensions(php_builtin_extensions, EXTCOUNT);
+ return php_register_extensions(php_builtin_extensions, EXTCOUNT TSRMLS_CC);
}
/*
View
@@ -1287,15 +1287,15 @@ static void core_globals_ctor(php_core_globals *core_globals TSRMLS_DC)
/* }}} */
#endif
-/* {{{ php_startup_extensions
+/* {{{ php_register_extensions
*/
-int php_startup_extensions(zend_module_entry **ptr, int count)
+int php_register_extensions(zend_module_entry **ptr, int count TSRMLS_DC)
{
- zend_module_entry **end = ptr+count;
+ zend_module_entry **end = ptr + count;
while (ptr < end) {
if (*ptr) {
- if (zend_startup_module(*ptr)==FAILURE) {
+ if (zend_register_internal_module(*ptr TSRMLS_CC)==FAILURE) {
return FAILURE;
}
}
@@ -1480,13 +1480,13 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
zend_register_default_classes(TSRMLS_C);
/* startup extensions staticly compiled in */
- if (php_startup_internal_extensions() == FAILURE) {
+ if (php_register_internal_extensions(TSRMLS_C) == FAILURE) {
php_printf("Unable to start builtin modules\n");
return FAILURE;
}
/* start additional PHP extensions */
- php_startup_extensions(&additional_modules, num_additional_modules);
+ php_register_extensions(&additional_modules, num_additional_modules TSRMLS_CC);
/* load and startup extensions compiled as shared objects (aka DLLs)
@@ -1496,7 +1496,8 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
which is always an internal extension and to be initialized
ahead of all other internals
*/
- php_ini_delayed_modules_startup(TSRMLS_C);
+ php_ini_register_extensions(TSRMLS_C);
+ zend_startup_modules(TSRMLS_C);
/* disable certain classes and functions as requested by php.ini */
php_disable_functions(TSRMLS_C);
View
@@ -319,7 +319,7 @@ END_EXTERN_C()
/* functions */
BEGIN_EXTERN_C()
-int php_startup_internal_extensions(void);
+int php_register_internal_extensions(TSRMLS_D);
int php_mergesort(void *base, size_t nmemb, register size_t size, int (*cmp)(const void *, const void * TSRMLS_DC) TSRMLS_DC);
View
@@ -544,9 +544,9 @@ int php_shutdown_config(void)
}
/* }}} */
-/* {{{ php_ini_delayed_modules_startup
+/* {{{ php_ini_register_extensions
*/
-void php_ini_delayed_modules_startup(TSRMLS_D)
+void php_ini_register_extensions(TSRMLS_D)
{
zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb TSRMLS_CC);
zend_llist_apply(&extension_lists.functions, php_load_function_extension_cb TSRMLS_CC);
View
@@ -26,7 +26,7 @@
BEGIN_EXTERN_C()
int php_init_config();
int php_shutdown_config(void);
-void php_ini_delayed_modules_startup(TSRMLS_D);
+void php_ini_register_extensions(TSRMLS_D);
zval *cfg_get_entry(char *name, uint name_length);
END_EXTERN_C()
View
@@ -36,7 +36,7 @@ PHPAPI void php_module_shutdown_for_exec(void);
PHPAPI int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals);
PHPAPI int php_request_startup_for_hook(TSRMLS_D);
-PHPAPI int php_startup_extensions(zend_module_entry **ptr, int count);
+PHPAPI int php_register_extensions(zend_module_entry **ptr, int count TSRMLS_DC);
PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC);
PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret TSRMLS_DC);

0 comments on commit f47c784

Please sign in to comment.