Changeset 1045 for trunk


Ignore:
Timestamp:
2012-07-25T11:32:11+02:00 (21 months ago)
Author:
moo
Message:

refactor: bring back compatibility with Zend Optimizer

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/mod_cacher/xc_cacher.c

    r1043 r1045  
    32543254 
    32553255    xc_sandbox_module_init(module_number TSRMLS_CC); 
    3256     return xcache_zend_extension_register(&xc_cacher_zend_extension_entry, 0); 
     3256    return xcache_zend_extension_prepend(&xc_cacher_zend_extension_entry); 
    32573257 
    32583258err_init: 
     
    32643264    xc_sandbox_module_shutdown(); 
    32653265 
    3266     xcache_zend_extension_unregister(&xc_cacher_zend_extension_entry); 
     3266    xcache_zend_extension_remove(&xc_cacher_zend_extension_entry); 
    32673267    UNREGISTER_INI_ENTRIES(); 
    32683268 
  • trunk/mod_coverager/xc_coverager.c

    r1043 r1045  
    671671    } 
    672672 
    673     return xcache_zend_extension_register(&xc_coverager_zend_extension_entry, 0); 
     673    return xcache_zend_extension_prepend(&xc_coverager_zend_extension_entry); 
    674674} 
    675675/* }}} */ 
     
    685685    } 
    686686    UNREGISTER_INI_ENTRIES(); 
    687     return xcache_zend_extension_unregister(&xc_coverager_zend_extension_entry); 
     687    return xcache_zend_extension_remove(&xc_coverager_zend_extension_entry); 
    688688} 
    689689/* }}} */ 
  • trunk/mod_optimizer/xc_optimizer.c

    r1043 r1045  
    667667{ 
    668668    REGISTER_INI_ENTRIES(); 
    669     return xcache_zend_extension_register(&xc_optimizer_zend_extension_entry, 0); 
     669    return xcache_zend_extension_prepend(&xc_optimizer_zend_extension_entry); 
    670670} 
    671671/* }}} */ 
     
    673673{ 
    674674    UNREGISTER_INI_ENTRIES(); 
    675     return xcache_zend_extension_unregister(&xc_optimizer_zend_extension_entry); 
     675    return xcache_zend_extension_remove(&xc_optimizer_zend_extension_entry); 
    676676} 
    677677/* }}} */ 
  • trunk/xcache.c

    r1040 r1045  
    3939 
    4040static zend_compile_file_t *old_compile_file = NULL; 
    41 static zend_llist_element  *xc_llist_zend_extension = NULL; 
    4241 
    4342zend_bool xc_test = 0; 
     
    544543#endif 
    545544 
    546 static startup_func_t xc_last_ext_startup; 
     545static startup_func_t xc_last_ext_old_startup; 
     546static xc_stack_t xc_llist_zend_extensions; /* (zend_extension *) */ 
    547547static int xc_zend_startup_last_hook(zend_extension *extension) /* {{{ */ 
    548548{ 
     
    552552    } 
    553553    /* restore */ 
    554     extension->startup = xc_last_ext_startup; 
     554    extension->startup = xc_last_ext_old_startup; 
     555    extension->startup = xc_last_ext_old_startup; 
     556    xc_last_ext_old_startup = NULL; 
    555557    if (extension->startup) { 
    556558        if (extension->startup(extension) != SUCCESS) { 
     
    558560        } 
    559561    } 
    560     assert(xc_llist_zend_extension); 
    561     xcache_llist_prepend(&zend_extensions, xc_llist_zend_extension); 
     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); 
    562569    return SUCCESS; 
    563570} 
     
    568575    zend_compile_file = xc_check_initial_compile_file; 
    569576 
    570     if (zend_llist_count(&zend_extensions) > 1) { 
     577    if (1 || xcache_zend_extension_count_by_prefix(&zend_extensions, XCACHE_NAME) != zend_llist_count(&zend_extensions)) { 
    571578        zend_llist_position lpos; 
    572         zend_extension *ext; 
    573  
    574         xc_llist_zend_extension = xcache_llist_get_element_by_zend_extension(&zend_extensions, XCACHE_NAME); 
    575         if (xc_llist_zend_extension != zend_extensions.head) { 
    576             zend_error(E_WARNING, "XCache failed to load itself as the first zend_extension. compatibility downgraded"); 
    577         } 
    578  
    579         /* hide myself */ 
    580         /* TODO: hide handle sub modules */ 
    581         xcache_llist_unlink(&zend_extensions, xc_llist_zend_extension); 
     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); 
    582589 
    583590        ext = (zend_extension *) zend_llist_get_last_ex(&zend_extensions, &lpos); 
    584         assert(ext && ext != (zend_extension *) xc_llist_zend_extension->data); 
    585         xc_last_ext_startup = ext->startup; 
     591        assert(ext); 
     592        xc_last_ext_old_startup = ext->startup; 
    586593        ext->startup = xc_zend_startup_last_hook; 
    587594    } 
     
    638645static PHP_MINIT_FUNCTION(xcache) /* {{{ */ 
    639646{ 
    640     /* must be the first */ 
    641     xcache_zend_extension_register(&xc_zend_extension_entry, 1); 
    642  
    643647#ifndef PHP_GINIT 
    644648    ZEND_INIT_MODULE_GLOBALS(xcache, xc_init_globals, xc_shutdown_globals); 
     
    653657    xc_shm_init_modules(); 
    654658 
     659    /* ZendExtension is registered in reverse order for prepend by XCache */ 
     660#ifdef HAVE_XCACHE_COVERAGER 
     661    xc_coverager_startup_module(); 
     662#endif 
     663#ifdef HAVE_XCACHE_DISASSEMBLER 
     664    xc_disassembler_startup_module(); 
     665#endif 
     666#ifdef HAVE_XCACHE_CACHER 
     667    xc_cacher_startup_module(); 
     668#endif 
    655669#ifdef HAVE_XCACHE_OPTIMIZER 
    656670    xc_optimizer_startup_module(); 
    657671#endif 
    658 #ifdef HAVE_XCACHE_CACHER 
    659     xc_cacher_startup_module(); 
    660 #endif 
    661 #ifdef HAVE_XCACHE_COVERAGER 
    662     xc_coverager_startup_module(); 
    663 #endif 
    664 #ifdef HAVE_XCACHE_DISASSEMBLER 
    665     xc_disassembler_startup_module(); 
    666 #endif 
     672    /* must be the first */ 
     673    xcache_zend_extension_prepend(&xc_zend_extension_entry); 
     674 
    667675    return SUCCESS; 
    668676 
     
    694702 
    695703    UNREGISTER_INI_ENTRIES(); 
    696     xcache_zend_extension_unregister(&xc_zend_extension_entry); 
     704    xcache_zend_extension_remove(&xc_zend_extension_entry); 
    697705    return SUCCESS; 
    698706} 
  • trunk/xcache/xc_extension.c

    r1026 r1045  
    55 
    66 
    7 int xcache_zend_extension_register(zend_extension *new_extension, zend_bool prepend) /* {{{ */ 
     7int xcache_zend_extension_prepend(zend_extension *new_extension) /* {{{ */ 
    88{ 
    99    zend_extension extension; 
     
    1414    zend_extension_dispatch_message(ZEND_EXTMSG_NEW_EXTENSION, &extension); 
    1515 
    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"); 
     16    zend_llist_prepend_element(&zend_extensions, &extension); 
     17    TRACE("%s", "prepended"); 
    2318    return SUCCESS; 
    2419} 
     
    4136} 
    4237/* }}} */ 
    43 int xcache_zend_extension_unregister(zend_extension *extension) /* {{{ */ 
     38int xcache_zend_extension_remove(zend_extension *extension) /* {{{ */ 
    4439{ 
    4540    zend_extension *ext = zend_get_extension(extension->name); 
     
    5651/* }}} */ 
    5752 
    58 zend_llist_element *xcache_llist_get_element_by_zend_extension(zend_llist *l, const char *extension_name) /* {{{ */ 
     53int xcache_zend_extension_count_by_prefix(zend_llist *l, const char *extension_name_prefix) /* {{{ */ 
    5954{ 
    6055    zend_llist_element *element; 
     56    size_t n = strlen(extension_name_prefix); 
     57    int count = 0; 
    6158 
    6259    for (element = zend_extensions.head; element; element = element->next) { 
    6360        zend_extension *extension = (zend_extension *) element->data; 
    6461 
    65         if (!strcmp(extension->name, extension_name)) { 
    66             return element; 
     62        if (strncmp(extension->name, extension_name_prefix, n) == 0) { 
     63            ++count; 
    6764        } 
    6865    } 
    69     return NULL; 
     66    return count; 
     67} 
     68/* }}} */ 
     69void 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    } 
    7089} 
    7190/* }}} */ 
  • trunk/xcache/xc_extension.h

    r1044 r1045  
    66#endif /* _MSC_VER > 1000 */ 
    77 
     8#include "util/xc_stack.h" 
    89#include "zend_extensions.h" 
    9 int xcache_zend_extension_register(zend_extension *new_extension, zend_bool prepend); 
    10 int xcache_zend_extension_unregister(zend_extension *extension); 
     10int xcache_zend_extension_prepend(zend_extension *new_extension); 
     11int xcache_zend_extension_remove(zend_extension *extension); 
     12int xcache_zend_extension_count_by_prefix(zend_llist *l, const char *extension_name_prefix); 
     13void xcache_zend_extension_unlink_by_prefix(xc_stack_t *unlinked, zend_llist *l, const char *extension_name_prefix); 
    1114 
    12 zend_llist_element *xcache_llist_get_element_by_zend_extension(zend_llist *l, const char *extension_name); 
    1315void xcache_llist_prepend(zend_llist *l, zend_llist_element *element); 
    1416void xcache_llist_unlink(zend_llist *l, zend_llist_element *element); 
Note: See TracChangeset for help on using the changeset viewer.