1
0
Fork 0

refactor: bring back compatibility with Zend Optimizer

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1045 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 2012-07-25 09:32:11 +00:00
parent 12e8dc053e
commit 86e370ebd2
6 changed files with 76 additions and 47 deletions

View File

@ -3253,7 +3253,7 @@ static PHP_MINIT_FUNCTION(xcache_cacher) /* {{{ */
REGISTER_INI_ENTRIES();
xc_sandbox_module_init(module_number TSRMLS_CC);
return xcache_zend_extension_register(&xc_cacher_zend_extension_entry, 0);
return xcache_zend_extension_prepend(&xc_cacher_zend_extension_entry);
err_init:
return FAILURE;
@ -3263,7 +3263,7 @@ static PHP_MSHUTDOWN_FUNCTION(xcache_cacher) /* {{{ */
{
xc_sandbox_module_shutdown();
xcache_zend_extension_unregister(&xc_cacher_zend_extension_entry);
xcache_zend_extension_remove(&xc_cacher_zend_extension_entry);
UNREGISTER_INI_ENTRIES();
if (xc_mmap_path) {

View File

@ -670,7 +670,7 @@ static PHP_MINIT_FUNCTION(xcache_coverager) /* {{{ */
}
}
return xcache_zend_extension_register(&xc_coverager_zend_extension_entry, 0);
return xcache_zend_extension_prepend(&xc_coverager_zend_extension_entry);
}
/* }}} */
static PHP_MSHUTDOWN_FUNCTION(xcache_coverager) /* {{{ */
@ -684,7 +684,7 @@ static PHP_MSHUTDOWN_FUNCTION(xcache_coverager) /* {{{ */
xc_coveragedump_dir = NULL;
}
UNREGISTER_INI_ENTRIES();
return xcache_zend_extension_unregister(&xc_coverager_zend_extension_entry);
return xcache_zend_extension_remove(&xc_coverager_zend_extension_entry);
}
/* }}} */

View File

