Debug output uses local buffer to avoid clashes between threads.

This commit is contained in:
Maria Matejka 2021-05-26 16:42:02 +02:00
parent eb20251655
commit 227e2d5541

View file

@ -309,22 +309,15 @@ die(const char *msg, ...)
void void
debug(const char *msg, ...) debug(const char *msg, ...)
{ {
#define MAX_DEBUG_BUFSIZE 65536 #define MAX_DEBUG_BUFSIZE 16384
va_list args; va_list args;
static uint bufsize = 4096; char buf[MAX_DEBUG_BUFSIZE];
static char *buf = NULL;
if (!buf)
buf = mb_alloc(&root_pool, bufsize);
va_start(args, msg); va_start(args, msg);
if (dbgf) if (dbgf)
{ {
while (bvsnprintf(buf, bufsize, msg, args) < 0) if (bvsnprintf(buf, MAX_DEBUG_BUFSIZE, msg, args) < 0)
if (bufsize >= MAX_DEBUG_BUFSIZE) bug("Extremely long debug output, split it.");
bug("Extremely long debug output, split it.");
else
buf = mb_realloc(buf, (bufsize *= 2));
fputs(buf, dbgf); fputs(buf, dbgf);
} }