1
0
Fork 0

merge stack/vector to 1 impl, avoid possible memory leak using malloc

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1551 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
master
Xuefer 9 years ago
parent c130a0d589
commit f664f5a518

@ -1,25 +1,24 @@
$(XCACHE_INCLUDES_I) includes.lo $(builddir)/includes.lo: $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h
mod_assembler/xc_assembler.lo $(builddir)/mod_assembler/xc_assembler.lo:
mod_cacher/xc_cacher.lo $(builddir)/mod_cacher/xc_cacher.lo: $(XCACHE_PROC_H) $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/mod_cacher/xc_cacher.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
mod_coverager/xc_coverager.lo $(builddir)/mod_coverager/xc_coverager.lo: $(srcdir)/mod_coverager/xc_coverager.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
mod_cacher/xc_cacher.lo $(builddir)/mod_cacher/xc_cacher.lo: $(XCACHE_PROC_H) $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/mod_cacher/xc_cacher.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
mod_coverager/xc_coverager.lo $(builddir)/mod_coverager/xc_coverager.lo: $(srcdir)/mod_coverager/xc_coverager.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
mod_decoder/xc_decoder.lo $(builddir)/mod_decoder/xc_decoder.lo:
mod_disassembler/xc_disassembler.lo $(builddir)/mod_disassembler/xc_disassembler.lo: $(XCACHE_PROC_H) $(srcdir)/mod_disassembler/xc_disassembler.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h
mod_encoder/xc_encoder.lo $(builddir)/mod_encoder/xc_encoder.lo:
mod_optimizer/xc_optimizer.lo $(builddir)/mod_optimizer/xc_optimizer.lo: $(XCACHE_PROC_H) $(srcdir)/mod_optimizer/xc_optimizer.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
util/xc_stack.lo $(builddir)/util/xc_stack.lo: $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h
mod_optimizer/xc_optimizer.lo $(builddir)/mod_optimizer/xc_optimizer.lo: $(XCACHE_PROC_H) $(srcdir)/mod_optimizer/xc_optimizer.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
util/xc_trace.lo $(builddir)/util/xc_trace.lo: $(srcdir)/util/xc_trace.h
xcache.lo $(builddir)/xcache.lo: $(XCACHE_PROC_H) $(srcdir)/util/xc_foreachcoresig.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
xcache.lo $(builddir)/xcache.lo: $(XCACHE_PROC_H) $(srcdir)/util/xc_foreachcoresig.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
xcache/xc_allocator.lo $(builddir)/xcache/xc_allocator.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_allocator_bestfit.lo $(builddir)/xcache/xc_allocator_bestfit.lo: $(srcdir)/util/xc_align.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h
xcache/xc_compatibility.lo $(builddir)/xcache/xc_compatibility.lo: $(srcdir)/xcache/xc_compatibility.h
xcache/xc_const_string.lo $(builddir)/xcache/xc_const_string.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_const_string_opcodes_php4.x.h $(srcdir)/xcache/xc_const_string_opcodes_php5.0.h $(srcdir)/xcache/xc_const_string_opcodes_php5.1.h $(srcdir)/xcache/xc_const_string_opcodes_php5.2.h $(srcdir)/xcache/xc_const_string_opcodes_php5.3.h $(srcdir)/xcache/xc_const_string_opcodes_php5.4.h $(srcdir)/xcache/xc_const_string_opcodes_php5.5.h $(srcdir)/xcache/xc_const_string_opcodes_php6.x.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_extension.lo $(builddir)/xcache/xc_extension.lo: $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_const_string.lo $(builddir)/xcache/xc_const_string.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_const_string_opcodes_php4.x.h $(srcdir)/xcache/xc_const_string_opcodes_php5.0.h $(srcdir)/xcache/xc_const_string_opcodes_php5.1.h $(srcdir)/xcache/xc_const_string_opcodes_php5.2.h $(srcdir)/xcache/xc_const_string_opcodes_php5.3.h $(srcdir)/xcache/xc_const_string_opcodes_php5.4.h $(srcdir)/xcache/xc_const_string_opcodes_php5.5.h $(srcdir)/xcache/xc_const_string_opcodes_php5.6.h $(srcdir)/xcache/xc_const_string_opcodes_php6.x.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_extension.lo $(builddir)/xcache/xc_extension.lo: $(srcdir)/util/xc_trace.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_ini.lo $(builddir)/xcache/xc_ini.lo: $(srcdir)/xcache/xc_ini.h
xcache/xc_malloc.lo $(builddir)/xcache/xc_malloc.lo: $(srcdir)/util/xc_align.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_mutex.lo $(builddir)/xcache/xc_mutex.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_opcode_spec.lo $(builddir)/xcache/xc_opcode_spec.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_opcode_spec_def.h $(srcdir)/xcache/xc_shm.h
xcache/xc_processor.lo $(builddir)/xcache/xc_processor.lo: $(XCACHE_PROC_C)
xcache/xc_sandbox.lo $(builddir)/xcache/xc_sandbox.lo: $(srcdir)/util/xc_stack.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
xcache/xc_sandbox.lo $(builddir)/xcache/xc_sandbox.lo: $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
xcache/xc_shm.lo $(builddir)/xcache/xc_shm.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
xcache/xc_shm_mmap.lo $(builddir)/xcache/xc_shm_mmap.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h
xcache/xc_utils.lo $(builddir)/xcache/xc_utils.lo: $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
xcache/xc_utils.lo $(builddir)/xcache/xc_utils.lo: $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h

