summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@oarcorp.com>2014-09-02 18:07:36 -0500
committerJoel Sherrill <joel.sherrill@oarcorp.com>2014-09-04 09:08:04 -0500
commit3bff410eec82cd11ff87bb1d1ee8c7c97abf888f (patch)
tree614a78b128b2d82c394430bf757e0402d0e28522 /cpukit
parentmprotect.c: Remove warning for no prototype (diff)
downloadrtems-3bff410eec82cd11ff87bb1d1ee8c7c97abf888f.tar.bz2
rtems/score/assert.h: Rework to allow use of NDEBUG
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/score/include/rtems/score/assert.h56
1 files changed, 43 insertions, 13 deletions
diff --git a/cpukit/score/include/rtems/score/assert.h b/cpukit/score/include/rtems/score/assert.h
index b8d9463e03..43ec2d0e38 100644
--- a/cpukit/score/include/rtems/score/assert.h
+++ b/cpukit/score/include/rtems/score/assert.h
@@ -30,22 +30,52 @@ extern "C" {
* NDEBUG.
*/
#if defined( RTEMS_DEBUG )
+
+ /**
+ * @brief Macro with method name used in assert output
+ *
+ * Given the variations in compilers and standards, we have to poke a bit.
+ *
+ * @note This is based on the code in newlib's assert.h.
+ */
+ #ifndef __RTEMS_ASSERT_FUNCTION
+ /* Use g++'s demangled names in C++. */
+ #if defined __cplusplus && defined __GNUC__
+ #define __RTEMS_ASSERT_FUNCTION __PRETTY_FUNCTION__
+
+ /* C99 requires the use of __func__. */
+ #elif __STDC_VERSION__ >= 199901L
+ #define __RTEMS_ASSERT_FUNCTION __func__
+
+ /* Older versions of gcc don't have __func__ but can use __FUNCTION__. */
+ #elif __GNUC__ >= 2
+ #define __RTEMS_ASSERT_FUNCTION __FUNCTION__
+
+ /* failed to detect __func__ support. */
+ #else
+ #define __RTEMS_ASSERT_FUNCTION ((char *) 0)
+ #endif
+ #endif /* !__RTEMS_ASSERT_FUNCTION */
+
#if !defined( RTEMS_SCHEDSIM )
- /* __ASSERT_FUNC is newlib. */
+ /* normal build is newlib. */
+
+ void __assert_func(const char *, int, const char *, const char *)
+ RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
+
+ #define _Assert( _e ) \
+ ( ( _e ) ? \
+ ( void ) 0 : \
+ __assert_func( __FILE__, __LINE__, __RTEMS_ASSERT_FUNCTION, #_e ) )
+
+ #elif defined(__linux__)
+ /* Scheduler simulator has only beed tested on glibc. */
#define _Assert( _e ) \
- ( ( _e ) ? \
- ( void ) 0 : \
- __assert_func( __FILE__, __LINE__, __ASSERT_FUNC, #_e ) )
+ ( ( _e ) ? \
+ ( void ) 0 : \
+ __assert_fail( #_e, __FILE__, __LINE__, __RTEMS_ASSERT_FUNCTION ) )
#else
- /* __ASSERT_FUNCTION is glibc. */
- #if defined(__ASSERT_FUNCTION)
- #define _Assert( _e ) \
- ( ( _e ) ? \
- ( void ) 0 : \
- __assert_fail( #_e, __FILE__, __LINE__, __ASSERT_FUNCTION ) )
- #else
- #error "What does assert.h use?"
- #endif
+ #error "Implement RTEMS assert support for this C Library"
#endif
#else