diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h index 151cd001..42720386 100644 --- a/include/mimalloc-internal.h +++ b/include/mimalloc-internal.h @@ -22,6 +22,7 @@ terms of the MIT license. A copy of the license can be found in the file // "options.c" +void _mi_fputs(FILE* out, const char* prefix, const char* message); void _mi_fprintf(FILE* out, const char* fmt, ...); void _mi_error_message(const char* fmt, ...); void _mi_warning_message(const char* fmt, ...); diff --git a/src/init.c b/src/init.c index b8bc2221..d66c875f 100644 --- a/src/init.c +++ b/src/init.c @@ -421,7 +421,9 @@ static void mi_process_load(void) { // show message from the redirector (if present) const char* msg = NULL; mi_allocator_init(&msg); - if (msg != NULL) _mi_verbose_message(msg); + if (msg != NULL && (mi_option_is_enabled(mi_option_verbose) || mi_option_is_enabled(mi_option_show_errors))) { + _mi_fputs(stderr,NULL,msg); + } } // Initialize the process; called by thread_init or the process loader diff --git a/src/options.c b/src/options.c index cd7e5da1..7e6e1a06 100644 --- a/src/options.c +++ b/src/options.c @@ -115,32 +115,41 @@ static uintptr_t error_count = 0; // when MAX_ERROR_COUNT stop emitting errors // inside the C runtime causes another message. static mi_decl_thread bool recurse = false; -// Define our own limited `fprintf` that avoids memory allocation. -// We do this using `snprintf` with a limited buffer. -static void mi_vfprintf( FILE* out, const char* prefix, const char* fmt, va_list args ) { - char buf[256]; - if (fmt==NULL) return; + +void _mi_fputs(FILE* out, const char* prefix, const char* message) { + if (out==NULL) out = stdout; if (_mi_preloading() || recurse) return; recurse = true; - if (out==NULL) out = stdout; - vsnprintf(buf,sizeof(buf)-1,fmt,args); #ifdef _WIN32 // on windows with redirection, the C runtime cannot handle locale dependent output // after the main thread closes so use direct console output. if (out==stderr) { if (prefix != NULL) _cputs(prefix); - _cputs(buf); + _cputs(message); } - else - #endif - { - if (prefix != NULL) fputs(prefix,out); - fputs(buf,out); + else + #endif + { + if (prefix != NULL) fputs(prefix, out); + fputs(message, out); } recurse = false; return; } +// Define our own limited `fprintf` that avoids memory allocation. +// We do this using `snprintf` with a limited buffer. +static void mi_vfprintf( FILE* out, const char* prefix, const char* fmt, va_list args ) { + char buf[512]; + if (fmt==NULL) return; + if (_mi_preloading() || recurse) return; + recurse = true; + vsnprintf(buf,sizeof(buf)-1,fmt,args); + recurse = false; + _mi_fputs(out,prefix,buf); +} + + void _mi_fprintf( FILE* out, const char* fmt, ... ) { va_list args; va_start(args,fmt);