From 5aaadb706fd0fad74428c56d483c6a5cba021a85 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Mon, 16 Aug 1999 17:21:47 +0000 Subject: [PATCH] added epicsAssertPrintf --- src/libCom/assertUNIX.c | 24 +++++++++++++++++++---- src/libCom/assertVX.c | 27 ++++++++++++++++++++------ src/libCom/epicsAssert.h | 37 +++++++++++++++++++++--------------- src/libCom/osi/epicsAssert.h | 37 +++++++++++++++++++++--------------- 4 files changed, 85 insertions(+), 40 deletions(-) diff --git a/src/libCom/assertUNIX.c b/src/libCom/assertUNIX.c index 9bccea953..9c2c13289 100644 --- a/src/libCom/assertUNIX.c +++ b/src/libCom/assertUNIX.c @@ -27,6 +27,9 @@ * Modification Log: * ----------------- * $Log$ + * Revision 1.11 1998/02/27 01:34:07 jhill + * cleaned up the DLL symbol export + * * Revision 1.10 1998/01/20 21:36:51 mrk * add dbDefs.h * @@ -66,14 +69,25 @@ /* - * epicsAssert () + * epicsAssertPrintf () */ epicsShareFunc void epicsShareAPI - epicsAssert (const char *pFile, const unsigned line, const char *pMsg, - const char *pAuthorName) + epicsAssertPrintf (const char *pFile, const unsigned line, + const char *pExp, const char *pAuthorName, const char *pFormat, ... + ) { + va_list pvar; + + va_start (pvar, pFormat); + epicsPrintf ( -"\n\n\nA call to \"assert (%s)\" failed in %s line %d.\n", pMsg, pFile, line); +"\n\n\nA call to \"assert (%s)\" failed in %s line %d.\n", pExp, pFile, line); + + if (pFormat) { + epicsPrintf ("When: "); + epicsVprintf (pFormat, pvar); + epicsPrintf ("\n"); + } epicsPrintf ( "The file \"core\" will be created in the current working directory.\n"); @@ -104,6 +118,8 @@ epicsShareFunc void epicsShareAPI } epicsPrintf ("This problem occurred in \"%s\"\n", epicsReleaseVersion); + va_end (pvar); + abort (); } diff --git a/src/libCom/assertVX.c b/src/libCom/assertVX.c index d71e8217d..5234c52cd 100644 --- a/src/libCom/assertVX.c +++ b/src/libCom/assertVX.c @@ -27,6 +27,9 @@ * Modification Log: * ----------------- * $Log$ + * Revision 1.10 1998/02/27 01:34:07 jhill + * cleaned up the DLL symbol export + * * Revision 1.9 1998/02/20 21:45:08 evans * Made a large number of changes to epicsShareThings in libCom routines * to get imports and exports straight on WIN32. Not everything is fixed @@ -69,24 +72,34 @@ /* - * epicsAssert () + * epicsAssertPrintf () * * This forces assert failures into the log file and then * calls taskSuspend() instead of exit() so that we can debug * the problem. */ -void epicsAssert (const char *pFile, const unsigned line, const char *pMsg, - const char *pAuthorName) +void epicsAssertPrintf (const char *pFile, const unsigned line, const char *pExp, + const char *pAuthorName, const char *pFormat, ...) { int taskId = taskIdSelf(); + va_list pvar; - epicsPrintf ( + va_start (pvar, pFormat); + + + epicsPrintf ( "\n\n\n%s: A call to \"assert (%s)\" failed in %s at %d\n", taskName (taskId), - pMsg, + pExp, pFile, line); + if (pFormat) { + epicsPrintf ("When: "); + epicsVprintf (pFormat, pvar); + epicsPrintf ("\n"); + } + if (pAuthorName) { epicsPrintf ( @@ -110,6 +123,8 @@ void epicsAssert (const char *pFile, const unsigned line, const char *pMsg, } epicsPrintf ("This problem occurred in \"%s\"\n", epicsReleaseVersion); - taskSuspend (taskId); + va_end (pvar); + + taskSuspend (taskId); } diff --git a/src/libCom/epicsAssert.h b/src/libCom/epicsAssert.h index 0b5f30cbf..3f98e27a2 100644 --- a/src/libCom/epicsAssert.h +++ b/src/libCom/epicsAssert.h @@ -41,6 +41,12 @@ extern "C" { #undef assert +#ifndef epicsAssertAuthor +# define epicsAssertAuthor 0 +#endif + +#define assertParenStrip(ARG) ARG + #ifdef NDEBUG # define assert(ignore) ((void) 0) #else /* NDEBUG */ @@ -48,8 +54,8 @@ extern "C" { #if defined(__STDC__) || defined(__cplusplus) epicsShareFunc extern void epicsShareAPI - epicsAssert (const char *pFile, const unsigned line, - const char *pMsg, const char *pAuthorName); + epicsAssertPrintf (const char *pFile, const unsigned line, + const char *pExp, const char *pAuthorName, const char *pFormat, ...); #else /*__STDC__ or __cplusplus*/ @@ -59,24 +65,25 @@ epicsShareFunc extern void epicsShareAPI #if (defined(__STDC__) || defined(__cplusplus)) && !defined(VAXC) -#ifdef epicsAssertAuthor #define assert(exp) \ -{if (!(exp)) epicsAssert (__FILE__, __LINE__, #exp, epicsAssertAuthor);} -#else /* epicsAssertAuthor */ -#define assert(exp) \ -{if (!(exp)) epicsAssert (__FILE__, __LINE__, #exp, 0);} -#endif /* epicsAssertAuthor */ +{if (!(exp)) epicsAssertPrintf (__FILE__, __LINE__, #exp, epicsAssertAuthor, 0);} + +/* + * Because C macros dont allow variable numbers of arguments we must + * use this as follows + * + * assertPrintf (a==b, ("bad news, a=%d b=%d", a, b) ); + */ +#define assertPrintf(exp, fmtAndArgsInParenthesis) \ + {if (!(exp)) {epicsAssertPrintf (__FILE__, __LINE__, #exp, epicsAssertAuthor, assertParenStrip fmtAndArgsInParenthesis);}} #else /*__STDC__ or __cplusplus*/ +#define assert(exp) \ +{if (!(exp)) epicsAssertPrintf (__FILE__, __LINE__, "", epicsAssertAuthor, 0);} -#ifdef epicsAssertAuthor -#define assert(exp) \ -{if (!(exp)) epicsAssert (__FILE__, __LINE__, "", epicsAssertAuthor);} -#else /* epicsAssertAuthor */ -#define assert(exp) \ -{if (!(exp)) epicsAssert (__FILE__, __LINE__, "", 0);} -#endif /* epicsAssertAuthor */ +#define assertPrintf(exp, fmtAndArgsInParenthesis) \ + {if (!(exp)) {epicsAssertPrintf (__FILE__, __LINE__, "", epicsAssertAuthor, assertParenStrip fmtAndArgsInParenthesis);}} #endif /* (__STDC__ or __cplusplus) and not VAXC */ diff --git a/src/libCom/osi/epicsAssert.h b/src/libCom/osi/epicsAssert.h index 0b5f30cbf..3f98e27a2 100644 --- a/src/libCom/osi/epicsAssert.h +++ b/src/libCom/osi/epicsAssert.h @@ -41,6 +41,12 @@ extern "C" { #undef assert +#ifndef epicsAssertAuthor +# define epicsAssertAuthor 0 +#endif + +#define assertParenStrip(ARG) ARG + #ifdef NDEBUG # define assert(ignore) ((void) 0) #else /* NDEBUG */ @@ -48,8 +54,8 @@ extern "C" { #if defined(__STDC__) || defined(__cplusplus) epicsShareFunc extern void epicsShareAPI - epicsAssert (const char *pFile, const unsigned line, - const char *pMsg, const char *pAuthorName); + epicsAssertPrintf (const char *pFile, const unsigned line, + const char *pExp, const char *pAuthorName, const char *pFormat, ...); #else /*__STDC__ or __cplusplus*/ @@ -59,24 +65,25 @@ epicsShareFunc extern void epicsShareAPI #if (defined(__STDC__) || defined(__cplusplus)) && !defined(VAXC) -#ifdef epicsAssertAuthor #define assert(exp) \ -{if (!(exp)) epicsAssert (__FILE__, __LINE__, #exp, epicsAssertAuthor);} -#else /* epicsAssertAuthor */ -#define assert(exp) \ -{if (!(exp)) epicsAssert (__FILE__, __LINE__, #exp, 0);} -#endif /* epicsAssertAuthor */ +{if (!(exp)) epicsAssertPrintf (__FILE__, __LINE__, #exp, epicsAssertAuthor, 0);} + +/* + * Because C macros dont allow variable numbers of arguments we must + * use this as follows + * + * assertPrintf (a==b, ("bad news, a=%d b=%d", a, b) ); + */ +#define assertPrintf(exp, fmtAndArgsInParenthesis) \ + {if (!(exp)) {epicsAssertPrintf (__FILE__, __LINE__, #exp, epicsAssertAuthor, assertParenStrip fmtAndArgsInParenthesis);}} #else /*__STDC__ or __cplusplus*/ +#define assert(exp) \ +{if (!(exp)) epicsAssertPrintf (__FILE__, __LINE__, "", epicsAssertAuthor, 0);} -#ifdef epicsAssertAuthor -#define assert(exp) \ -{if (!(exp)) epicsAssert (__FILE__, __LINE__, "", epicsAssertAuthor);} -#else /* epicsAssertAuthor */ -#define assert(exp) \ -{if (!(exp)) epicsAssert (__FILE__, __LINE__, "", 0);} -#endif /* epicsAssertAuthor */ +#define assertPrintf(exp, fmtAndArgsInParenthesis) \ + {if (!(exp)) {epicsAssertPrintf (__FILE__, __LINE__, "", epicsAssertAuthor, assertParenStrip fmtAndArgsInParenthesis);}} #endif /* (__STDC__ or __cplusplus) and not VAXC */