@ -666,13 +666,13 @@ static PHP_MINFO_FUNCTION(xcache_optimizer) /* {{{ */
static PHP_MINIT_FUNCTION(xcache_optimizer) /* {{{ */
{
REGISTER_INI_ENTRIES();
return xcache_zend_extension_register(&xc_optimizer_zend_extension_entry, 0);
return xcache_zend_extension_prepend(&xc_optimizer_zend_extension_entry);
}
/* }}} */
static PHP_MSHUTDOWN_FUNCTION(xcache_optimizer) /* {{{ */
{
UNREGISTER_INI_ENTRIES();
return xcache_zend_extension_unregister(&xc_optimizer_zend_extension_entry);
return xcache_zend_extension_remove(&xc_optimizer_zend_extension_entry);
}
/* }}} */
static zend_module_entry xcache_optimizer_module_entry = { /* {{{ */

View File

@ -38,7 +38,6 @@ static char *xc_coredump_dir = NULL;
static zend_bool xc_disable_on_crash = 0;
static zend_compile_file_t *old_compile_file = NULL;
static zend_llist_element *xc_llist_zend_extension = NULL;
zend_bool xc_test = 0;
@ -543,7 +542,8 @@ static void xcache_signal_handler(int sig) /* {{{ */
/* }}} */
#endif
static startup_func_t xc_last_ext_startup;
static startup_func_t xc_last_ext_old_startup;
static xc_stack_t xc_llist_zend_extensions; /* (zend_extension *) */
static int xc_zend_startup_last_hook(zend_extension *extension) /* {{{ */
{
zend_extension *ext = zend_get_extension(XCACHE_NAME);
@ -551,14 +551,21 @@ static int xc_zend_startup_last_hook(zend_extension *extension) /* {{{ */
zend_error(E_WARNING, "Module '" XCACHE_NAME "' already loaded");
}
/* restore */
extension->startup = xc_last_ext_startup;
extension->startup = xc_last_ext_old_startup;
extension->startup = xc_last_ext_old_startup;
xc_last_ext_old_startup = NULL;
if (extension->startup) {
if (extension->startup(extension) != SUCCESS) {
return FAILURE;
}
}
assert(xc_llist_zend_extension);
xcache_llist_prepend(&zend_extensions, xc_llist_zend_extension);
assert(xc_stack_count(&xc_llist_zend_extensions));
while (xc_stack_count(&xc_llist_zend_extensions)) {
zend_llist_element *p = (zend_llist_element *) xc_stack_pop(&xc_llist_zend_extensions);
xcache_llist_prepend(&zend_extensions, p);
}
xc_stack_destroy(&xc_llist_zend_extensions);
return SUCCESS;
}
/* }}} */
@ -567,22 +574,22 @@ static int xc_zend_startup(zend_extension *extension) /* {{{ */
old_compile_file = zend_compile_file;
zend_compile_file = xc_check_initial_compile_file;
if (zend_llist_count(&zend_extensions) > 1) {
if (1 || xcache_zend_extension_count_by_prefix(&zend_extensions, XCACHE_NAME) != zend_llist_count(&zend_extensions)) {
zend_llist_position lpos;
zend_extension *ext;
zend_extension *ext = (zend_extension *) zend_extensions.head->data;
assert(ext);
xc_llist_zend_extension = xcache_llist_get_element_by_zend_extension(&zend_extensions, XCACHE_NAME);
if (xc_llist_zend_extension != zend_extensions.head) {
zend_error(E_WARNING, "XCache failed to load itself as the first zend_extension. compatibility downgraded");
if (strcmp(ext->name, XCACHE_NAME) != 0) {
zend_error(E_WARNING, "XCache failed to load itself as the before \"%s\". compatibility downgraded", ext->name);
}
/* hide myself */
/* TODO: hide handle sub modules */
xcache_llist_unlink(&zend_extensions, xc_llist_zend_extension);
/* hide XCache modules */
xc_stack_init(&xc_llist_zend_extensions);
xcache_zend_extension_unlink_by_prefix(&xc_llist_zend_extensions, &zend_extensions, XCACHE_NAME);
ext = (zend_extension *) zend_llist_get_last_ex(&zend_extensions, &lpos);
assert(ext && ext != (zend_extension *) xc_llist_zend_extension->data);
xc_last_ext_startup = ext->startup;
assert(ext);
xc_last_ext_old_startup = ext->startup;
ext->startup = xc_zend_startup_last_hook;
}
return SUCCESS;
@ -637,9 +644,6 @@ static PHP_MINFO_FUNCTION(xcache) /* {{{ */
/* }}} */
static PHP_MINIT_FUNCTION(xcache) /* {{{ */
{
/* must be the first */
xcache_zend_extension_register(&xc_zend_extension_entry, 1);
#ifndef PHP_GINIT
ZEND_INIT_MODULE_GLOBALS(xcache, xc_init_globals, xc_shutdown_globals);
#endif
@ -652,18 +656,22 @@ static PHP_MINIT_FUNCTION(xcache) /* {{{ */
xc_init_constant(module_number TSRMLS_CC);
xc_shm_init_modules();
#ifdef HAVE_XCACHE_OPTIMIZER
xc_optimizer_startup_module();
#endif
#ifdef HAVE_XCACHE_CACHER
xc_cacher_startup_module();
#endif
/* ZendExtension is registered in reverse order for prepend by XCache */
#ifdef HAVE_XCACHE_COVERAGER
xc_coverager_startup_module();
#endif
#ifdef HAVE_XCACHE_DISASSEMBLER
xc_disassembler_startup_module();
#endif
#ifdef HAVE_XCACHE_CACHER
xc_cacher_startup_module();
#endif
#ifdef HAVE_XCACHE_OPTIMIZER
xc_optimizer_startup_module();
#endif
/* must be the first */
xcache_zend_extension_prepend(&xc_zend_extension_entry);
return SUCCESS;
err_init:
@ -693,7 +701,7 @@ static PHP_MSHUTDOWN_FUNCTION(xcache) /* {{{ */
#endif
UNREGISTER_INI_ENTRIES();
xcache_zend_extension_unregister(&xc_zend_extension_entry);
xcache_zend_extension_remove(&xc_zend_extension_entry);
return SUCCESS;
}
/* }}} */

View File

@ -4,7 +4,7 @@
#include "util/xc_trace.h"
int xcache_zend_extension_register(zend_extension *new_extension, zend_bool prepend) /* {{{ */
int xcache_zend_extension_prepend(zend_extension *new_extension) /* {{{ */
{
zend_extension extension;
@ -13,13 +13,8 @@ int xcache_zend_extension_register(zend_extension *new_extension, zend_bool prep
zend_extension_dispatch_message(ZEND_EXTMSG_NEW_EXTENSION, &extension);
if (prepend) {
zend_llist_prepend_element(&zend_extensions, &extension);
}
else {
zend_llist_add_element(&zend_extensions, &extension);
}
TRACE("%s", "registered");
zend_llist_prepend_element(&zend_extensions, &extension);
TRACE("%s", "prepended");
return SUCCESS;
}
/* }}} */
@ -40,7 +35,7 @@ static int xc_zend_extension_remove(zend_extension *extension) /* {{{ */
return SUCCESS;
}
/* }}} */
int xcache_zend_extension_unregister(zend_extension *extension) /* {{{ */
int xcache_zend_extension_remove(zend_extension *extension) /* {{{ */
{
zend_extension *ext = zend_get_extension(extension->name);
if (!ext) {
@ -55,18 +50,42 @@ int xcache_zend_extension_unregister(zend_extension *extension) /* {{{ */
}
/* }}} */
zend_llist_element *xcache_llist_get_element_by_zend_extension(zend_llist *l, const char *extension_name) /* {{{ */
int xcache_zend_extension_count_by_prefix(zend_llist *l, const char *extension_name_prefix) /* {{{ */
{
zend_llist_element *element;
size_t n = strlen(extension_name_prefix);
int count = 0;
for (element = zend_extensions.head; element; element = element->next) {
zend_extension *extension = (zend_extension *) element->data;
if (!strcmp(extension->name, extension_name)) {
return element;
if (strncmp(extension->name, extension_name_prefix, n) == 0) {
++count;
}
}
return NULL;
return count;
}
/* }}} */
void xcache_zend_extension_unlink_by_prefix(xc_stack_t *linked, zend_llist *l, const char *extension_name_prefix) /* {{{ */
{
size_t n = strlen(extension_name_prefix);
zend_llist_element *unlinked = NULL;
zend_llist_element *element, *next;
for (element = zend_extensions.head; element; element = next) {
zend_extension *extension = (zend_extension *) element->data;
next = element->next;
if (strncmp(extension->name, extension_name_prefix, n) == 0) {
xcache_llist_unlink(l, element);
xc_stack_push(linked, element);
}
}
for (element = zend_extensions.head; element; element = next) {
zend_extension *extension = (zend_extension *) element->data;
next = element->next;
}
}
/* }}} */
void xcache_llist_prepend(zend_llist *l, zend_llist_element *element) /* {{{ */

View File

@ -5,11 +5,13 @@
#pragma once
#endif /* _MSC_VER > 1000 */
#include "util/xc_stack.h"
#include "zend_extensions.h"
int xcache_zend_extension_register(zend_extension *new_extension, zend_bool prepend);
int xcache_zend_extension_unregister(zend_extension *extension);
int xcache_zend_extension_prepend(zend_extension *new_extension);
int xcache_zend_extension_remove(zend_extension *extension);
int xcache_zend_extension_count_by_prefix(zend_llist *l, const char *extension_name_prefix);
void xcache_zend_extension_unlink_by_prefix(xc_stack_t *unlinked, zend_llist *l, const char *extension_name_prefix);
zend_llist_element *xcache_llist_get_element_by_zend_extension(zend_llist *l, const char *extension_name);
void xcache_llist_prepend(zend_llist *l, zend_llist_element *element);
void xcache_llist_unlink(zend_llist *l, zend_llist_element *element);