Minor code structure refactoring as requested by @jkotas in PR #138
authorGeoff Norton <grompf@gmail.com>
Sun, 8 Feb 2015 18:12:12 +0000 (10:12 -0800)
committerGeoff Norton <grompf@gmail.com>
Sun, 8 Feb 2015 18:12:12 +0000 (10:12 -0800)
src/jit/compiler.cpp
src/jit/error.cpp
src/utilcode/stresslog.cpp

index 2e1a626..de8925d 100644 (file)
@@ -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);
 }
 
index 348b190..223afb1 100644 (file)
@@ -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
index a158188..3d1720c 100644 (file)
@@ -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
 }