Skip to content

Commit 089e85b

Browse files
committed
Make MIMALLOC_SHOW_STATS work with redirected stderr
Setting `MIMALLOC_SHOW_STATS` to ask mimalloc to print out something after the process is done is the easiest way to verify that a mimalloc-enabled Git is running. So it better work and not try to write to a Win32 Console when it got a regular file handle instead or, as is the case in Git for Windows' regular Git Bash window, an emulated pseudo terminal. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent edb181c commit 089e85b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/options.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,15 @@ static void mi_cdecl mi_out_stderr(const char* msg, void* arg) {
180180
if (!_mi_preloading()) {
181181
// _cputs(msg); // _cputs cannot be used at is aborts if it fails to lock the console
182182
static HANDLE hcon = INVALID_HANDLE_VALUE;
183+
static int write_to_console;
183184
if (hcon == INVALID_HANDLE_VALUE) {
185+
CONSOLE_SCREEN_BUFFER_INFO sbi;
184186
hcon = GetStdHandle(STD_ERROR_HANDLE);
187+
write_to_console = GetConsoleScreenBufferInfo(hcon, &sbi) ? 1 : 0;
188+
}
189+
if (!write_to_console) {
190+
fputs(msg, stderr);
191+
return;
185192
}
186193
const size_t len = strlen(msg);
187194
if (hcon != INVALID_HANDLE_VALUE && len > 0 && len < UINT32_MAX) {

0 commit comments

Comments
 (0)