Changeset 1047 in svn for trunk


Ignore:
Timestamp:
2012-07-25T10:56:27Z (3 years ago)
Author:
Xuefer
Message:

refactor: fall back to more simpler trick

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/mod_cacher/xc_cacher.c

    r1045 r1047  
    32543254
    32553255    xc_sandbox_module_init(module_number TSRMLS_CC);
    3256     return xcache_zend_extension_prepend(&xc_cacher_zend_extension_entry);
     3256    return xcache_zend_extension_add(&xc_cacher_zend_extension_entry, 0);
    32573257
    32583258err_init:
  • trunk/mod_coverager/xc_coverager.c

    r1045 r1047  
    671671    }
    672672
    673     return xcache_zend_extension_prepend(&xc_coverager_zend_extension_entry);
     673    return xcache_zend_extension_add(&xc_coverager_zend_extension_entry, 0);
    674674}
    675675/* }}} */
  • trunk/mod_optimizer/xc_optimizer.c

    r1045 r1047  
    667667{
    668668    REGISTER_INI_ENTRIES();
    669     return xcache_zend_extension_prepend(&xc_optimizer_zend_extension_entry);
     669    return xcache_zend_extension_add(&xc_optimizer_zend_extension_entry, 0);
    670670}
    671671/* }}} */
  • trunk/xcache.c

    r1045 r1047  
    543543#endif
    544544
    545 static startup_func_t xc_last_ext_old_startup;
    546 static xc_stack_t xc_llist_zend_extensions; /* (zend_extension *) */
    547 static int xc_zend_startup_last_hook(zend_extension *extension) /* {{{ */
    548 {
    549     zend_extension *ext = zend_get_extension(XCACHE_NAME);
    550     if (ext) {
    551         zend_error(E_WARNING, "Module '" XCACHE_NAME "' already loaded");
    552     }
     545/* {{{ incompatible zend extensions handling */
     546typedef struct {
     547    const char *name;
     548    startup_func_t old_startup;
     549} xc_incompatible_zend_extension_info_t;
     550static xc_incompatible_zend_extension_info_t xc_incompatible_zend_extensions[] = {
     551    { "Zend Optimizer", NULL }
     552};
     553
     554static xc_incompatible_zend_extension_info_t *xc_get_incompatible_zend_extension_info(const char *name)
     555{
     556    size_t i;
     557
     558    for (i = 0; i < sizeof(xc_incompatible_zend_extensions) / sizeof(xc_incompatible_zend_extensions[0]); ++i) {
     559        xc_incompatible_zend_extension_info_t *incompatible_zend_extension_info = &xc_incompatible_zend_extensions[i];
     560        if (strcmp(incompatible_zend_extension_info->name, name) == 0) {
     561            return incompatible_zend_extension_info;
     562        }
     563    }
     564
     565    return NULL;
     566}
     567/* }}} */
     568static int xc_incompatible_zend_extension_startup_hook(zend_extension *extension) /* {{{ */
     569{
     570    xc_incompatible_zend_extension_info_t *incompatible_zend_extension_info = xc_get_incompatible_zend_extension_info(extension->name);
     571    int status;
     572    zend_bool catched = 0;
     573    zend_llist old_zend_extensions = zend_extensions;
     574    TSRMLS_FETCH();
     575
     576    /* hide all extensions from it */
     577    zend_extensions.head = NULL;
     578    zend_extensions.count = 0;
     579
    553580    /* restore */
    554     extension->startup = xc_last_ext_old_startup;
    555     extension->startup = xc_last_ext_old_startup;
    556     xc_last_ext_old_startup = NULL;
    557     if (extension->startup) {
    558         if (extension->startup(extension) != SUCCESS) {
    559             return FAILURE;
    560         }
    561     }
    562 
    563     assert(xc_stack_count(&xc_llist_zend_extensions));
    564     while (xc_stack_count(&xc_llist_zend_extensions)) {
    565         zend_llist_element *p = (zend_llist_element *) xc_stack_pop(&xc_llist_zend_extensions);
    566         xcache_llist_prepend(&zend_extensions, p);
    567     }
    568     xc_stack_destroy(&xc_llist_zend_extensions);
    569     return SUCCESS;
     581    extension->startup = incompatible_zend_extension_info->old_startup;
     582    incompatible_zend_extension_info->old_startup = NULL;
     583    assert(extension->startup);
     584
     585    zend_try {
     586        status = extension->startup(extension);
     587    } zend_catch {
     588        catched = 1;
     589    } zend_end_try();
     590
     591    zend_extensions = old_zend_extensions;
     592    if (catched) {
     593        zend_bailout();
     594    }
     595    return status;
    570596}
    571597/* }}} */
    572598static int xc_zend_startup(zend_extension *extension) /* {{{ */
    573599{
     600    zend_llist_position lpos;
     601    zend_extension *ext;
     602
     603    ext = (zend_extension *) zend_extensions.head->data;
     604    if (strcmp(ext->name, XCACHE_NAME) != 0) {
     605        zend_error(E_WARNING, "XCache failed to load itself as the before \"%s\". compatibility downgraded", ext->name);
     606    }
     607
    574608    old_compile_file = zend_compile_file;
    575609    zend_compile_file = xc_check_initial_compile_file;
    576610
    577     if (1 || xcache_zend_extension_count_by_prefix(&zend_extensions, XCACHE_NAME) != zend_llist_count(&zend_extensions)) {
    578         zend_llist_position lpos;
    579         zend_extension *ext = (zend_extension *) zend_extensions.head->data;
    580         assert(ext);
    581 
    582         if (strcmp(ext->name, XCACHE_NAME) != 0) {
    583             zend_error(E_WARNING, "XCache failed to load itself as the before \"%s\". compatibility downgraded", ext->name);
    584         }
    585 
    586         /* hide XCache modules */
    587         xc_stack_init(&xc_llist_zend_extensions);
    588         xcache_zend_extension_unlink_by_prefix(&xc_llist_zend_extensions, &zend_extensions, XCACHE_NAME);
    589 
    590         ext = (zend_extension *) zend_llist_get_last_ex(&zend_extensions, &lpos);
    591         assert(ext);
    592         xc_last_ext_old_startup = ext->startup;
    593         ext->startup = xc_zend_startup_last_hook;
     611    for (ext = (zend_extension *) zend_llist_get_first_ex(&zend_extensions, &lpos);
     612            ext;
     613            ext = (zend_extension *) zend_llist_get_next_ex(&zend_extensions, &lpos)) {
     614        xc_incompatible_zend_extension_info_t *incompatible_zend_extension_info = xc_get_incompatible_zend_extension_info(extension->name);
     615        if (incompatible_zend_extension_info) {
     616            assert(!incompatible_zend_extension_info->old_startup);
     617            incompatible_zend_extension_info->old_startup = ext->startup;
     618            ext->startup = xc_incompatible_zend_extension_startup_hook;
     619        }
    594620    }
    595621    return SUCCESS;
     
    657683    xc_shm_init_modules();
    658684
    659     /* ZendExtension is registered in reverse order for prepend by XCache */
     685    /* must be the first */
     686    xcache_zend_extension_add(&xc_zend_extension_entry, 1);
     687#ifdef HAVE_XCACHE_OPTIMIZER
     688    xc_optimizer_startup_module();
     689#endif
     690#ifdef HAVE_XCACHE_CACHER
     691    xc_cacher_startup_module();
     692#endif
    660693#ifdef HAVE_XCACHE_COVERAGER
    661694    xc_coverager_startup_module();
     
    664697    xc_disassembler_startup_module();
    665698#endif
    666 #ifdef HAVE_XCACHE_CACHER
    667     xc_cacher_startup_module();
    668 #endif
    669 #ifdef HAVE_XCACHE_OPTIMIZER
    670     xc_optimizer_startup_module();
    671 #endif
    672     /* must be the first */
    673     xcache_zend_extension_prepend(&xc_zend_extension_entry);
    674699
    675700    return SUCCESS;
  • trunk/xcache/xc_extension.c

    r1045 r1047  
    55
    66
    7 int xcache_zend_extension_prepend(zend_extension *new_extension) /* {{{ */
     7int xcache_zend_extension_add(zend_extension *new_extension, zend_bool prepend) /* {{{ */
    88{
    99    zend_extension extension;
     
    1414    zend_extension_dispatch_message(ZEND_EXTMSG_NEW_EXTENSION, &extension);
    1515
    16     zend_llist_prepend_element(&zend_extensions, &extension);
    17     TRACE("%s", "prepended");
     16    if (prepend) {
     17        zend_llist_prepend_element(&zend_extensions, &extension);
     18    }
     19    else {
     20        zend_llist_add_element(&zend_extensions, &extension);
     21    }
     22    TRACE("%s", "registered");
    1823    return SUCCESS;
    1924}
     
    5156/* }}} */
    5257
    53 int xcache_zend_extension_count_by_prefix(zend_llist *l, const char *extension_name_prefix) /* {{{ */
    54 {
    55     zend_llist_element *element;
    56     size_t n = strlen(extension_name_prefix);
    57     int count = 0;
    58 
    59     for (element = zend_extensions.head; element; element = element->next) {
    60         zend_extension *extension = (zend_extension *) element->data;
    61 
    62         if (strncmp(extension->name, extension_name_prefix, n) == 0) {
    63             ++count;
    64         }
    65     }
    66     return count;
    67 }
    68 /* }}} */
    69 void xcache_zend_extension_unlink_by_prefix(xc_stack_t *linked, zend_llist *l, const char *extension_name_prefix) /* {{{ */
    70 {
    71     size_t n = strlen(extension_name_prefix);
    72     zend_llist_element *unlinked = NULL;
    73     zend_llist_element *element, *next;
    74 
    75     for (element = zend_extensions.head; element; element = next) {
    76         zend_extension *extension = (zend_extension *) element->data;
    77         next = element->next;
    78 
    79         if (strncmp(extension->name, extension_name_prefix, n) == 0) {
    80             xcache_llist_unlink(l, element);
    81             xc_stack_push(linked, element);
    82         }
    83     }
    84 
    85     for (element = zend_extensions.head; element; element = next) {
    86         zend_extension *extension = (zend_extension *) element->data;
    87         next = element->next;
    88     }
    89 }
    90 /* }}} */
    9158void xcache_llist_prepend(zend_llist *l, zend_llist_element *element) /* {{{ */
    9259{
  • trunk/xcache/xc_extension.h

    r1045 r1047  
    88#include "util/xc_stack.h"
    99#include "zend_extensions.h"
    10 int xcache_zend_extension_prepend(zend_extension *new_extension);
     10int xcache_zend_extension_add(zend_extension *new_extension, zend_bool prepend);
    1111int xcache_zend_extension_remove(zend_extension *extension);
    12 int xcache_zend_extension_count_by_prefix(zend_llist *l, const char *extension_name_prefix);
    13 void xcache_zend_extension_unlink_by_prefix(xc_stack_t *unlinked, zend_llist *l, const char *extension_name_prefix);
    1412
    1513void xcache_llist_prepend(zend_llist *l, zend_llist_element *element);
Note: See TracChangeset for help on using the changeset viewer.