diff options
author | Daan Leijen <daan@microsoft.com> | 2022-04-07 12:35:34 -0700 |
---|---|---|
committer | Daan Leijen <daan@microsoft.com> | 2022-04-07 12:35:34 -0700 |
commit | 88f9c9410114cc72dcf3835e985d862660d2b530 (patch) | |
tree | 84081f02c7e5a947489038186d4990e86f620993 | |
parent | 0cda8b02d5bdaa6d23c8862729cce624d5f07964 (diff) | |
parent | a799b214a2429908cbfcb6e083b1606869c96696 (diff) |
Merge branch 'dev' into dev-slice
-rw-r--r-- | src/options.c | 14 | ||||
-rw-r--r-- | src/os.c | 9 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/options.c b/src/options.c index 537b2e6..24cba03 100644 --- a/src/options.c +++ b/src/options.c @@ -163,10 +163,22 @@ void mi_option_disable(mi_option_t option) { static void mi_out_stderr(const char* msg, void* arg) { MI_UNUSED(arg); + if (msg == NULL) return; #ifdef _WIN32 // on windows with redirection, the C runtime cannot handle locale dependent output // after the main thread closes so we use direct console output. - if (!_mi_preloading()) { _cputs(msg); } + if (!_mi_preloading()) { + // _cputs(msg); // _cputs cannot be used at is aborts if it fails to lock the console + static HANDLE hcon = INVALID_HANDLE_VALUE; + if (hcon == INVALID_HANDLE_VALUE) { + hcon = GetStdHandle(STD_ERROR_HANDLE); + } + const size_t len = strlen(msg); + if (hcon != INVALID_HANDLE_VALUE && len > 0 && len < UINT32_MAX) { + DWORD written = 0; + WriteConsoleA(hcon, msg, (DWORD)len, &written, NULL); + } + } #else fputs(msg, stderr); #endif @@ -335,15 +335,8 @@ static void* mi_win_virtual_allocx(void* addr, size_t size, size_t try_alignment if (hint != NULL) { void* p = VirtualAlloc(hint, size, flags, PAGE_READWRITE); if (p != NULL) return p; - // for robustness always fall through in case of an error - /* - DWORD err = GetLastError(); - if (err != ERROR_INVALID_ADDRESS && // If linked with multiple instances, we may have tried to allocate at an already allocated area (#210) - err != ERROR_INVALID_PARAMETER) { // Windows7 instability (#230) - return NULL; - } - */ _mi_warning_message("unable to allocate hinted aligned OS memory (%zu bytes, error code: 0x%x, address: %p, alignment: %zu, flags: 0x%x)\n", size, GetLastError(), hint, try_alignment, flags); + // fall through on error } } #endif |