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-c2e55f420ca7master
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
|
||||
|
@ -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
|
||||
|
@ -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 */
|
@ -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;
|
||||
}
|
||||
/* }}} */
|
Loading…
Reference in New Issue