From: teodor Date: Wed, 17 Mar 2010 15:59:44 +0000 (+0000) Subject: StrinBuffer now can work both with and without memory context X-Git-Url: http://www.sigaev.ru/git/gitweb.cgi?p=tedtools.git;a=commitdiff_plain;h=97949d6c025ec892ff5ae21e32014b2f23218571 StrinBuffer now can work both with and without memory context --- diff --git a/tmalloc.c b/tmalloc.c index 8b16322..2d45bc6 100644 --- a/tmalloc.c +++ b/tmalloc.c @@ -298,11 +298,15 @@ mcnstrdup(MemoryContext *cntx, char *src, int len) { } /*********StringBuffer********/ + +#define SBALLOC(s) ( ( (s)->mc ) ? mcalloc((s)->mc, (s)->len) : tmalloc((s)->len) ) +#define SBREALLOC(s) ( ( (s)->mc ) ? mcrealloc((s)->buf, (s)->len) : trealloc((s)->buf, (s)->len) ) + StringBuffer* initStringBuffer(StringBuffer* state, MemoryContext *mc, int initsize) { state->len = (initsize>0) ? initsize : 1024; state->mc = mc; - state->ptr = state->buf = (char*)mcalloc(state->mc, state->len); + state->ptr = state->buf = (char*)SBALLOC(state); *(state->ptr) ='\0'; return state; @@ -323,7 +327,7 @@ appendStringBuffer( StringBuffer *state, char *string, int stringlen) { int diff = state->ptr - state->buf; state->len *= 2; - state->buf = (char*)mcrealloc( (void*)state->buf, state->len ); + state->buf = (char*)SBREALLOC(state); state->ptr = state->buf + diff; } @@ -354,7 +358,7 @@ printStringBuffer( StringBuffer *state, const char *format, ...) { state->len *= 2; } while( state->ptr - state->buf + printedlen >= state->len ); - state->buf = (char*)mcrealloc( (void*)state->buf, state->len ); + state->buf = (char*)SBREALLOC(state); state->ptr = state->buf + curlen; va_start(args, format); printedlen = vsnprintf(state->ptr, printedlen+1, format, args);