From 6876767592de3e96dfe5aa24489906c1cd3b406b Mon Sep 17 00:00:00 2001 From: eschnett Date: Tue, 26 Feb 2013 03:08:06 +0000 Subject: Implement CCTK_Error and friends git-svn-id: http://svn.cactuscode.org/flesh/trunk@4963 17b73243-c579-4c4c-a9d2-2d5706c11dac --- src/comm/CactusDefaultComm.c | 2 - src/include/CommOverloadables.h | 10 +++ src/include/IOOverloadables.h | 6 ++ src/include/MainOverloadables.h | 6 ++ src/include/OverloadMacros.h | 4 +- src/include/cctk_WarnLevel.h | 30 +++++---- src/include/cctk_core.h | 9 +-- src/main/WarnLevel.c | 138 +++++++++++++++++++++++++++++++++++++++- 8 files changed, 179 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/comm/CactusDefaultComm.c b/src/comm/CactusDefaultComm.c index 330cdcbe..0bf67dcd 100644 --- a/src/comm/CactusDefaultComm.c +++ b/src/comm/CactusDefaultComm.c @@ -377,7 +377,6 @@ int CactusDefaultExit (cGH *GH, int retval) } #endif exit (retval); - return (0); } @@ -436,7 +435,6 @@ int CactusDefaultAbort (cGH *GH, int retval) /*abort();*/ #endif exit (retval); - return (retval); } diff --git a/src/include/CommOverloadables.h b/src/include/CommOverloadables.h index 361d166f..9f95c1dd 100644 --- a/src/include/CommOverloadables.h +++ b/src/include/CommOverloadables.h @@ -40,9 +40,14 @@ #undef RETURN_TYPE #endif +#ifdef ATTRIBUTES +#undef ATTRIBUTES +#endif + #define RETURN_TYPE int #define ARGUMENTS const cGH *GH, const char *group #define USE_ARGUMENTS GH = GH; group = group; +#define ATTRIBUTES OVERLOADABLE(SyncGroup) OVERLOADABLE(EnableGroupStorage) @@ -77,6 +82,8 @@ OVERLOADABLE(ParallelInit) #define USE_ARGUMENTS GH = GH; retval = retval; #undef RETURN_TYPE #define RETURN_TYPE int +#undef ATTRIBUTES +#define ATTRIBUTES CCTK_ATTRIBUTE_NORETURN OVERLOADABLE(Exit) OVERLOADABLE(Abort) @@ -86,6 +93,8 @@ OVERLOADABLE(Abort) #define USE_ARGUMENTS config = config; convergence_level = convergence_level; #undef RETURN_TYPE #define RETURN_TYPE cGH * +#undef ATTRIBUTES +#define ATTRIBUTES OVERLOADABLE(SetupGH) #undef ARGUMENTS @@ -159,6 +168,7 @@ OVERLOADABLE(InterpGridArrays) #undef ARGUMENTS #undef USE_ARGUMENTS #undef RETURN_TYPE +#undef ATTRIBUTES #undef OVERLOADABLE_CALL #undef OVERLOADABLE_PREFIX diff --git a/src/include/IOOverloadables.h b/src/include/IOOverloadables.h index 2b0a50de..030a8c21 100644 --- a/src/include/IOOverloadables.h +++ b/src/include/IOOverloadables.h @@ -37,9 +37,14 @@ #undef RETURN_TYPE #endif +#ifdef ATTRIBUTES +#undef ATTRIBUTES +#endif + #define ARGUMENTS const cGH *GH #define USE_ARGUMENTS GH = GH; #define RETURN_TYPE int +#define ATTRIBUTES OVERLOADABLE(OutputGH) #undef ARGUMENTS @@ -54,6 +59,7 @@ OVERLOADABLE(OutputVarAsByMethod) #undef ARGUMENTS #undef USE_ARGUMENTS #undef RETURN_TYPE +#undef ATTRIBUTES #undef OVERLOADABLE_CALL #undef OVERLOADABLE_PREFIX diff --git a/src/include/MainOverloadables.h b/src/include/MainOverloadables.h index f112ece0..fef0307d 100644 --- a/src/include/MainOverloadables.h +++ b/src/include/MainOverloadables.h @@ -38,9 +38,14 @@ #undef RETURN_TYPE #endif +#ifdef ATTRIBUTES +#undef ATTRIBUTES +#endif + #define ARGUMENTS tFleshConfig *config #define USE_ARGUMENTS config = config #define RETURN_TYPE int +#define ATTRIBUTES OVERLOADABLE(Initialise) OVERLOADABLE(Evolve) @@ -67,6 +72,7 @@ OVERLOADABLE(SetMainLoopIndex) #undef ARGUMENTS #undef USE_ARGUMENTS #undef RETURN_TYPE +#undef ATTRIBUTES #undef OVERLOADABLE_CALL #undef OVERLOADABLE_PREFIX diff --git a/src/include/OverloadMacros.h b/src/include/OverloadMacros.h index 973c94c3..e967bb79 100644 --- a/src/include/OverloadMacros.h +++ b/src/include/OverloadMacros.h @@ -77,7 +77,7 @@ int call##Overload##name(RETURN_TYPE (*func)(ARGUMENTS)) \ #define _OVERLOADABLE_PROTOTYPE(prefix, dummy_prefix, name) __OVERLOADABLE_PROTOTYPE(prefix, dummy_prefix, name) #define __OVERLOADABLE_PROTOTYPE(prefix, dummy_prefix, name) \ -extern RETURN_TYPE (*prefix##name)(ARGUMENTS); +extern RETURN_TYPE (*prefix##name)(ARGUMENTS) ATTRIBUTES; /* This macro defines a dummy function */ #define OVERLOADABLE_DUMMY(name) _OVERLOADABLE_DUMMY(OVERLOADABLE_PREFIX, OVERLOADABLE_DUMMY_PREFIX, name) @@ -97,7 +97,7 @@ RETURN_TYPE dummy_prefix##name(ARGUMENTS) \ #define _OVERLOADABLE_DUMMYPROTOTYPE(prefix, dummy_prefix, name) __OVERLOADABLE_DUMMYPROTOTYPE(prefix, dummy_prefix, name) #define __OVERLOADABLE_DUMMYPROTOTYPE(prefix, dummy_prefix, name) \ -RETURN_TYPE dummy_prefix##name(ARGUMENTS); +RETURN_TYPE dummy_prefix##name(ARGUMENTS) ATTRIBUTES; /* This macro initialises the function to the dummy if it diff --git a/src/include/cctk_WarnLevel.h b/src/include/cctk_WarnLevel.h index fed8bbad..a2a7b531 100644 --- a/src/include/cctk_WarnLevel.h +++ b/src/include/cctk_WarnLevel.h @@ -11,6 +11,8 @@ #ifndef _CCTK_WARNLEVEL_H_ #define _CCTK_WARNLEVEL_H_ +#include + #ifdef CCODE #ifdef __cplusplus @@ -28,24 +30,28 @@ int CCTK_VWarn(int level, const char *file, const char *thorn, const char *format, ...) -#ifdef __GNUC__ -__attribute__ ((format (printf, 5, 6))) -#endif -; + CCTK_ATTRIBUTE_FORMAT(printf, 5, 6); + +void CCTK_Error(int line, + const char *file, + const char *thorn, + const char *message) + CCTK_ATTRIBUTE_NORETURN; + +void CCTK_VError(int line, + const char *file, + const char *thorn, + const char *format, ...) + CCTK_ATTRIBUTE_FORMAT(printf, 4, 5) + CCTK_ATTRIBUTE_NORETURN; int CCTK_VParamWarn (const char *thorn, const char *format, ...) -#ifdef __GNUC__ -__attribute__ ((format (printf, 2, 3))) -#endif -; + CCTK_ATTRIBUTE_FORMAT(printf, 2, 3); int CCTK_ParamWarn(const char *thorn, const char *message); int CCTK_Info(const char *thorn, const char *message); int CCTK_VInfo(const char *thorn, const char *format, ...) -#ifdef __GNUC__ -__attribute__ ((format (printf, 2, 3))) -#endif -; + CCTK_ATTRIBUTE_FORMAT(printf, 2, 3); /* prototypes for warn/info callback routines */ diff --git a/src/include/cctk_core.h b/src/include/cctk_core.h index cebc6c96..1878b4e8 100644 --- a/src/include/cctk_core.h +++ b/src/include/cctk_core.h @@ -66,6 +66,7 @@ cctk_ash1,cctk_ash2,cctk_ash3 CCTK_DECLARE(INTEGER,cctk_ash3,)&& #define CCTK_WARN(a,b) CCTK_Warn(a,__LINE__,__FORTRANFILE__,CCTK_THORNSTRING,b) +#define CCTK_ERROR(b) CCTK_Error(__LINE__,__FORTRANFILE__,CCTK_THORNSTRING,b) #define CCTK_CoordRegisterSystem(a,b,c) CCTKi_CoordRegisterSystem(a,b,CCTK_THORNSTRING,c) @@ -346,6 +347,7 @@ static inline int CCTK_VECTGFINDEX4D (const cGH *restrict cctkGH, #define CCTK_DELTA_TIME (cctk_delta_time/cctk_timefac) #define CCTK_WARN(a,b) CCTK_Warn(a,__LINE__,__FILE__,CCTK_THORNSTRING,b) +#define CCTK_ERROR(b) CCTK_Error(__LINE__,__FILE__,CCTK_THORNSTRING,b) #define CCTK_MALLOC(s) CCTKi_Malloc(s,__LINE__,__FILE__) #define CCTK_FREE(p) CCTKi_Free(p) @@ -355,11 +357,4 @@ static inline int CCTK_VECTGFINDEX4D (const cGH *restrict cctkGH, #define CCTK_INFO(a) CCTK_Info(CCTK_THORNSTRING,(a)) #define CCTK_PARAMWARN(a) CCTK_ParamWarn(CCTK_THORNSTRING,(a)) -/* -#define CCTK_MAKESTRING(x) CCTK_REALSTRING(x) -#define CCTK_REALSTRING(x) #x -#define CCTK_WARN(a,b) CCTK_Warn(a,CCTK_MAKESTRING(CCTK_THORN),b,__LINE__,__FILE__) -*/ - - #endif diff --git a/src/main/WarnLevel.c b/src/main/WarnLevel.c index 52fa0f5a..ff257e83 100644 --- a/src/main/WarnLevel.c +++ b/src/main/WarnLevel.c @@ -97,6 +97,9 @@ void CCTK_FCALL CCTK_FNAME (CCTK_Warn) (const int *level, const int *line, THREE_FORTSTRING_ARG); +void CCTK_FCALL CCTK_FNAME (CCTK_Error) + (const int *line, + THREE_FORTSTRING_ARG); void CCTK_FCALL CCTK_FNAME (CCTK_ParamWarn) (TWO_FORTSTRING_ARG); int CCTK_FCALL CCTK_FNAME (CCTK_MessageFormat) @@ -438,6 +441,26 @@ void CCTK_FCALL CCTK_FNAME (CCTK_Warn) } +void CCTK_Error (int line, + const char *file, + const char *thorn, + const char *message) +{ + CCTK_Warn (0, line, file, thorn, message); +} + +void CCTK_FCALL CCTK_FNAME (CCTK_Error) + (const int *line, + THREE_FORTSTRING_ARG) +{ + THREE_FORTSTRING_CREATE (file, thorn, message) + CCTK_Error (*line, file, thorn, message); + free (thorn); + free (message); + free (file); +} + + /*@@ @routine CCTK_VWarn @date Sun Nov 14 00:23:29 1999 @@ -558,7 +581,7 @@ int CCTK_VWarn (int level, if (highlight_warning_messages) { - bold_stderr(ON); + bold_stderr (ON); } if (level <= error_level || cctk_full_warnings) @@ -593,7 +616,7 @@ int CCTK_VWarn (int level, if (highlight_warning_messages) { - bold_stdout(ON); + bold_stdout (ON); } if (level <= error_level || cctk_full_warnings) @@ -611,7 +634,7 @@ int CCTK_VWarn (int level, if (highlight_warning_messages) { - bold_stdout(OFF); + bold_stdout (OFF); } fprintf (stdout, " "); @@ -633,6 +656,115 @@ int CCTK_VWarn (int level, } +void CCTK_VError (int line, + const char *file, + const char *thorn, + const char *format, + ...) +{ + const CCTK_INT *cctk_full_warnings_ptr, *highlight_warning_messages_ptr; + CCTK_INT cctk_full_warnings, highlight_warning_messages; + int param_type; + int myproc; + va_list ap; + + /* Necessary for wrapping up the final message */ + + int msg_size; + char *message = NULL; + char hostname[MAXNAMELEN+1]; + + /* Start generating message only if the warbcallback list is not NULL */ + if(warncallbacks) + { + va_start(ap,format); + msg_size = Util_vsnprintf(NULL, 0, format, ap); + va_end(ap); + + /* Empty string is ok */ + if(msg_size >= 0) + { + message = (char *)malloc(msg_size+1); + } + + /* Try to print in the allocated space. */ + if(message) + { + va_start(ap,format); + Util_vsnprintf(message,msg_size+1,format,ap); + va_end(ap); + } + + /* call the callback function */ + CCTKi_WarnCallbacksCall(0,line,file,thorn,message); + + /* free the memory allocated for temp messsage */ + free (message); + } + + myproc = CCTK_MyProc(NULL); + Util_GetHostName (hostname, MAXNAMELEN); + + cctk_full_warnings_ptr = + CCTK_ParameterGet ("cctk_full_warnings", "Cactus", ¶m_type); + /* Default to yes */ + cctk_full_warnings = + cctk_full_warnings_ptr && *cctk_full_warnings_ptr; + + highlight_warning_messages_ptr = + CCTK_ParameterGet ("highlight_warning_messages", "Cactus", ¶m_type); + /* Default to no */ + highlight_warning_messages = + ! highlight_warning_messages_ptr || *highlight_warning_messages_ptr; + + /* print to stderr */ + if (highlight_warning_messages) + { + bold_stderr (ON); + } + + fprintf (stderr, "ERROR in thorn %s processor %d host %s\n" + " (line %d of %s): \n" + " ->", + thorn, myproc, hostname, line, file); + + if (highlight_warning_messages) + { + bold_stderr (OFF); + } + + fprintf (stderr, " "); + va_start (ap, format); + vfprintf (stderr, format, ap); + va_end (ap); + fprintf (stderr, "\n"); + + /* print to stdout */ + if (highlight_warning_messages) + { + bold_stdout (ON); + } + + fprintf (stdout, "ERROR in thorn %s processor %d host %s\n" + " (line %d of %s): \n" + " ->", + thorn, myproc, hostname, line, file); + + if (highlight_warning_messages) + { + bold_stdout (OFF); + } + + fprintf (stdout, " "); + va_start (ap, format); + vfprintf (stdout, format, ap); + va_end (ap); + fprintf (stdout, "\n"); + + CCTK_Abort (NULL, 0); +} + + /*@@ @routine CCTK_ParameterLevel @date Wed Feb 21 2001 -- cgit v1.2.3