[rtems commit] rtems/score/assert.h: Rework to allow use of NDEBUG

Joel Sherrill joel at rtems.org
Thu Sep 4 13:59:25 UTC 2014


Module:    rtems
Branch:    master
Commit:    3bff410eec82cd11ff87bb1d1ee8c7c97abf888f
Changeset: http://git.rtems.org/rtems/commit/?id=3bff410eec82cd11ff87bb1d1ee8c7c97abf888f

Author:    Joel Sherrill <joel.sherrill at oarcorp.com>
Date:      Tue Sep  2 18:07:36 2014 -0500

rtems/score/assert.h: Rework to allow use of NDEBUG

---

 cpukit/score/include/rtems/score/assert.h |   56 ++++++++++++++++++++++-------
 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 b8d9463..43ec2d0 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



More information about the vc mailing list