From 7b0a4ed9deda5bf9dbf3359fe2adeeb8238eb6b8 Mon Sep 17 00:00:00 2001 From: Geoff Norton Date: Sun, 8 Feb 2015 10:12:12 -0800 Subject: [PATCH] Minor code structure refactoring as requested by @jkotas in PR #138 --- src/jit/compiler.cpp | 6 ++---- src/jit/error.cpp | 18 +++++++++--------- src/utilcode/stresslog.cpp | 9 ++++----- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/jit/compiler.cpp b/src/jit/compiler.cpp index 2e1a626..de8925d 100644 --- a/src/jit/compiler.cpp +++ b/src/jit/compiler.cpp @@ -92,20 +92,18 @@ unsigned jitCurSrcLine; void Compiler::JitLogEE(unsigned level, const char* fmt, ...) { va_list args; - va_start(args, fmt); #ifndef CROSSGEN_COMPILE if (verbose) { + va_start(args, fmt); logf_stdout(fmt, args); - // logf_stdout can modify args so we need to reset it va_end(args); - va_start(args, fmt); } #endif + va_start(args, fmt); vlogf(level, fmt, args); - va_end(args); } diff --git a/src/jit/error.cpp b/src/jit/error.cpp index 348b190..223afb1 100644 --- a/src/jit/error.cpp +++ b/src/jit/error.cpp @@ -380,7 +380,6 @@ void logf_stdout(const char* fmt, va_list args) void logf(const char* fmt, ...) { va_list args; - va_start(args, fmt); static bool logToEEfailed = false; // // We remember when the EE failed to log, because vlogf() @@ -389,19 +388,20 @@ void logf(const char* fmt, ...) // If it fails to log an LL_INFO1000 message once // it will always fail when logging an LL_INFO1000 message. // - if (logToEEfailed) + if (!logToEEfailed) { - logf_stdout(fmt, args); + va_start(args, fmt); + if (!vlogf(LL_INFO1000, fmt, args)) + logToEEfailed = true; + va_end(args); } - else if (!vlogf(LL_INFO1000, fmt, args)) + + if (logToEEfailed) { - logToEEfailed = true; - - // The vlogf call may have modified args, so we need to reset it - va_end(args); + // if the EE refuses to log it, we try to send it to stdout va_start(args, fmt); - logf_stdout(fmt, args); + va_end(args); } #if 0 // Enable this only when you need it else diff --git a/src/utilcode/stresslog.cpp b/src/utilcode/stresslog.cpp index a158188..3d1720c 100644 --- a/src/utilcode/stresslog.cpp +++ b/src/utilcode/stresslog.cpp @@ -655,7 +655,6 @@ void StressLog::LogMsg (unsigned level, unsigned facility, int cArgs, const char _ASSERTE ( cArgs >= 0 && cArgs <= 7 ); va_list Args; - va_start(Args, format); if(InlinedStressLogOn(facility, level)) { @@ -667,20 +666,22 @@ void StressLog::LogMsg (unsigned level, unsigned facility, int cArgs, const char if (msgs == 0) return; } + va_start(Args, format); msgs->LogMsg (facility, cArgs, format, Args); + va_end(Args); } // Stress Log ETW feature available only on the desktop versions of the runtime #if !defined(FEATURE_CORECLR) // The previous LogMsg call could have modified the Args, so we need to reset it - va_end(Args); - va_start(Args, format); if(InlinedETWLogOn(facility, level)) { #define MAX_STRESSLOG_DATA_ETW_LENGTH 256 CHAR logMessage[MAX_STRESSLOG_DATA_ETW_LENGTH]; + va_start(Args, format); ULONG messageLength = (USHORT)_vsnprintf_s(logMessage, COUNTOF(logMessage), MAX_STRESSLOG_DATA_ETW_LENGTH-1, format, Args); + va_end(Args); if(messageLength >= 0 && messageLength < MAX_STRESSLOG_DATA_ETW_LENGTH) // this condition has been added to make prefast happy @@ -693,8 +694,6 @@ void StressLog::LogMsg (unsigned level, unsigned facility, int cArgs, const char #undef MAX_STRESSLOG_DATA_ETW_LENGTH } #endif // !FEATURE_CORECLR - - va_end(Args); #endif //!DACCESS_COMPILE } -- 2.7.4