Browse Source

full ZendOptimizer compatibility

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@405 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 15 years ago
parent
commit
49984336de
  1. 16
      utils.c
  2. 8
      utils.h
  3. 39
      xcache.c
  4. 1
      xcache_globals.h

16
utils.c

@ -623,7 +623,7 @@ static void xc_early_binding_cb(zend_op *opline, int oplineno, void *data TSRMLS
xc_do_early_binding(CG(active_op_array), OG(class_table), oplineno TSRMLS_CC);
}
/* }}} */
static void xc_sandbox_install(xc_sandbox_t *sandbox TSRMLS_DC) /* {{{ */
static void xc_sandbox_install(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */
{
int i;
Bucket *b;
@ -667,15 +667,17 @@ static void xc_sandbox_install(xc_sandbox_t *sandbox TSRMLS_DC) /* {{{ */
}
#endif
xc_undo_pass_two(CG(active_op_array) TSRMLS_CC);
xc_foreach_early_binding_class(CG(active_op_array), xc_early_binding_cb, (void *) sandbox TSRMLS_CC);
xc_redo_pass_two(CG(active_op_array) TSRMLS_CC);
if (install != XC_InstallNoBinding) {
xc_undo_pass_two(CG(active_op_array) TSRMLS_CC);
xc_foreach_early_binding_class(CG(active_op_array), xc_early_binding_cb, (void *) sandbox TSRMLS_CC);
xc_redo_pass_two(CG(active_op_array) TSRMLS_CC);
}
i = 1;
zend_hash_add(&OG(included_files), sandbox->filename, strlen(sandbox->filename) + 1, (void *)&i, sizeof(int), NULL);
}
/* }}} */
void xc_sandbox_free(xc_sandbox_t *sandbox, int install TSRMLS_DC) /* {{{ */
void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */
{
/* restore first first install function/class */
#ifdef HAVE_XCACHE_CONSTANT
@ -688,11 +690,11 @@ void xc_sandbox_free(xc_sandbox_t *sandbox, int install TSRMLS_DC) /* {{{ */
CG(auto_globals) = OG(auto_globals);
#endif
if (install) {
if (install != XC_NoInstall) {
CG(in_compilation) = 1;
CG(compiled_filename) = sandbox->filename;
CG(zend_lineno) = 0;
xc_sandbox_install(sandbox TSRMLS_CC);
xc_sandbox_install(sandbox, install TSRMLS_CC);
CG(in_compilation) = 0;
CG(compiled_filename) = NULL;

8
utils.h

@ -99,6 +99,12 @@ typedef struct {
Bucket *tmp_internal_class_tail;
} xc_sandbox_t;
typedef enum _xc_install_action_t {
XC_NoInstall,
XC_Install,
XC_InstallNoBinding
} xc_install_action_t;
void xc_zend_class_add_ref(zend_class_entry ZESW(*ce, **ce));
xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC);
void xc_sandbox_free(xc_sandbox_t *sandbox, int install TSRMLS_DC);
void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC);

39
xcache.c

@ -86,6 +86,7 @@ static xc_cache_t **xc_php_caches = NULL;
static xc_cache_t **xc_var_caches = NULL;
static zend_bool xc_initized = 0;
static zend_compile_file_t *origin_compile_file = NULL;
static zend_compile_file_t *old_compile_file = NULL;
static zend_llist_element *xc_llist_zend_extension = NULL;
@ -973,6 +974,8 @@ static zend_op_array *xc_compile_php(xc_entry_data_php_t *php, zend_file_handle
old_funcinfo_cnt = zend_hash_num_elements(CG(function_table));
old_constinfo_cnt = zend_hash_num_elements(EG(zend_constants));
php->op_array = NULL;
XG(initial_compile_file_called) = 0;
zend_try {
op_array = old_compile_file(h, type TSRMLS_CC);
} zend_catch {
@ -987,6 +990,10 @@ static zend_op_array *xc_compile_php(xc_entry_data_php_t *php, zend_file_handle
goto err_op_array;
}
if (!XG(initial_compile_file_called)) {
return op_array;
}
#ifdef HAVE_XCACHE_OPTIMIZER
if (XG(optimizer)) {
xc_optimize(op_array TSRMLS_CC);
@ -1163,6 +1170,12 @@ static zend_op_array *xc_compile_restore(xc_entry_t *stored_xce, zend_file_handl
return op_array;
}
/* }}} */
static zend_op_array *xc_check_initial_compile_file(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
{
XG(initial_compile_file_called) = 1;
return origin_compile_file(h, type TSRMLS_CC);
}
/* }}} */
static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
{
zend_op_array *op_array;
@ -1289,6 +1302,13 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /
goto err_aftersandbox;
}
/* not cachable */
if (!php.op_array) {
cache->compiling = 0;
xc_sandbox_free(&sandbox, XC_InstallNoBinding TSRMLS_CC);
return op_array;
}
xce.data.php = &php;
}
/* }}} */
@ -1354,7 +1374,7 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /
h = NULL;
}
if (newlycompiled) {
xc_sandbox_free(&sandbox, 0 TSRMLS_CC);
xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC);
}
return xc_compile_restore(stored_xce, h TSRMLS_CC);
}
@ -1362,7 +1382,7 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /
if (newlycompiled) {
/* install it */
CG(active_op_array) = op_array;
xc_sandbox_free(&sandbox, 1 TSRMLS_CC);
xc_sandbox_free(&sandbox, XC_Install TSRMLS_CC);
}
}
return op_array;
@ -1370,7 +1390,7 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /
err_aftersandbox:
if (newlycompiled) {
xc_free_php(&php TSRMLS_CC);
xc_sandbox_free(&sandbox, 0 TSRMLS_CC);
xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC);
}
if (catched) {
@ -1565,6 +1585,11 @@ static void xc_destroy() /* {{{ */
old_compile_file = NULL;
}
if (origin_compile_file) {
zend_compile_file = origin_compile_file;
origin_compile_file = NULL;
}
if (xc_php_caches) {
shm = xc_cache_destroy(xc_php_caches, &xc_php_hcache);
xc_php_caches = NULL;
@ -2914,7 +2939,7 @@ zend_module_entry xcache_module_entry = {
ZEND_GET_MODULE(xcache)
#endif
/* }}} */
static startup_func_t xc_last_ext_startup = NULL;
static startup_func_t xc_last_ext_startup;
static int xc_zend_startup_last(zend_extension *extension) /* {{{ */
{
/* restore */
@ -2935,6 +2960,12 @@ static int xc_zend_startup_last(zend_extension *extension) /* {{{ */
ZEND_DLEXPORT int xcache_zend_startup(zend_extension *extension) /* {{{ */
{
xc_zend_extension_gotup = 1;
if (!origin_compile_file) {
origin_compile_file = zend_compile_file;
zend_compile_file = xc_check_initial_compile_file;
}
if (zend_llist_count(&zend_extensions) > 1) {
zend_llist_position lpos;
zend_extension *ext;

1
xcache_globals.h

@ -1,5 +1,6 @@
ZEND_BEGIN_MODULE_GLOBALS(xcache)
zend_bool initial_compile_file_called; /* true is origin_compile_file is called */
zend_bool cacher; /* true if enabled */
zend_bool stat;
zend_bool experimental;

Loading…
Cancel
Save