Changeset 1551 in svn


Ignore:
Timestamp:
2014-11-08T07:38:45Z (5 years ago)
Author:
Xuefer
Message:

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

Location:
trunk
Files:
1 added
2 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile.frag.deps

    r1444 r1551  
    11$(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
    22mod_assembler/xc_assembler.lo $(builddir)/mod_assembler/xc_assembler.lo:
    3 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
    4 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
     3mod_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
     4mod_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
    55mod_decoder/xc_decoder.lo $(builddir)/mod_decoder/xc_decoder.lo:
    66mod_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
    77mod_encoder/xc_encoder.lo $(builddir)/mod_encoder/xc_encoder.lo:
    8 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
    9 util/xc_stack.lo $(builddir)/util/xc_stack.lo: $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h
     8mod_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
    109util/xc_trace.lo $(builddir)/util/xc_trace.lo: $(srcdir)/util/xc_trace.h
    11 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
     10xcache.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
    1211xcache/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
    1312xcache/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
    1413xcache/xc_compatibility.lo $(builddir)/xcache/xc_compatibility.lo: $(srcdir)/xcache/xc_compatibility.h
    15 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
    16 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
     14xcache/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
     15xcache/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
    1716xcache/xc_ini.lo $(builddir)/xcache/xc_ini.lo: $(srcdir)/xcache/xc_ini.h
    1817xcache/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
     
    2019xcache/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
    2120xcache/xc_processor.lo $(builddir)/xcache/xc_processor.lo: $(XCACHE_PROC_C)
    22 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
     21xcache/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
    2322xcache/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
    2423xcache/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
    25 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
     24xcache/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
  • trunk/config.m4

    r1473 r1551  
    2626  xcache_sources="xcache.c"
    2727  for i in \
    28 xc_stack.c \
    2928xc_trace.c \
    3029; do
  • trunk/config.w32

    r1473 r1551  
    1414
    1515    ADD_SOURCES(configure_module_dirname + "/util", " \
    16 xc_stack.c \
    1716xc_trace.c \
    1817", "xcache");
  • trunk/devel/run

    r1550 r1551  
    4040
    4141xtest() { # {{{1
    42     $MAKE ${MAKEOPTS} -f devel/test.mak
     42    $MAKE ${MAKEOPTS} -f devel/test.mak clean all
    4343}
    4444
  • trunk/devel/test.mak

    r1135 r1551  
    11#! /usr/bin/make -f
    22
    3 EXES=allocator_test
    4 OBJS=allocator.o
    53CC=gcc
     4LDFLAGS=
    65CFLAGS=-g -O0 -I. -D TEST -D HAVE_XCACHE_TEST -Wall
    76TEST=valgrind
    87
    9 all: allocator
     8all: allocator vector
    109
    1110allocator_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
    12     $(CC) $(CFLAGS) -o allocator_test xcache/xc_allocator.c xcache/xc_malloc.c xcache/xc_allocator_bestfit.c util/xc_trace.c
     11    $(CC) $(LDFLAGS) $(CFLAGS) -o allocator_test xcache/xc_allocator.c xcache/xc_malloc.c xcache/xc_allocator_bestfit.c util/xc_trace.c
    1312   
    1413allocator: allocator_test
    1514    $(TEST) ./allocator_test
    1615
     16vector_test: util/xc_vector_test.c
     17    $(CC) $(LDFLAGS) $(CFLAGS) -o vector_test util/xc_vector_test.c
     18   
     19vector: vector_test
     20    $(TEST) ./vector_test
     21
    1722clean:
    18     rm -f $(OBJS) $(EXES)
     23    rm -f allocator_test vector_test
  • trunk/mod_cacher/xc_cacher.c

    r1538 r1551  
    433433#endif
    434434    entry->refcount ++;
    435     xc_stack_push(&XG(php_holds)[cache->cacheid], (void *)entry);
     435    xc_vector_push_back(&XG(php_holds)[cache->cacheid], &entry);
    436436}
    437437/* }}} */
     
    872872/* }}} */
    873873
    874 static inline void xc_entry_unholds_real(xc_stack_t *holds, xc_cache_t *caches, size_t cachecount TSRMLS_DC) /* {{{ */
     874static inline void xc_entry_unholds_real(xc_vector_t *holds, xc_cache_t *caches, size_t cachecount TSRMLS_DC) /* {{{ */
    875875{
    876876    size_t i;
    877     xc_stack_t *s;
     877    xc_vector_t *v;
    878878    xc_cache_t *cache;
    879879    xc_entry_php_t *entry_php;
    880880
    881881    for (i = 0; i < cachecount; i ++) {
    882         s = &holds[i];
    883         TRACE("holded %d items", xc_stack_count(s));
    884         if (xc_stack_count(s)) {
     882        v = &holds[i];
     883        TRACE("holded %d items", v->cnt);
     884        if (xc_vector_size(v)) {
    885885            cache = &caches[i];
    886886            ENTER_LOCK(cache) {
    887                 while (xc_stack_count(s)) {
    888                     entry_php = (xc_entry_php_t *) xc_stack_pop(s);
     887                while (xc_vector_size(v)) {
     888                    entry_php = xc_vector_pop_back(xc_entry_php_t *, v);
    889889                    TRACE("unhold %lu:%s", (unsigned long) entry_php->file_inode, entry_php->entry.name.str.val);
    890890                    assert(entry_php->refcount > 0);
     
    14101410{
    14111411    uint index;
    1412     xc_vector_t constantinfos;
    1413 
    1414     xc_vector_init(xc_constant_info_t, &constantinfos);
     1412    xc_vector_t constantinfos = xc_vector_initializer(xc_constant_info_t, 0);
    14151413
    14161414    for (index = 0; index < constants->nTableSize; ++index) {
     
    14391437                detail.index = index2 * constants->nTableSize + index;
    14401438                detail.info  = constantinfo;
    1441                 xc_vector_add(xc_constant_info_t, &constantinfos, detail);
    1442             }
    1443         }
    1444     }
    1445 
    1446     classinfo->constantinfo_cnt = constantinfos.cnt;
     1439                xc_vector_push_back(&constantinfos, &detail);
     1440            }
     1441        }
     1442    }
     1443
     1444    classinfo->constantinfo_cnt = xc_vector_size(&constantinfos);
    14471445    classinfo->constantinfos    = xc_vector_detach(xc_constant_info_t, &constantinfos);
    14481446}
     
    14561454    zend_uint oplinenum;
    14571455#endif
    1458     xc_vector_t constantinfos;
    1459 
    1460     xc_vector_init(xc_constant_info_t, &constantinfos);
     1456    xc_vector_t constantinfos = xc_vector_initializer(xc_constant_info_t, 0);
    14611457
    14621458#ifdef ZEND_ENGINE_2_4
     
    14811477            detail.index = literalindex;
    14821478            detail.info  = constantinfo;
    1483             xc_vector_add(xc_constant_info_t, &constantinfos, detail);
    1484         }
    1485     }
    1486 
    1487     op_array_info->constantinfo_cnt = constantinfos.cnt;
    1488     op_array_info->constantinfos    = xc_vector_detach(xc_constant_info_t, &constantinfos);
     1479            xc_vector_push_back(&constantinfos, &detail);
     1480        }
     1481    }
    14891482#else /* ZEND_ENGINE_2_4 */
    14901483    for (oplinenum = 0; oplinenum < op_array->last; oplinenum++) {
     
    15311524        }
    15321525    }
    1533 
    1534     op_array_info->constantinfo_cnt = constantinfos.cnt;
     1526#endif /* ZEND_ENGINE_2_4 */
     1527
     1528    op_array_info->constantinfo_cnt = xc_vector_size(&constantinfos);
    15351529    op_array_info->constantinfos    = xc_vector_detach(xc_constant_info_t, &constantinfos);
    1536 #endif /* ZEND_ENGINE_2_4 */
    1537     xc_vector_free(xc_constant_info_t, &constantinfos);
     1530    xc_vector_destroy(&constantinfos);
    15381531}
    15391532/* }}} */
     
    28272820    if (xc_php_caches && !XG(php_holds)) {
    28282821        XG(php_holds_size) = xc_php_hcache.size;
    2829         XG(php_holds) = calloc(XG(php_holds_size), sizeof(xc_stack_t));
     2822        XG(php_holds) = calloc(XG(php_holds_size), sizeof(xc_vector_t));
    28302823        for (i = 0; i < xc_php_hcache.size; i ++) {
    2831             xc_stack_init(&XG(php_holds[i]));
     2824            xc_vector_init(xc_entry_php_t *, &XG(php_holds[i]), 1);
    28322825        }
    28332826    }
     
    28352828    if (xc_var_caches && !XG(var_holds)) {
    28362829        XG(var_holds_size) = xc_var_hcache.size;
    2837         XG(var_holds) = calloc(XG(var_holds_size), sizeof(xc_stack_t));
     2830        XG(var_holds) = calloc(XG(var_holds_size), sizeof(xc_vector_t));
    28382831        for (i = 0; i < xc_var_hcache.size; i ++) {
    2839             xc_stack_init(&XG(var_holds[i]));
     2832            xc_vector_init(xc_entry_php_t *, &XG(var_holds[i]), 1);
    28402833        }
    28412834    }
     
    28482841    if (xc_php_caches && XG(php_holds)) {
    28492842        for (i = 0; i < XG(php_holds_size); i ++) {
    2850             xc_stack_destroy(&XG(php_holds[i]));
     2843            xc_vector_destroy(&XG(php_holds[i]));
    28512844        }
    28522845        free(XG(php_holds));
     
    28572850    if (xc_var_caches && XG(var_holds)) {
    28582851        for (i = 0; i < XG(var_holds_size); i ++) {
    2859             xc_stack_destroy(&XG(var_holds[i]));
     2852            xc_vector_destroy(&XG(var_holds[i]));
    28602853        }
    28612854        free(XG(var_holds));
  • trunk/mod_coverager/xc_coverager.c

    r1538 r1551  
    1414#include "xcache/xc_ini.h"
    1515#include "xcache/xc_utils.h"
    16 #include "util/xc_stack.h"
     16#include "util/xc_vector.h"
    1717#include "util/xc_trace.h"
    1818#include "xcache_globals.h"
  • trunk/mod_optimizer/xc_optimizer.c

    r1532 r1551  
    33#include "xcache/xc_ini.h"
    44#include "xcache/xc_utils.h"
    5 #include "util/xc_stack.h"
     5#include "util/xc_vector.h"
    66#include "util/xc_trace.h"
    77#include "xcache_globals.h"
     
    4747
    4848/* basic blocks */
    49 typedef xc_stack_t bbs_t;
     49typedef xc_vector_t bbs_t;
    5050
    5151/* op array helper functions */
     
    353353static bb_t *bbs_get(bbs_t *bbs, int n) /* {{{ */
    354354{
    355     return (bb_t *) xc_stack_get(bbs, n);
     355    return xc_vector_data(bb_t *, bbs)[n];
    356356}
    357357/* }}} */
    358358static int bbs_count(bbs_t *bbs) /* {{{ */
    359359{
    360     return xc_stack_count(bbs);
    361 }
    362 /* }}} */
    363 static void bbs_destroy(bbs_t *bbs) /* {{{ */
     360    return xc_vector_size(bbs);
     361}
     362/* }}} */
     363static void bbs_destroy(bbs_t *bbs TSRMLS_DC) /* {{{ */
    364364{
    365365    bb_t *bb;
    366366    while (bbs_count(bbs)) {
    367         bb = (bb_t *) xc_stack_pop(bbs);
     367        bb = xc_vector_pop_back(bb_t *, bbs);
    368368        bb_destroy(bb);
    369369    }
    370     xc_stack_destroy(bbs);
     370    xc_vector_destroy(bbs);
    371371}
    372372/* }}} */
     
    375375{
    376376    int i;
    377     for (i = 0; i < xc_stack_count(bbs); i ++) {
     377    for (i = 0; i < xc_vector_size(bbs); i ++) {
    378378        bb_print(bbs_get(bbs, i), op_array);
    379379    }
     
    381381/* }}} */
    382382#endif
    383 #define bbs_init(bbs) xc_stack_init_ex(bbs, 16)
    384 static bb_t *bbs_add_bb(bbs_t *bbs, bb_t *bb) /* {{{ */
    385 {
    386     bb->id = (bbid_t) xc_stack_count(bbs);
    387     xc_stack_push(bbs, (void *) bb);
     383#define bbs_init(bbs) xc_vector_init(bb_t *, bbs, 0)
     384#define bbs_initializer() xc_vector_initializer(bb_t *, 0)
     385static bb_t *bbs_add_bb(bbs_t *bbs, bb_t *bb TSRMLS_DC) /* {{{ */
     386{
     387    bb->id = (bbid_t) bbs_count(bbs);
     388    xc_vector_push_back(bbs, &bb);
    388389    return bb;
    389390}
    390391/* }}} */
    391 static bb_t *bbs_new_bb_ex(bbs_t *bbs, zend_op *opcodes, int count) /* {{{ */
    392 {
    393     return bbs_add_bb(bbs, bb_new_ex(opcodes, count));
    394 }
    395 /* }}} */
    396 static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count) /* {{{ */
     392static bb_t *bbs_new_bb_ex(bbs_t *bbs, zend_op *opcodes, int count TSRMLS_DC) /* {{{ */
     393{
     394    return bbs_add_bb(bbs, bb_new_ex(opcodes, count) TSRMLS_CC);
     395}
     396/* }}} */
     397static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count TSRMLS_DC) /* {{{ */
    397398{
    398399    int i, start;
     
    480481
    481482        opline = op_array->opcodes + start;
    482         bb = bbs_new_bb_ex(bbs, opline, i - start);
     483        bb = bbs_new_bb_ex(bbs, opline, i - start TSRMLS_CC);
    483484
    484485        /* last */
     
    563564static int xc_optimize_op_array(zend_op_array *op_array TSRMLS_DC) /* {{{ */
    564565{
    565     bbs_t bbs;
    566 
    567566    if (op_array->type != ZEND_USER_FUNCTION) {
    568567        return 0;
     
    579578
    580579    if (op_array_convert_switch(op_array) == SUCCESS) {
    581         bbs_init(&bbs);
    582         if (bbs_build_from(&bbs, op_array, op_array->last) == SUCCESS) {
     580        bbs_t bbs = bbs_initializer();
     581
     582        if (bbs_build_from(&bbs, op_array, op_array->last TSRMLS_CC) == SUCCESS) {
    583583            int i;
    584584#ifdef XCACHE_DEBUG
     
    592592            bbs_restore_opnum(&bbs, op_array);
    593593        }
    594         bbs_destroy(&bbs);
     594        bbs_destroy(&bbs TSRMLS_CC);
    595595    }
    596596
  • trunk/processor/foot.m4

    r1470 r1551  
    1313    processor.relocatediff = storage->relocatediff;
    1414
    15     IFAUTOCHECK(`xc_stack_init(&processor.allocsizes);')
     15    IFAUTOCHECK(`xc_vector_init(unsigned long, &processor.allocsizes, 0);')
    1616
    1717    /* calc size */ {
     
    3939    )
    4040
    41     IFAUTOCHECK(`xc_stack_reverse(&processor.allocsizes);')
     41    IFAUTOCHECK(`xc_vector_reverse(&processor.allocsizes);')
    4242    /* store {{{ */
    4343    {
     
    7878    /* }}} */
    7979
    80     IFAUTOCHECK(`xc_stack_destroy(&processor.allocsizes);')
     80    IFAUTOCHECK(`xc_vector_destroy(&processor.allocsizes);')
    8181
    8282    return dst;
  • trunk/processor/head.m4

    r1546 r1551  
    120120
    121121    zend_bool readonly_protection; /* wheather it's present */
    122 IFAUTOCHECK(xc_stack_t allocsizes;)
     122IFAUTOCHECK(xc_vector_t allocsizes;)
    123123} xc_processor_t;
    124124dnl }}}
     
    192192#define C_RELAYLINE , __LINE__
    193193')
    194 static inline void xc_calc_string_n(xc_processor_t *processor, zend_uchar type, const_zstr str, long size IFAUTOCHECK(`, int relayline')) { /* {{{ */
     194static inline void xc_calc_string_n(xc_processor_t *processor, zend_uchar type, const_zstr str, long size IFAUTOCHECK(`, int relayline') TSRMLS_DC) { /* {{{ */
    195195    pushdef(`PROCESSOR_TYPE', `calc')
    196196    pushdef(`__LINE__', `relayline')
  • trunk/processor/main.m4

    r1492 r1551  
    4444    IFCALC(`
    4545        IFAUTOCHECK(`
    46             xc_stack_push(&processor->allocsizes, (void *) (long) (SIZE));
    47             xc_stack_push(&processor->allocsizes, (void *) (long) (__LINE__));
     46            {
     47                unsigned long allocsize = SIZE, allocline = __LINE__;
     48                xc_vector_push_back(&processor->allocsizes, &allocsize);
     49                xc_vector_push_back(&processor->allocsizes, &allocline);
     50            }
    4851        ')
    4952        processor->size = (size_t) ALIGN(processor->size);
     
    5255    IFSTORE(`
    5356        IFAUTOCHECK(`{
    54             if (!xc_stack_count(&processor->allocsizes)) {
     57            if (!xc_vector_size(&processor->allocsizes)) {
    5558                fprintf(stderr, "mismatch `$@' at line %d\n", __LINE__);
    5659            }
    5760            else {
    58                 unsigned long expect = (unsigned long) xc_stack_pop(&processor->allocsizes);
    59                 unsigned long atline = (unsigned long) xc_stack_pop(&processor->allocsizes);
     61                unsigned long expect = xc_vector_pop_back(unsigned long, &processor->allocsizes);
     62                unsigned long atline = xc_vector_pop_back(unsigned long, &processor->allocsizes);
    6063                unsigned long real = SIZE;
    6164                if (expect != real) {
  • trunk/processor/string.m4

    r1471 r1551  
    5959            ')
    6060        ')
    61         IFCALC(`xc_calc_string_n(processor, ISTYPE, SRCSTR, $3 C_RELAYLINE);')
     61        IFCALC(`xc_calc_string_n(processor, ISTYPE, SRCSTR, $3 C_RELAYLINE TSRMLS_CC);')
    6262        IFSTORE(`DSTPTR = ifdef(`REALPTRTYPE', `(REALPTRTYPE() *)') ifelse(PTRTYPE,`char',`ZSTR_S',`ZSTR_U')(xc_store_string_n(processor, ISTYPE, SRCSTR, $3 C_RELAYLINE));')
    6363        IFRESTORE(`
  • trunk/util/xc_vector.h

    r1044 r1551  
    66#endif /* _MSC_VER > 1000 */
    77
     8#include <string.h>
     9#include <stdlib.h>
     10#include <assert.h>
     11
    812typedef struct {
    9     zend_uint size;
    10     zend_uint cnt;
     13    size_t size;
    1114    void *data;
     15
     16    size_t capacity;
     17    size_t data_size;
     18    int persistent;
    1219} xc_vector_t;
    1320
    14 #define xc_vector_init(type, vector) do { \
    15     (vector)->cnt = 0;     \
    16     (vector)->size = 0;    \
     21#define xc_vector_initializer(type, persistent_) { \
     22    0, \
     23    NULL, \
     24\
     25    0, \
     26    sizeof(type), \
     27    persistent_, \
     28}
     29
     30#define xc_vector_init(type, vector, persistent_) do { \
     31    (vector)->size = 0; \
    1732    (vector)->data = NULL; \
     33\
     34    (vector)->capacity = 0; \
     35    (vector)->data_size = sizeof(type); \
     36    (vector)->persistent = persistent_; \
    1837} while (0)
    1938
    20 #define xc_vector_add(type, vector, value) do { \
    21     if ((vector)->cnt == (vector)->size) { \
    22         if ((vector)->size) { \
    23             (vector)->size <<= 1; \
    24             (vector)->data = erealloc((vector)->data, sizeof(type) * (vector)->size); \
    25         } \
    26         else { \
    27             (vector)->size = 8; \
    28             (vector)->data = emalloc(sizeof(type) * (vector)->size); \
    29         } \
    30     } \
    31     ((type *) (vector)->data)[(vector)->cnt++] = value; \
     39static inline void xc_vector_destroy_impl(xc_vector_t *vector TSRMLS_DC)
     40{
     41    if (vector->data) {
     42        pefree(vector->data, vector->persistent);
     43    }
     44    vector->capacity = 0;
     45    vector->size = 0;
     46}
     47
     48#define xc_vector_destroy(vector) xc_vector_destroy_impl(vector TSRMLS_CC)
     49
     50#define xc_vector_size(vector) ((vector)->size)
     51#define xc_vector_element_ptr_(vector, index) ( \
     52    (void *) ( \
     53        ((char *) (vector)->data) + (index) * (vector)->data_size \
     54    ) \
     55)
     56
     57static inline xc_vector_t *xc_vector_check_type_(xc_vector_t *vector, size_t data_size)
     58{
     59    assert(vector->data_size = data_size);
     60    return vector;
     61}
     62
     63#define xc_vector_data(type, vector) ((type *) xc_vector_check_type_(vector, sizeof(type))->data)
     64
     65static inline void xc_vector_check_reserve_(xc_vector_t *vector TSRMLS_DC)
     66{
     67    if (vector->size == vector->capacity) {
     68        if (vector->capacity) {
     69            vector->capacity <<= 1;
     70            vector->data = perealloc(vector->data, vector->data_size * vector->capacity, vector->persistent);
     71        }
     72        else {
     73            vector->capacity = 8;
     74            vector->data = pemalloc(vector->data_size * vector->capacity, vector->persistent);
     75        }
     76    }
     77}
     78
     79#define xc_vector_push_back(vector, value_ptr) do { \
     80    xc_vector_check_reserve_(vector TSRMLS_CC); \
     81    memcpy(xc_vector_element_ptr_(vector, (vector)->size++), value_ptr, (vector)->data_size); \
    3282} while (0)
    3383
     
    3585{
    3686    void *data = vector->data;
     87
    3788    vector->data = NULL;
     89    vector->capacity = 0;
    3890    vector->size = 0;
    39     vector->cnt = 0;
    4091    return data;
    4192}
    4293
    43 #define xc_vector_detach(type, vector) ((type *) xc_vector_detach_impl(vector))
     94#define xc_vector_detach(type, vector) ((type *) xc_vector_detach_impl(xc_vector_check_type_(vector, sizeof(type))))
    4495
    45 static inline void xc_vector_free_impl(xc_vector_t *vector TSRMLS_DC)
     96static inline xc_vector_t *xc_vector_pop_back_check_(xc_vector_t *vector, size_t data_size)
    4697{
    47     if (vector->data) {
    48         efree(vector->data);
    49     }
    50     vector->size = 0;
    51     vector->cnt = 0;
     98    assert(vector);
     99    assert(vector->data_size == data_size);
     100    assert(vector->capacity > 0);
     101    return vector;
    52102}
    53103
    54 #define xc_vector_free(type, vector) xc_vector_free_impl(vector TSRMLS_CC)
     104#define xc_vector_pop_back(type, vector) xc_vector_data(type, \
     105    xc_vector_pop_back_check_(vector, sizeof(type)) \
     106)[--(vector)->size]
     107
     108static inline void xc_vector_reverse(xc_vector_t *vector)
     109{
     110    char *left, *right;
     111    void *tmp;
     112
     113    assert(vector);
     114    tmp = alloca(vector->data_size);
     115    for (left = vector->data, right = xc_vector_element_ptr_(vector, vector->size - 1); left < right; left += vector->data_size, right -= vector->data_size) {
     116        memcpy(tmp, left, vector->data_size);
     117        memcpy(left, right, vector->data_size);
     118        memcpy(right, tmp, vector->data_size);
     119    }
     120}
    55121
    56122#endif /* XC_VECTOR_H_0957AC4E1A44E838C7B8DBECFF9C4B3B */
  • trunk/xcache.c

    r1523 r1551  
    2727#include "xcache/xc_opcode_spec.h"
    2828#include "xcache/xc_utils.h"
    29 #include "util/xc_stack.h"
     29#include "util/xc_vector.h"
    3030
    3131#include "php.h"
     
    151151    if (xcache_globals->php_holds != NULL) {
    152152        for (i = 0; i < xcache_globals->php_holds_size; i ++) {
    153             xc_stack_destroy(&xcache_globals->php_holds[i]);
     153            xc_vector_destroy(&xcache_globals->php_holds[i]);
    154154        }
    155155        free(xcache_globals->php_holds);
     
    160160    if (xcache_globals->var_holds != NULL) {
    161161        for (i = 0; i < xcache_globals->var_holds_size; i ++) {
    162             xc_stack_destroy(&xcache_globals->var_holds[i]);
     162            xc_vector_destroy(&xcache_globals->var_holds[i]);
    163163        }
    164164        free(xcache_globals->var_holds);
  • trunk/xcache/xc_extension.h

    r1047 r1551  
    66#endif /* _MSC_VER > 1000 */
    77
    8 #include "util/xc_stack.h"
    98#include "zend_extensions.h"
    109int xcache_zend_extension_add(zend_extension *new_extension, zend_bool prepend);
  • trunk/xcache_globals.h

    r1381 r1551  
    1 #include "util/xc_stack.h"
     1#include "util/xc_vector.h"
    22
    33ZEND_BEGIN_MODULE_GLOBALS(xcache)
     
    1818    pid_t holds_pid;
    1919#endif
    20     xc_stack_t *php_holds;
     20    xc_vector_t *php_holds;
    2121    zend_uint php_holds_size;
    22     xc_stack_t *var_holds;
     22    xc_vector_t *var_holds;
    2323    zend_uint var_holds_size;
    2424    time_t request_time;
Note: See TracChangeset for help on using the changeset viewer.