Skip to content

Commit 7d6e888

Browse files
committed
mimalloc: 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 <[email protected]>
1 parent 534cebd commit 7d6e888

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compat/mimalloc/options.c

+7
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,15 @@ static void mi_out_stderr(const char* msg, void* arg) {
179179
if (!_mi_preloading()) {
180180
// _cputs(msg); // _cputs cannot be used at is aborts if it fails to lock the console
181181
static HANDLE hcon = INVALID_HANDLE_VALUE;
182+
static int write_to_console;
182183
if (hcon == INVALID_HANDLE_VALUE) {
184+
CONSOLE_SCREEN_BUFFER_INFO sbi;
183185
hcon = GetStdHandle(STD_ERROR_HANDLE);
186+
write_to_console = GetConsoleScreenBufferInfo(hcon, &sbi) ? 1 : 0;
187+
}
188+
if (!write_to_console) {
189+
fputs(msg, stderr);
190+
return;
184191
}
185192
const size_t len = strlen(msg);
186193
if (hcon != INVALID_HANDLE_VALUE && len > 0 && len < UINT32_MAX) {

0 commit comments

Comments
 (0)