From 862719008dab4c540b233ac53f25f8002f0d631b Mon Sep 17 00:00:00 2001 From: avolkov Date: Thu, 4 May 2006 21:46:32 +0000 Subject: [PATCH] Logger does not handle SIGABRT anymore; use explode() instead of abort() git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2350 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/clock.c | 5 ++-- sc2/src/sc2code/libs/log/uqmlog.c | 28 +------------------ sc2/src/sc2code/libs/memory/w_memlib.c | 5 ++-- sc2/src/sc2code/libs/misc.h | 12 ++++++++ sc2/src/sc2code/libs/resource/resinit.c | 2 +- sc2/src/sc2code/libs/sound/mixer/mixer.c | 2 +- sc2/src/sc2code/libs/threads/sdl/sdlthreads.c | 2 +- 7 files changed, 22 insertions(+), 34 deletions(-) diff --git a/sc2/src/sc2code/clock.c b/sc2/src/sc2code/clock.c index 3d2fd2898..ccbcdad89 100644 --- a/sc2/src/sc2code/clock.c +++ b/sc2/src/sc2code/clock.c @@ -25,6 +25,7 @@ #include "libs/tasklib.h" #include "libs/threadlib.h" #include "libs/log.h" +#include "libs/misc.h" // the running of the game-clock is based on game framerates // *not* on the system (or translated) timer @@ -228,7 +229,7 @@ SuspendGameClock (void) log_add (log_Always, "BUG: " "Attempted to suspend non-existent game clock"); #ifdef DEBUG - abort(); + explode (); #endif return; } @@ -249,7 +250,7 @@ ResumeGameClock (void) log_add (log_Always, "BUG: " "Attempted to resume non-existent game clock\n"); #ifdef DEBUG - abort(); + explode (); #endif return; } diff --git a/sc2/src/sc2code/libs/log/uqmlog.c b/sc2/src/sc2code/libs/log/uqmlog.c index 6a1431918..7f7bf8b07 100755 --- a/sc2/src/sc2code/libs/log/uqmlog.c +++ b/sc2/src/sc2code/libs/log/uqmlog.c @@ -53,10 +53,7 @@ static FILE *streamOut; static volatile int qlock = 0; static Mutex qmutex; -static void (* prevAbortFunc)(int) = SIG_ERR; - static void exitCallback (void); -static void abortHandler (int); static void displayLog (bool isError); static void displayBox (const char *title, bool isError, const char *msg); @@ -141,14 +138,8 @@ log_init (int max_lines) msgBuf[sizeof (msgBuf) - 1] = '\0'; msgNoThread[sizeof (msgNoThread) - 1] = '\0'; - // install exit and abort handlers + // install exit handlers atexit (exitCallback); - prevAbortFunc = signal (SIGABRT, abortHandler); - if (prevAbortFunc == SIG_ERR) - { - fprintf (stderr, "Warning: cannot install SIGABRT handler: %s\n", - strerror (errno)); - } } void @@ -169,9 +160,6 @@ log_exit (int code) DestroyMutex (qmutex); } - if (prevAbortFunc != SIG_ERR) - signal (SIGABRT, prevAbortFunc); - return code; } @@ -289,20 +277,6 @@ exitCallback (void) log_exit (0); } -static void -abortHandler (int sig) -{ - if (showBox) - displayLog (true); - - if (prevAbortFunc == SIG_ERR || prevAbortFunc == SIG_IGN) - ; // do nothing - else if (prevAbortFunc == SIG_DFL) - raise (SIGABRT); // forward to default - else - prevAbortFunc (sig); // forward directly -} - static void displayLog (bool isError) { diff --git a/sc2/src/sc2code/libs/memory/w_memlib.c b/sc2/src/sc2code/libs/memory/w_memlib.c index 07da023d5..06cf81b05 100644 --- a/sc2/src/sc2code/libs/memory/w_memlib.c +++ b/sc2/src/sc2code/libs/memory/w_memlib.c @@ -28,6 +28,7 @@ #include "libs/threadlib.h" #include "libs/memlib.h" #include "libs/log.h" +#include "libs/misc.h" #define GetToolFrame() 1 @@ -211,7 +212,7 @@ MallocWithRetry(int bytes, char *diagStr) log_add (log_Always, "Malloc failed for %s. #Bytes %d.", diagStr, bytes); fflush (stderr); - abort (); + explode (); #if 0 /* The user gets a chance to close other applications and try again. */ if (!MessageWithRetry ("I'm out of memory! " @@ -587,7 +588,7 @@ HMalloc (int size) if ((p = _alloc_mem(size)) == NULL) { log_add (log_Always, "Fatal Error: HMalloc(): out of memory."); fflush (stderr); - abort (); + explode (); } return (p); } diff --git a/sc2/src/sc2code/libs/misc.h b/sc2/src/sc2code/libs/misc.h index b0ba4fd03..ec435ffe8 100644 --- a/sc2/src/sc2code/libs/misc.h +++ b/sc2/src/sc2code/libs/misc.h @@ -23,6 +23,8 @@ #define MISC_H #include +#include +#include "port.h" extern void *HMalloc (int size); @@ -32,5 +34,15 @@ extern void *HRealloc (void *p, int size); extern int TFB_DEBUG_HALT; +static inline void explode (void) +{ +#ifdef DEBUG + // give debugger a chance to hook + abort (); +#else + exit (EXIT_FAILURE); +#endif +} + #endif diff --git a/sc2/src/sc2code/libs/resource/resinit.c b/sc2/src/sc2code/libs/resource/resinit.c index 29280944b..88fa9bde6 100644 --- a/sc2/src/sc2code/libs/resource/resinit.c +++ b/sc2/src/sc2code/libs/resource/resinit.c @@ -192,7 +192,7 @@ loadResourceIndex (uio_Stream *stream, const char *fileName) { log_add (log_Always, "Fatal: resource index '%s' is not sorted " "on the resource number, or contains a double entry. " "Problem encountered on line %d.", fileName, lineNum); - abort (); + explode (); } lastResource = res; #endif diff --git a/sc2/src/sc2code/libs/sound/mixer/mixer.c b/sc2/src/sc2code/libs/sound/mixer/mixer.c index fc0494e69..8be58864d 100644 --- a/sc2/src/sc2code/libs/sound/mixer/mixer.c +++ b/sc2/src/sc2code/libs/sound/mixer/mixer.c @@ -939,7 +939,7 @@ mixer_SourceStop_internal (mixer_Source *src) log_add (log_Debug, "mixer_SourceStop_internal(): " "desynced source state"); #ifdef DEBUG - abort (); + explode (); #endif } diff --git a/sc2/src/sc2code/libs/threads/sdl/sdlthreads.c b/sc2/src/sc2code/libs/threads/sdl/sdlthreads.c index e930401d3..476371481 100644 --- a/sc2/src/sc2code/libs/threads/sdl/sdlthreads.c +++ b/sc2/src/sc2code/libs/threads/sdl/sdlthreads.c @@ -155,7 +155,7 @@ UnQueueThread (TrueThread thread) log_add (log_Debug, "Error: Trying to remove non-present thread " "from thread queue."); fflush (stderr); - abort(); + explode (); } #endif /* DEBUG_THREADS */ ptr = &(*ptr)->next;