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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.