[PATCH 04/10] Rename and move RTEMS_PRINTF_ATTRIBUTE()

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Jun 21 13:57:49 UTC 2016


Rename RTEMS_PRINTF_ATTRIBUTE() into RTEMS_PRINTFLIKE() (similar to
<sys/cdefs.h> __printflike()) and move it to <rtems/score/basedefs.h>.
---
 cpukit/include/rtems/bspIo.h                | 17 +++++------------
 cpukit/include/rtems/print.h                |  2 +-
 cpukit/libmisc/testsupport/test.h           |  2 +-
 cpukit/score/include/rtems/score/basedefs.h | 11 +++++++++++
 testsuites/sptests/spprintk/init.c          |  8 +++++---
 5 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/cpukit/include/rtems/bspIo.h b/cpukit/include/rtems/bspIo.h
index 112dde6..4b5b2a2 100644
--- a/cpukit/include/rtems/bspIo.h
+++ b/cpukit/include/rtems/bspIo.h
@@ -18,6 +18,10 @@
 #ifndef _RTEMS_BSPIO_H
 #define _RTEMS_BSPIO_H
 
+#include <rtems/score/basedefs.h>
+
+#include <stdarg.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -37,15 +41,6 @@ extern "C" {
  */
 
 /**
- * Print format function attribute for warning checks. Can be defined if
- * checking needs to be disabled.
- */
-#ifndef RTEMS_PRINTF_ATTRIBUTE
-#define RTEMS_PRINTF_ATTRIBUTE(_format_pos, _ap_pos) \
-  __attribute__((format(__printf__, _format_pos, _ap_pos)))
-#endif
-
-/**
  * This type defines the prototype for the BSP provided method to
  * print a single character. It is assumed to be polled.
  */
@@ -69,8 +64,6 @@ extern 	BSP_output_char_function_type 		BSP_output_char;
  */
 extern 	BSP_polling_getchar_function_type 	BSP_poll_char;
 
-#include <stdarg.h>
-
 /**
  * @brief Get Character (kernel I/O)
  *
@@ -107,7 +100,7 @@ extern int vprintk(const char *fmt, va_list ap);
  *
  * @return The number of characters output.
  */
-extern int printk(const char *fmt, ...) RTEMS_PRINTF_ATTRIBUTE(1, 2);
+extern int printk(const char *fmt, ...) RTEMS_PRINTFLIKE(1, 2);
 
 /**
  * @brief Kernel Put String
diff --git a/cpukit/include/rtems/print.h b/cpukit/include/rtems/print.h
index 91c4515..c4dacce 100644
--- a/cpukit/include/rtems/print.h
+++ b/cpukit/include/rtems/print.h
@@ -68,7 +68,7 @@ static inline bool rtems_print_printer_valid(const rtems_printer *printer)
  */
 extern int rtems_printf(const rtems_printer *printer,
                         const char          *format,
-                        ...) RTEMS_PRINTF_ATTRIBUTE(2, 3);
+                        ...) RTEMS_PRINTFLIKE(2, 3);
 
 /**
  * @brief Print to the kernel plugin handler. This has to be a macro because
diff --git a/cpukit/libmisc/testsupport/test.h b/cpukit/libmisc/testsupport/test.h
index 980ab66..ce5172f 100644
--- a/cpukit/libmisc/testsupport/test.h
+++ b/cpukit/libmisc/testsupport/test.h
@@ -86,7 +86,7 @@ int rtems_test_end(void);
  *
  * @returns As specified by printf().
  */
-int rtems_test_print(const char* format, ...) RTEMS_PRINTF_ATTRIBUTE(1, 2);
+int rtems_test_print(const char* format, ...) RTEMS_PRINTFLIKE(1, 2);
 
 /**
  * @brief Internal context for parallel job execution.
diff --git a/cpukit/score/include/rtems/score/basedefs.h b/cpukit/score/include/rtems/score/basedefs.h
index 24a56f2..7e691b5 100644
--- a/cpukit/score/include/rtems/score/basedefs.h
+++ b/cpukit/score/include/rtems/score/basedefs.h
@@ -210,6 +210,17 @@
   #define RTEMS_UNREACHABLE() _Assert_Unreachable()
 #endif
 
+/**
+ * @brief Tells the compiler that this function expects printf()-like
+ * arguments.
+ */
+#if defined(__GNUC__)
+  #define RTEMS_PRINTFLIKE( _format_pos, _ap_pos ) \
+    __attribute__((__format__(__printf__, _format_pos, _ap_pos)))
+#else
+  #define RTEMS_PRINTFLIKE( _format_pos, _ap_pos )
+#endif
+
 #if __cplusplus >= 201103L
   #define RTEMS_STATIC_ASSERT(cond, msg) \
     static_assert(cond, # msg)
diff --git a/testsuites/sptests/spprintk/init.c b/testsuites/sptests/spprintk/init.c
index 4b45450..55e132d 100644
--- a/testsuites/sptests/spprintk/init.c
+++ b/testsuites/sptests/spprintk/init.c
@@ -13,12 +13,14 @@
 #include "config.h"
 #endif
 
+#include <rtems/score/basedefs.h>
+
 /*
- * Undefined the RTEMS_PRINTF_ATTRIBUTE and make it nothing. The test code
+ * Undefined the RTEMS_PRINTFLIKE and make it nothing. The test code
  * contained in the file is suppose to be wrong.
  */
-#undef RTEMS_PRINTF_ATTRIBUTE
-#define RTEMS_PRINTF_ATTRIBUTE(_a, _b)
+#undef RTEMS_PRINTFLIKE
+#define RTEMS_PRINTFLIKE(_a, _b)
 
 #define TESTS_USE_PRINTK
 #include <tmacros.h>
-- 
1.8.4.5




More information about the devel mailing list