Browse Source

merged[344] [345] [346] from trunk->1.2: fixed #59: pass by reference for internal function was broken

git-svn-id: svn://svn.lighttpd.net/xcache/branches/1.2@378 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
1.2
Xuefer 15 years ago
parent
commit
197d776677
  1. 1
      NEWS
  2. 31
      utils.c
  3. 3
      utils.h
  4. 19
      xcache.c
  5. 3
      xcache_globals.h

1
NEWS

@ -7,6 +7,7 @@
== ChangeLog ==
* #86: remove/edit variable in admin page
* fixed #77: hits/misses was not updated
* fixed #59: pass by reference for internal function was broken
* fixed #56: xcache_set segfaults when xcache.var_size=0
========

31
utils.c

@ -1,5 +1,7 @@
#include "xcache.h"
#include "stack.h"
#include "xcache_globals.h"
#include "utils.h"
#ifdef ZEND_ENGINE_2_1
#include "zend_vm.h"
@ -533,9 +535,20 @@ static int xc_auto_global_arm(zend_auto_global *auto_global TSRMLS_DC) /* {{{ */
}
/* }}} */
#endif
void xc_zend_class_add_ref(zend_class_entry ZESW(*ce, **ce))
{
#ifdef ZEND_ENGINE_2
(*ce)->refcount++;
#else
(*ce->refcount)++;
#endif
}
xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /* {{{ */
{
HashTable *h;
if (sandbox) {
memset(sandbox, 0, sizeof(sandbox[0]));
}
@ -572,8 +585,22 @@ xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /
#endif
h = OG(function_table);
zend_hash_init_ex(&TG(function_table), 128, NULL, h->pDestructor, h->persistent, h->bApplyProtection);
{
zend_function tmp_func;
zend_hash_copy(&TG(function_table), &XG(internal_function_table), (copy_ctor_func_t) function_add_ref, (void *) &tmp_func, sizeof(tmp_func));
}
TG(internal_class_tail) = TG(function_table).pListTail;
h = OG(class_table);
zend_hash_init_ex(&TG(class_table), 16, NULL, h->pDestructor, h->persistent, h->bApplyProtection);
#if 0 && TODO
{
xc_cest_t tmp_cest;
zend_hash_copy(&TG(class_table), &XG(internal_class_table), (copy_ctor_func_t) xc_zend_class_add_ref, (void *) &tmp_cest, sizeof(tmp_cest));
}
#endif
TG(internal_class_tail) = TG(class_table).pListTail;
#ifdef ZEND_ENGINE_2_1
/* shallow copy, don't destruct */
h = OG(auto_globals);
@ -618,7 +645,7 @@ static void xc_sandbox_install(xc_sandbox_t *sandbox TSRMLS_DC) /* {{{ */
}
#endif
b = TG(function_table).pListHead;
b = TG(internal_function_tail) ? TG(internal_function_tail)->pListNext : TG(function_table).pListHead;
/* install function */
while (b != NULL) {
zend_function *func = (zend_function*) b->pData;
@ -627,7 +654,7 @@ static void xc_sandbox_install(xc_sandbox_t *sandbox TSRMLS_DC) /* {{{ */
b = b->pListNext;
}
b = TG(class_table).pListHead;
b = TG(internal_class_tail) ? TG(internal_class_tail)->pListNext : TG(class_table).pListHead;
/* install class */
while (b != NULL) {
xc_install_class(sandbox->filename, (xc_cest_t*) b->pData, -1,

3
utils.h

@ -52,7 +52,10 @@ typedef struct {
HashTable tmp_function_table;
HashTable tmp_class_table;
HashTable tmp_auto_globals;
Bucket *tmp_internal_function_tail;
Bucket *tmp_internal_class_tail;
} xc_sandbox_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);

19
xcache.c

@ -1022,14 +1022,16 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /
/* {{{ shallow copy, pointers only */ {
Bucket *b;
unsigned int i;
unsigned int j;
#define COPY_H(vartype, var, cnt, name, datatype) do { \
for (i = 0; b; i ++, b = b->pListNext) { \
vartype *data = &php.var[i]; \
for (i = 0, j = 0; b; i ++, b = b->pListNext) { \
vartype *data = &php->var[j]; \
\
if (i < old_##cnt) { \
continue; \
} \
j ++; \
\
assert(i < old_##cnt + php.cnt); \
assert(b->pData); \
@ -1442,6 +1444,16 @@ static void xc_request_init(TSRMLS_D) /* {{{ */
{
int i;
if (XG(internal_function_table).nTableSize == 0) {
zend_function tmp_func;
xc_cest_t tmp_cest;
zend_hash_init_ex(&XG(internal_function_table), 100, NULL, NULL, 1, 0);
zend_hash_copy(&XG(internal_function_table), CG(function_table), (copy_ctor_func_t) function_add_ref, &tmp_func, sizeof(tmp_func));
zend_hash_init_ex(&XG(internal_class_table), 10, NULL, NULL, 1, 0);
zend_hash_copy(&XG(internal_class_table), CG(class_table), (copy_ctor_func_t) xc_zend_class_add_ref, &tmp_cest, sizeof(tmp_cest));
}
if (xc_php_hcache.size && !XG(php_holds)) {
XG(php_holds) = calloc(xc_php_hcache.size, sizeof(xc_stack_t));
for (i = 0; i < xc_php_hcache.size; i ++) {
@ -1515,6 +1527,9 @@ void xc_shutdown_globals(zend_xcache_globals* xcache_globals TSRMLS_DC)
free(xcache_globals->var_holds);
xcache_globals->var_holds = NULL;
}
zend_hash_destroy(&xcache_globals->internal_function_table);
zend_hash_destroy(&xcache_globals->internal_class_table);
}
/* }}} */

3
xcache_globals.h

@ -15,6 +15,9 @@ ZEND_BEGIN_MODULE_GLOBALS(xcache)
time_t request_time;
long var_ttl;
zend_bool auth_enabled;
HashTable internal_function_table;
HashTable internal_class_table;
ZEND_END_MODULE_GLOBALS(xcache)
ZEND_EXTERN_MODULE_GLOBALS(xcache)

Loading…
Cancel
Save