summaryrefslogtreecommitdiff
path: root/processor
diff options
context:
space:
mode:
authorXuefer <xuefer@gmail.com>2014-11-08 07:38:45 +0000
committerXuefer <xuefer@gmail.com>2014-11-08 07:38:45 +0000
commitf664f5a518600b71055ffe871c16440439a25f2f (patch)
tree14fa36604ce00d4cf04b185e20bd02c006278f54 /processor
parentc130a0d58900e7a024135a328dedb112df109995 (diff)
downloadxcache-f664f5a518600b71055ffe871c16440439a25f2f.tar.gz
xcache-f664f5a518600b71055ffe871c16440439a25f2f.zip
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
Diffstat (limited to 'processor')
-rw-r--r--processor/foot.m46
-rw-r--r--processor/head.m44
-rw-r--r--processor/main.m413
-rw-r--r--processor/string.m42
4 files changed, 14 insertions, 11 deletions
diff --git a/processor/foot.m4 b/processor/foot.m4
index f6f39cb..c22e97e 100644
--- a/processor/foot.m4
+++ b/processor/foot.m4
@@ -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;
}
diff --git a/processor/head.m4 b/processor/head.m4
index e360836..36dbddc 100644
--- a/processor/head.m4
+++ b/processor/head.m4
@@ -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);
diff --git a/processor/main.m4 b/processor/main.m4
index d4fa0c1..5a9ba25 100644
--- a/processor/main.m4
+++ b/processor/main.m4
@@ -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);
diff --git a/processor/string.m4 b/processor/string.m4
index 6653912..5b1f592 100644
--- a/processor/string.m4
+++ b/processor/string.m4
@@ -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);