}
/*********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;
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;
}
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);