@ -25,7 +25,6 @@ if test "$PHP_XCACHE" != "no"; then
xcache_sources="xcache.c"
for i in \
xc_stack.c \
xc_trace.c \
; do
xcache_sources="$xcache_sources util/$i"

@ -13,7 +13,6 @@ if (PHP_XCACHE != "no") {
// }}}
ADD_SOURCES(configure_module_dirname + "/util", " \
xc_stack.c \
xc_trace.c \
", "xcache");

@ -39,7 +39,7 @@ stopfpm() { # {{{1
}
xtest() { # {{{1
$MAKE ${MAKEOPTS} -f devel/test.mak
$MAKE ${MAKEOPTS} -f devel/test.mak clean all
}
prep() { # {{{1

@ -1,18 +1,23 @@
#! /usr/bin/make -f
EXES=allocator_test
OBJS=allocator.o
CC=gcc
LDFLAGS=
CFLAGS=-g -O0 -I. -D TEST -D HAVE_XCACHE_TEST -Wall
TEST=valgrind
all: allocator
all: allocator vector
allocator_test: xcache/xc_allocator.h xcache/xc_allocator.c xcache/xc_malloc.c xcache/xc_allocator_bestfit.c util/xc_trace.c util/xc_trace.h
$(CC) $(CFLAGS) -o allocator_test xcache/xc_allocator.c xcache/xc_malloc.c xcache/xc_allocator_bestfit.c util/xc_trace.c
$(CC) $(LDFLAGS) $(CFLAGS) -o allocator_test xcache/xc_allocator.c xcache/xc_malloc.c xcache/xc_allocator_bestfit.c util/xc_trace.c
allocator: allocator_test
$(TEST) ./allocator_test
vector_test: util/xc_vector_test.c
$(CC) $(LDFLAGS) $(CFLAGS) -o vector_test util/xc_vector_test.c
vector: vector_test
$(TEST) ./vector_test
clean:
rm -f $(OBJS) $(EXES)
rm -f allocator_test vector_test

@ -432,7 +432,7 @@ static void xc_entry_hold_php_unlocked(xc_cache_t *cache, xc_entry_php_t *entry
}
#endif
entry->refcount ++;
xc_stack_push(&XG(php_holds)[cache->cacheid], (void *)entry);
xc_vector_push_back(&XG(php_holds)[cache->cacheid], &entry);
}
/* }}} */
static inline zend_uint advance_wrapped(zend_uint val, zend_uint count) /* {{{ */
@ -871,21 +871,21 @@ static zend_op_array *xc_entry_install(xc_entry_php_t *entry_php TSRMLS_DC) /* {
}
/* }}} */
static inline void xc_entry_unholds_real(xc_stack_t *holds, xc_cache_t *caches, size_t cachecount TSRMLS_DC) /* {{{ */
static inline void xc_entry_unholds_real(xc_vector_t *holds, xc_cache_t *caches, size_t cachecount TSRMLS_DC) /* {{{ */
{
size_t i;
xc_stack_t *s;
xc_vector_t *v;
xc_cache_t *cache;
xc_entry_php_t *entry_php;
for (i = 0; i < cachecount; i ++) {
s = &holds[i];
TRACE("holded %d items", xc_stack_count(s));
if (xc_stack_count(s)) {
v = &holds[i];
TRACE("holded %d items", v->cnt);
if (xc_vector_size(v)) {
cache = &caches[i];
ENTER_LOCK(cache) {
while (xc_stack_count(s)) {
entry_php = (xc_entry_php_t *) xc_stack_pop(s);
while (xc_vector_size(v)) {
entry_php = xc_vector_pop_back(xc_entry_php_t *, v);
TRACE("unhold %lu:%s", (unsigned long) entry_php->file_inode, entry_php->entry.name.str.val);
assert(entry_php->refcount > 0);
--entry_php->refcount;
@ -1409,9 +1409,7 @@ typedef struct {
static void xc_collect_class_constant_info(xc_compiler_t *compiler, xc_const_usage_t *usage, xc_classinfo_t *classinfo, HashTable *constants TSRMLS_DC) /* {{{ */
{
uint index;
xc_vector_t constantinfos;
xc_vector_init(xc_constant_info_t, &constantinfos);
xc_vector_t constantinfos = xc_vector_initializer(xc_constant_info_t, 0);
for (index = 0; index < constants->nTableSize; ++index) {
Bucket *bucket;
@ -1438,12 +1436,12 @@ static void xc_collect_class_constant_info(xc_compiler_t *compiler, xc_const_usa
xc_constant_info_t detail;
detail.index = index2 * constants->nTableSize + index;
detail.info = constantinfo;
xc_vector_add(xc_constant_info_t, &constantinfos, detail);
xc_vector_push_back(&constantinfos, &detail);
}
}
}
classinfo->constantinfo_cnt = constantinfos.cnt;
classinfo->constantinfo_cnt = xc_vector_size(&constantinfos);
classinfo->constantinfos = xc_vector_detach(xc_constant_info_t, &constantinfos);
}
/* }}} */
@ -1455,9 +1453,7 @@ static void xc_collect_op_array_info(xc_compiler_t *compiler, xc_const_usage_t *
#else
zend_uint oplinenum;
#endif
xc_vector_t constantinfos;
xc_vector_init(xc_constant_info_t, &constantinfos);
xc_vector_t constantinfos = xc_vector_initializer(xc_constant_info_t, 0);
#ifdef ZEND_ENGINE_2_4
for (literalindex = 0; literalindex < op_array->last_literal; literalindex++) {
@ -1480,12 +1476,9 @@ static void xc_collect_op_array_info(xc_compiler_t *compiler, xc_const_usage_t *
xc_constant_info_t detail;
detail.index = literalindex;
detail.info = constantinfo;
xc_vector_add(xc_constant_info_t, &constantinfos, detail);
xc_vector_push_back(&constantinfos, &detail);
}
}
op_array_info->constantinfo_cnt = constantinfos.cnt;
op_array_info->constantinfos = xc_vector_detach(xc_constant_info_t, &constantinfos);
#else /* ZEND_ENGINE_2_4 */
for (oplinenum = 0; oplinenum < op_array->last; oplinenum++) {
zend_op *opline = &op_array->opcodes[oplinenum];
@ -1530,11 +1523,11 @@ static void xc_collect_op_array_info(xc_compiler_t *compiler, xc_const_usage_t *
xc_vector_add(xc_constant_info_t, &constantinfos, detail);
}
}
#endif /* ZEND_ENGINE_2_4 */
op_array_info->constantinfo_cnt = constantinfos.cnt;
op_array_info->constantinfo_cnt = xc_vector_size(&constantinfos);
op_array_info->constantinfos = xc_vector_detach(xc_constant_info_t, &constantinfos);
#endif /* ZEND_ENGINE_2_4 */
xc_vector_free(xc_constant_info_t, &constantinfos);
xc_vector_destroy(&constantinfos);
}
/* }}} */
#ifdef IS_UNICODE
@ -2826,17 +2819,17 @@ static void xc_holds_init(TSRMLS_D) /* {{{ */
if (xc_php_caches && !XG(php_holds)) {
XG(php_holds_size) = xc_php_hcache.size;
XG(php_holds) = calloc(XG(php_holds_size), sizeof(xc_stack_t));
XG(php_holds) = calloc(XG(php_holds_size), sizeof(xc_vector_t));
for (i = 0; i < xc_php_hcache.size; i ++) {
xc_stack_init(&XG(php_holds[i]));
xc_vector_init(xc_entry_php_t *, &XG(php_holds[i]), 1);
}
}
if (xc_var_caches && !XG(var_holds)) {
XG(var_holds_size) = xc_var_hcache.size;
XG(var_holds) = calloc(XG(var_holds_size), sizeof(xc_stack_t));
XG(var_holds) = calloc(XG(var_holds_size), sizeof(xc_vector_t));
for (i = 0; i < xc_var_hcache.size; i ++) {
xc_stack_init(&XG(var_holds[i]));
xc_vector_init(xc_entry_php_t *, &XG(var_holds[i]), 1);
}
}
}
@ -2847,7 +2840,7 @@ static void xc_holds_destroy(TSRMLS_D) /* {{{ */
if (xc_php_caches && XG(php_holds)) {
for (i = 0; i < XG(php_holds_size); i ++) {
xc_stack_destroy(&XG(php_holds[i]));
xc_vector_destroy(&XG(php_holds[i]));
}
free(XG(php_holds));
XG(php_holds) = NULL;
@ -2856,7 +2849,7 @@ static void xc_holds_destroy(TSRMLS_D) /* {{{ */
if (xc_var_caches && XG(var_holds)) {
for (i = 0; i < XG(var_holds_size); i ++) {
xc_stack_destroy(&XG(var_holds[i]));
xc_vector_destroy(&XG(var_holds[i]));
}
free(XG(var_holds));
XG(var_holds) = NULL;

@ -13,7 +13,7 @@
#include "xcache/xc_extension.h"
#include "xcache/xc_ini.h"
#include "xcache/xc_utils.h"
#include "util/xc_stack.h"
#include "util/xc_vector.h"
#include "util/xc_trace.h"
#include "xcache_globals.h"

@ -2,7 +2,7 @@
#include "xcache/xc_extension.h"
#include "xcache/xc_ini.h"
#include "xcache/xc_utils.h"
#include "util/xc_stack.h"
#include "util/xc_vector.h"
#include "util/xc_trace.h"
#include "xcache_globals.h"
@ -46,7 +46,7 @@ typedef struct _bb_t {
/* }}} */
/* basic blocks */
typedef xc_stack_t bbs_t;
typedef xc_vector_t bbs_t;
/* op array helper functions */
static int op_array_convert_switch(zend_op_array *op_array) /* {{{ */
@ -352,48 +352,49 @@ static void bb_print(bb_t *bb, zend_op_array *op_array) /* {{{ */
static bb_t *bbs_get(bbs_t *bbs, int n) /* {{{ */
{
return (bb_t *) xc_stack_get(bbs, n);
return xc_vector_data(bb_t *, bbs)[n];
}
/* }}} */
static int bbs_count(bbs_t *bbs) /* {{{ */
{
return xc_stack_count(bbs);
return xc_vector_size(bbs);
}
/* }}} */
static void bbs_destroy(bbs_t *bbs) /* {{{ */
static void bbs_destroy(bbs_t *bbs TSRMLS_DC) /* {{{ */
{
bb_t *bb;
while (bbs_count(bbs)) {
bb = (bb_t *) xc_stack_pop(bbs);
bb = xc_vector_pop_back(bb_t *, bbs);
bb_destroy(bb);
}
xc_stack_destroy(bbs);
xc_vector_destroy(bbs);
}
/* }}} */
#ifdef XCACHE_DEBUG
static void bbs_print(bbs_t *bbs, zend_op_array *op_array) /* {{{ */
{
int i;
for (i = 0; i < xc_stack_count(bbs); i ++) {
for (i = 0; i < xc_vector_size(bbs); i ++) {
bb_print(bbs_get(bbs, i), op_array);
}
}
/* }}} */
#endif
#define bbs_init(bbs) xc_stack_init_ex(bbs, 16)
static bb_t *bbs_add_bb(bbs_t *bbs, bb_t *bb) /* {{{ */
#define bbs_init(bbs) xc_vector_init(bb_t *, bbs, 0)
#define bbs_initializer() xc_vector_initializer(bb_t *, 0)
static bb_t *bbs_add_bb(bbs_t *bbs, bb_t *bb TSRMLS_DC) /* {{{ */
{
bb->id = (bbid_t) xc_stack_count(bbs);
xc_stack_push(bbs, (void *) bb);
bb->id = (bbid_t) bbs_count(bbs);
xc_vector_push_back(bbs, &bb);
return bb;
}
/* }}} */
static bb_t *bbs_new_bb_ex(bbs_t *bbs, zend_op *opcodes, int count) /* {{{ */
static bb_t *bbs_new_bb_ex(bbs_t *bbs, zend_op *opcodes, int count TSRMLS_DC) /* {{{ */
{
return bbs_add_bb(bbs, bb_new_ex(opcodes, count));
return bbs_add_bb(bbs, bb_new_ex(opcodes, count) TSRMLS_CC);
}
/* }}} */
static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count) /* {{{ */
static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count TSRMLS_DC) /* {{{ */
{
int i, start;
bb_t *bb;
@ -479,7 +480,7 @@ static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count) /* {{{
}
opline = op_array->opcodes + start;
bb = bbs_new_bb_ex(bbs, opline, i - start);
bb = bbs_new_bb_ex(bbs, opline, i - start TSRMLS_CC);
/* last */
opline = bb->opcodes + bb->count - 1;
@ -562,8 +563,6 @@ static void bbs_restore_opnum(bbs_t *bbs, zend_op_array *op_array) /* {{{ */
*/
static int xc_optimize_op_array(zend_op_array *op_array TSRMLS_DC) /* {{{ */
{
bbs_t bbs;
if (op_array->type != ZEND_USER_FUNCTION) {
return 0;
}
@ -578,8 +577,9 @@ static int xc_optimize_op_array(zend_op_array *op_array TSRMLS_DC) /* {{{ */
#endif
if (op_array_convert_switch(op_array) == SUCCESS) {
bbs_init(&bbs);
if (bbs_build_from(&bbs, op_array, op_array->last) == SUCCESS) {
bbs_t bbs = bbs_initializer();
if (bbs_build_from(&bbs, op_array, op_array->last TSRMLS_CC) == SUCCESS) {
int i;
#ifdef XCACHE_DEBUG
bbs_print(&bbs, op_array);
@ -591,7 +591,7 @@ static int xc_optimize_op_array(zend_op_array *op_array TSRMLS_DC) /* {{{ */
}
bbs_restore_opnum(&bbs, op_array);
}
bbs_destroy(&bbs);
bbs_destroy(&bbs TSRMLS_CC);
}
#ifdef XCACHE_DEBUG

@ -12,7 +12,7 @@ EXPORTED_FUNCTION(`$1 *xc_processor_store_$1(const xc_processor_storage_t *stora
processor.handle_reference = 1;
processor.relocatediff = storage->relocatediff;
IFAUTOCHECK(`xc_stack_init(&processor.allocsizes);')
IFAUTOCHECK(`xc_vector_init(unsigned long, &processor.allocsizes, 0);')
/* calc size */ {
zend_hash_init(&processor.strings, 0, NULL, NULL, 0);
@ -38,7 +38,7 @@ EXPORTED_FUNCTION(`$1 *xc_processor_store_$1(const xc_processor_storage_t *stora
`$1', `xc_entry_data_php_t', `SRC(`have_references') = processor.have_references;'
)
IFAUTOCHECK(`xc_stack_reverse(&processor.allocsizes);')
IFAUTOCHECK(`xc_vector_reverse(&processor.allocsizes);')
/* store {{{ */
{
IFAUTOCHECK(`char *oldp;')
@ -77,7 +77,7 @@ err_alloc:
}
/* }}} */
IFAUTOCHECK(`xc_stack_destroy(&processor.allocsizes);')
IFAUTOCHECK(`xc_vector_destroy(&processor.allocsizes);')
return dst;
}

@ -119,7 +119,7 @@ typedef struct _xc_processor_t {
const xc_op_array_info_t *active_op_array_infos_src;
zend_bool readonly_protection; /* wheather it's present */
IFAUTOCHECK(xc_stack_t allocsizes;)
IFAUTOCHECK(xc_vector_t allocsizes;)
} xc_processor_t;
dnl }}}
EXPORT(`typedef struct _xc_dasm_t { const zend_op_array *active_op_array_src; } xc_dasm_t;')
@ -191,7 +191,7 @@ IFAUTOCHECK(`
#undef C_RELAYLINE
#define C_RELAYLINE , __LINE__
')
static inline void xc_calc_string_n(xc_processor_t *processor, zend_uchar type, const_zstr str, long size IFAUTOCHECK(`, int relayline')) { /* {{{ */
static inline void xc_calc_string_n(xc_processor_t *processor, zend_uchar type, const_zstr str, long size IFAUTOCHECK(`, int relayline') TSRMLS_DC) { /* {{{ */
pushdef(`PROCESSOR_TYPE', `calc')
pushdef(`__LINE__', `relayline')
size_t realsize = UNISW(size, (type == IS_UNICODE) ? UBYTES(size) : size);

@ -43,20 +43,23 @@ define(`ALLOC', `
/* allocate */
IFCALC(`
IFAUTOCHECK(`
xc_stack_push(&processor->allocsizes, (void *) (long) (SIZE));
xc_stack_push(&processor->allocsizes, (void *) (long) (__LINE__));
{
unsigned long allocsize = SIZE, allocline = __LINE__;
xc_vector_push_back(&processor->allocsizes, &allocsize);
xc_vector_push_back(&processor->allocsizes, &allocline);
}
')
processor->size = (size_t) ALIGN(processor->size);
processor->size += SIZE;
')
IFSTORE(`
IFAUTOCHECK(`{
if (!xc_stack_count(&processor->allocsizes)) {
if (!xc_vector_size(&processor->allocsizes)) {
fprintf(stderr, "mismatch `$@' at line %d\n", __LINE__);
}
else {
unsigned long expect = (unsigned long) xc_stack_pop(&processor->allocsizes);
unsigned long atline = (unsigned long) xc_stack_pop(&processor->allocsizes);
unsigned long expect = xc_vector_pop_back(unsigned long, &processor->allocsizes);
unsigned long atline = xc_vector_pop_back(unsigned long, &processor->allocsizes);
unsigned long real = SIZE;
if (expect != real) {
fprintf(stderr, "mismatch `$@' at line %d(was %lu): real %lu - expect %lu = %lu\n", __LINE__, atline, real, expect, real - expect);

@ -58,7 +58,7 @@ define(`PROC_STRING_N_EX', `
fprintf(stderr, "\" len=%lu\n", (unsigned long) $3 - 1);
')
')
IFCALC(`xc_calc_string_n(processor, ISTYPE, SRCSTR, $3 C_RELAYLINE);')
IFCALC(`xc_calc_string_n(processor, ISTYPE, SRCSTR, $3 C_RELAYLINE TSRMLS_CC);')
IFSTORE(`DSTPTR = ifdef(`REALPTRTYPE', `(REALPTRTYPE() *)') ifelse(PTRTYPE,`char',`ZSTR_S',`ZSTR_U')(xc_store_string_n(processor, ISTYPE, SRCSTR, $3 C_RELAYLINE));')
IFRESTORE(`
DSTPTR = ifdef(`REALPTRTYPE', `(REALPTRTYPE() *)') STRDUP() (SRCPTR, ($3) - 1);

@ -1,66 +0,0 @@
#include <stdlib.h>
#include "xc_trace.h"
#include "xc_stack.h"
typedef xc_stack_t* S;
void xc_stack_init_ex(S stack, int initsize)
{
stack->cnt = 0;
stack->size = initsize;
stack->data = malloc(sizeof(void *) * stack->size);
}
void xc_stack_destroy(S stack)
{
free(stack->data);
}
void xc_stack_push(S stack, void *item)
{
if (stack->cnt == stack->size) {
stack->size <<= 1;
stack->data = realloc(stack->data, sizeof(void *) * stack->size);
}
stack->data[stack->cnt++] = item;
}
void* xc_stack_pop(S stack)
{
assert(stack != NULL);
assert(stack->size > 0);
return stack->data[--stack->cnt];
}
void* xc_stack_top(S stack)
{
assert(stack != NULL);
assert(stack->cnt > 0);
return stack->data[stack->cnt-1];
}
void* xc_stack_get(S stack, int n)
{
assert(stack != NULL);
assert(stack->cnt > 0);
return stack->data[n];
}
int xc_stack_count(S stack)
{
assert(stack != NULL);
return stack->cnt;
}
void xc_stack_reverse(S stack)
{
int i, j;
void *tmp;
assert(stack != NULL);
for (i = 0, j = stack->cnt - 1; i < j; i ++, j --) {
tmp = stack->data[i];
stack->data[i] = stack->data[j];
stack->data[j] = tmp;
}
}

@ -1,22 +0,0 @@
#ifndef __XC_UTIL_STACK
#define __XC_UTIL_STACK
typedef struct {
void **data;
int cnt;
int size;
} xc_stack_t;
#define S xc_stack_t*
void xc_stack_init_ex(S stack, int initsize);
#define xc_stack_init(stack) xc_stack_init_ex(stack, 8)
void xc_stack_destroy(S stack);
void xc_stack_push(S stack, void *item);
void *xc_stack_pop(S stack);
void *xc_stack_top(S stack);
void *xc_stack_get(S stack, int n);
int xc_stack_count(S stack);
void xc_stack_reverse(S stack);
#undef S
#endif /* __XC_UTIL_STACK */

@ -5,52 +5,118 @@
#pragma once
#endif /* _MSC_VER > 1000 */
#include <string.h>
#include <stdlib.h>
#include <assert.h>
typedef struct {
zend_uint size;
zend_uint cnt;
size_t size;
void *data;
size_t capacity;
size_t data_size;
int persistent;
} xc_vector_t;
#define xc_vector_init(type, vector) do { \
(vector)->cnt = 0; \
(vector)->size = 0; \
#define xc_vector_initializer(type, persistent_) { \
0, \
NULL, \
\
0, \
sizeof(type), \
persistent_, \
}
#define xc_vector_init(type, vector, persistent_) do { \
(vector)->size = 0; \
(vector)->data = NULL; \
\
(vector)->capacity = 0; \
(vector)->data_size = sizeof(type); \
(vector)->persistent = persistent_; \
} while (0)
#define xc_vector_add(type, vector, value) do { \
if ((vector)->cnt == (vector)->size) { \
if ((vector)->size) { \
(vector)->size <<= 1; \
(vector)->data = erealloc((vector)->data, sizeof(type) * (vector)->size); \
} \
else { \
(vector)->size = 8; \
(vector)->data = emalloc(sizeof(type) * (vector)->size); \
} \
} \
((type *) (vector)->data)[(vector)->cnt++] = value; \
static inline void xc_vector_destroy_impl(xc_vector_t *vector TSRMLS_DC)
{
if (vector->data) {
pefree(vector->data, vector->persistent);
}
vector->capacity = 0;
vector->size = 0;
}
#define xc_vector_destroy(vector) xc_vector_destroy_impl(vector TSRMLS_CC)
#define xc_vector_size(vector) ((vector)->size)
#define xc_vector_element_ptr_(vector, index) ( \
(void *) ( \
((char *) (vector)->data) + (index) * (vector)->data_size \
) \
)
static inline xc_vector_t *xc_vector_check_type_(xc_vector_t *vector, size_t data_size)
{
assert(vector->data_size = data_size);
return vector;
}
#define xc_vector_data(type, vector) ((type *) xc_vector_check_type_(vector, sizeof(type))->data)
static inline void xc_vector_check_reserve_(xc_vector_t *vector TSRMLS_DC)
{
if (vector->size == vector->capacity) {
if (vector->capacity) {
vector->capacity <<= 1;
vector->data = perealloc(vector->data, vector->data_size * vector->capacity, vector->persistent);
}
else {
vector->capacity = 8;
vector->data = pemalloc(vector->data_size * vector->capacity, vector->persistent);
}
}
}
#define xc_vector_push_back(vector, value_ptr) do { \
xc_vector_check_reserve_(vector TSRMLS_CC); \
memcpy(xc_vector_element_ptr_(vector, (vector)->size++), value_ptr, (vector)->data_size); \
} while (0)
static inline void *xc_vector_detach_impl(xc_vector_t *vector)
{
void *data = vector->data;
vector->data = NULL;
vector->capacity = 0;
vector->size = 0;
vector->cnt = 0;
return data;
}
#define xc_vector_detach(type, vector) ((type *) xc_vector_detach_impl(vector))
#define xc_vector_detach(type, vector) ((type *) xc_vector_detach_impl(xc_vector_check_type_(vector, sizeof(type))))
static inline void xc_vector_free_impl(xc_vector_t *vector TSRMLS_DC)
static inline xc_vector_t *xc_vector_pop_back_check_(xc_vector_t *vector, size_t data_size)
{
if (vector->data) {
efree(vector->data);
}
vector->size = 0;
vector->cnt = 0;
assert(vector);
assert(vector->data_size == data_size);
assert(vector->capacity > 0);
return vector;
}
#define xc_vector_free(type, vector) xc_vector_free_impl(vector TSRMLS_CC)
#define xc_vector_pop_back(type, vector) xc_vector_data(type, \
xc_vector_pop_back_check_(vector, sizeof(type)) \
)[--(vector)->size]
static inline void xc_vector_reverse(xc_vector_t *vector)
{
char *left, *right;
void *tmp;
assert(vector);
tmp = alloca(vector->data_size);
for (left = vector->data, right = xc_vector_element_ptr_(vector, vector->size - 1); left < right; left += vector->data_size, right -= vector->data_size) {
memcpy(tmp, left, vector->data_size);
memcpy(left, right, vector->data_size);
memcpy(right, tmp, vector->data_size);
}
}
#endif /* XC_VECTOR_H_0957AC4E1A44E838C7B8DBECFF9C4B3B */

@ -0,0 +1,38 @@
#define TSRMLS_DC
#define TSRMLS_CC
#define pemalloc(size, p) malloc(size)
#define perealloc(ptr, size, p) realloc(ptr, size)
#define pefree(ptr, p) free(ptr)
#include <stdio.h>
#include "xc_vector.h"
#undef CHECK
#define CHECK(a, msg) do { \
if (!(a)) { \
fprintf(stderr, "%s\n", msg); return -1; \
} \
} while (0)
int main() /* {{{ */
{
xc_vector_t vector = xc_vector_initializer(int, 0);
int t;
t = 1; xc_vector_push_back(&vector, &t);
t = 2; xc_vector_push_back(&vector, &t);
t = 3; xc_vector_push_back(&vector, &t);
xc_vector_reverse(&vector);
t = xc_vector_pop_back(int, &vector);
CHECK(t == 1, "not 1");
t = xc_vector_pop_back(int, &vector);
CHECK(t == 2, "not 2");
t = xc_vector_pop_back(int, &vector);
CHECK(t == 3, "not 3");
xc_vector_destroy(&vector);
return 0;
}
/* }}} */

@ -26,7 +26,7 @@
#include "xcache/xc_const_string.h"
#include "xcache/xc_opcode_spec.h"
#include "xcache/xc_utils.h"
#include "util/xc_stack.h"
#include "util/xc_vector.h"
#include "php.h"
#include "ext/standard/info.h"
@ -150,7 +150,7 @@ void xc_shutdown_globals(zend_xcache_globals* xcache_globals TSRMLS_DC)
if (xcache_globals->php_holds != NULL) {
for (i = 0; i < xcache_globals->php_holds_size; i ++) {
xc_stack_destroy(&xcache_globals->php_holds[i]);
xc_vector_destroy(&xcache_globals->php_holds[i]);
}
free(xcache_globals->php_holds);
xcache_globals->php_holds = NULL;
@ -159,7 +159,7 @@ void xc_shutdown_globals(zend_xcache_globals* xcache_globals TSRMLS_DC)
if (xcache_globals->var_holds != NULL) {
for (i = 0; i < xcache_globals->var_holds_size; i ++) {
xc_stack_destroy(&xcache_globals->var_holds[i]);
xc_vector_destroy(&xcache_globals->var_holds[i]);
}
free(xcache_globals->var_holds);
xcache_globals->var_holds = NULL;

@ -5,7 +5,6 @@
#pragma once
#endif /* _MSC_VER > 1000 */
#include "util/xc_stack.h"
#include "zend_extensions.h"
int xcache_zend_extension_add(zend_extension *new_extension, zend_bool prepend);
int xcache_zend_extension_remove(zend_extension *extension);

@ -1,4 +1,4 @@
#include "util/xc_stack.h"
#include "util/xc_vector.h"
ZEND_BEGIN_MODULE_GLOBALS(xcache)
zend_bool initial_compile_file_called; /* true if origin_compile_file is called */
@ -17,9 +17,9 @@ ZEND_BEGIN_MODULE_GLOBALS(xcache)
#ifndef ZEND_WIN32
pid_t holds_pid;
#endif
xc_stack_t *php_holds;
xc_vector_t *php_holds;
zend_uint php_holds_size;
xc_stack_t *var_holds;
xc_vector_t *var_holds;
zend_uint var_holds_size;
time_t request_time;
long var_ttl;

Loading…
Cancel
Save