mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-05 23:19:31 +03:00
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>
This commit is contained in:
parent
edb181c377
commit
089e85b113
1 changed files with 7 additions and 0 deletions
|
@ -180,8 +180,15 @@ static void mi_cdecl mi_out_stderr(const char* msg, void* arg) {
|
||||||
if (!_mi_preloading()) {
|
if (!_mi_preloading()) {
|
||||||
// _cputs(msg); // _cputs cannot be used at is aborts if it fails to lock the console
|
// _cputs(msg); // _cputs cannot be used at is aborts if it fails to lock the console
|
||||||
static HANDLE hcon = INVALID_HANDLE_VALUE;
|
static HANDLE hcon = INVALID_HANDLE_VALUE;
|
||||||
|
static int write_to_console;
|
||||||
if (hcon == INVALID_HANDLE_VALUE) {
|
if (hcon == INVALID_HANDLE_VALUE) {
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
||||||
hcon = GetStdHandle(STD_ERROR_HANDLE);
|
hcon = GetStdHandle(STD_ERROR_HANDLE);
|
||||||
|
write_to_console = GetConsoleScreenBufferInfo(hcon, &sbi) ? 1 : 0;
|
||||||
|
}
|
||||||
|
if (!write_to_console) {
|
||||||
|
fputs(msg, stderr);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const size_t len = strlen(msg);
|
const size_t len = strlen(msg);
|
||||||
if (hcon != INVALID_HANDLE_VALUE && len > 0 && len < UINT32_MAX) {
|
if (hcon != INVALID_HANDLE_VALUE && len > 0 && len < UINT32_MAX) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue