提交 00b0d7f7 编写于 作者: J Junio C Hamano

set_try_to_free_routine(NULL) means "do nothing special"

This way, the next caller that wants to disable our memory reclamation
machinery does not have to define its own do_nothing() stub.
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 6068ac88
...@@ -25,10 +25,6 @@ ...@@ -25,10 +25,6 @@
#include "cache.h" #include "cache.h"
#include "quote.h" #include "quote.h"
static void do_nothing(size_t unused)
{
}
/* Get a trace file descriptor from GIT_TRACE env variable. */ /* Get a trace file descriptor from GIT_TRACE env variable. */
static int get_trace_fd(int *need_close) static int get_trace_fd(int *need_close)
{ {
...@@ -76,7 +72,7 @@ void trace_printf(const char *fmt, ...) ...@@ -76,7 +72,7 @@ void trace_printf(const char *fmt, ...)
if (!fd) if (!fd)
return; return;
set_try_to_free_routine(do_nothing); /* is never reset */ set_try_to_free_routine(NULL); /* is never reset */
strbuf_init(&buf, 64); strbuf_init(&buf, 64);
va_start(ap, fmt); va_start(ap, fmt);
len = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap); len = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);
...@@ -108,7 +104,7 @@ void trace_argv_printf(const char **argv, const char *fmt, ...) ...@@ -108,7 +104,7 @@ void trace_argv_printf(const char **argv, const char *fmt, ...)
if (!fd) if (!fd)
return; return;
set_try_to_free_routine(do_nothing); /* is never reset */ set_try_to_free_routine(NULL); /* is never reset */
strbuf_init(&buf, 64); strbuf_init(&buf, 64);
va_start(ap, fmt); va_start(ap, fmt);
len = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap); len = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);
......
...@@ -12,6 +12,8 @@ static void (*try_to_free_routine)(size_t size) = do_nothing; ...@@ -12,6 +12,8 @@ static void (*try_to_free_routine)(size_t size) = do_nothing;
try_to_free_t set_try_to_free_routine(try_to_free_t routine) try_to_free_t set_try_to_free_routine(try_to_free_t routine)
{ {
try_to_free_t old = try_to_free_routine; try_to_free_t old = try_to_free_routine;
if (!routine)
routine = do_nothing;
try_to_free_routine = routine; try_to_free_routine = routine;
return old; return old;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册