diff mbox

[API-NEXT] api: debug: promote ODP_STATIC_ASSERT() to be an ODP API

Message ID 1459963360-8901-1-git-send-email-bill.fischofer@linaro.org
State Superseded
Headers show

Commit Message

Bill Fischofer April 6, 2016, 5:22 p.m. UTC
Convert the formerly internal _ODP_STATIC_ASSERT() macro to be
a full ODP API named ODP_STATIC_ASSERT().  This provides
a wrapper around any platform-specific compile-time assertion
macro.

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 helper/include/odp/helper/eth.h                    |  9 ++++---
 helper/include/odp/helper/icmp.h                   |  3 ++-
 helper/include/odp/helper/ip.h                     |  6 +++--
 helper/include/odp/helper/ipsec.h                  |  9 ++++---
 helper/include/odp/helper/udp.h                    |  3 ++-
 include/odp/api/spec/debug.h                       | 29 +++++-----------------
 platform/linux-generic/include/odp/api/debug.h     | 21 ++++++++++++++++
 .../linux-generic/include/odp_buffer_internal.h    | 10 ++++----
 .../linux-generic/include/odp_packet_internal.h    | 12 ++++-----
 .../linux-generic/include/odp_packet_io_queue.h    |  4 +--
 platform/linux-generic/include/odp_packet_socket.h |  5 ++--
 platform/linux-generic/odp_cpumask.c               |  4 +--
 platform/linux-generic/odp_schedule.c              |  4 +--
 platform/linux-generic/odp_shared_memory.c         |  4 +--
 platform/linux-generic/odp_timer.c                 |  2 +-
 platform/linux-generic/pktio/ipc.c                 |  4 +--
 16 files changed, 72 insertions(+), 57 deletions(-)

Comments

Bill Fischofer April 12, 2016, 2:09 p.m. UTC | #1
v2 posted with suggested rewording.

On Tue, Apr 12, 2016 at 7:17 AM, Savolainen, Petri (Nokia - FI/Espoo) <
petri.savolainen@nokia.com> wrote:

> >  /**

> >   * @}

> > diff --git a/include/odp/api/spec/debug.h b/include/odp/api/spec/debug.h

> > index 252a82f..0540268 100644

> > --- a/include/odp/api/spec/debug.h

> > +++ b/include/odp/api/spec/debug.h

> > @@ -17,31 +17,14 @@

> >  extern "C" {

> >  #endif

> >

> > -#if defined(__GNUC__) && !defined(__clang__)

> > -

> > -

> > -#if __GNUC__ < 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ < 6))

> > -

> > -/**

> > - * @internal _Static_assert was only added in GCC 4.6. Provide a weak

> > replacement

> > - * for previous versions.

> > - */

> > -#define _Static_assert(e, s) (extern int (*static_assert_checker(void))

> \

> > -     [sizeof(struct { unsigned int error_if_negative:(e) ? 1 : -1; })])

> > -

> > -#endif

> > -

> > -

> > -

> > -#endif

> > -

> > -

> >  /**

> > - * @internal Compile time assertion-macro - fail compilation if cond is

> > false.

> > - * This macro has zero runtime overhead

> > + * @def ODP_STATIC_ASSERT

> > + * Compile time assertion macro - fail compilation if cond if false.

>                                                             ^^^^^^

>

> Typo (if cond is false). Also I'd document that the macro is empty if

> compiler does not support static asserts.

>

> Something like this:

> "Compile time assertion macro. Fails compilation and outputs message 'msg'

> if condition 'cond' is false. Macro definition is empty when the compiler

> is not supported or the compiler does not support static assertion."

>

> -Petri

>

> > + *

> > + * @param cond Conditional expression to be evaluated at compile time

> > + *

> > + * @param msg  Compile time error message to be displayed if cond is

> > false

> >   */

> > -#define _ODP_STATIC_ASSERT(cond, msg)  _Static_assert(cond, msg)

> > -

> >

> >  #ifdef __cplusplus

> >  }

>
diff mbox

Patch

diff --git a/helper/include/odp/helper/eth.h b/helper/include/odp/helper/eth.h
index 1e16225..60949d9 100644
--- a/helper/include/odp/helper/eth.h
+++ b/helper/include/odp/helper/eth.h
@@ -40,7 +40,8 @@  typedef struct ODP_PACKED {
 } odph_ethaddr_t;
 
 /** @internal Compile time assert */
-_ODP_STATIC_ASSERT(sizeof(odph_ethaddr_t) == ODPH_ETHADDR_LEN, "ODPH_ETHADDR_T__SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(odph_ethaddr_t) == ODPH_ETHADDR_LEN,
+		  "ODPH_ETHADDR_T__SIZE_ERROR");
 
 /**
  * Ethernet header
@@ -52,7 +53,8 @@  typedef struct ODP_PACKED {
 } odph_ethhdr_t;
 
 /** @internal Compile time assert */
-_ODP_STATIC_ASSERT(sizeof(odph_ethhdr_t) == ODPH_ETHHDR_LEN, "ODPH_ETHHDR_T__SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(odph_ethhdr_t) == ODPH_ETHHDR_LEN,
+		  "ODPH_ETHHDR_T__SIZE_ERROR");
 
 /**
  * VLAN header
@@ -65,7 +67,8 @@  typedef struct ODP_PACKED {
 } odph_vlanhdr_t;
 
 /** @internal Compile time assert */
-_ODP_STATIC_ASSERT(sizeof(odph_vlanhdr_t) == ODPH_VLANHDR_LEN, "ODPH_VLANHDR_T__SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(odph_vlanhdr_t) == ODPH_VLANHDR_LEN,
+		  "ODPH_VLANHDR_T__SIZE_ERROR");
 
 
 /* Ethernet header Ether Type ('type') values, a selected few */
diff --git a/helper/include/odp/helper/icmp.h b/helper/include/odp/helper/icmp.h
index 929b8bc..e25646a 100644
--- a/helper/include/odp/helper/icmp.h
+++ b/helper/include/odp/helper/icmp.h
@@ -92,7 +92,8 @@  typedef struct ODP_PACKED {
 								exceeded*/
 
 /** @internal Compile time assert */
-_ODP_STATIC_ASSERT(sizeof(odph_icmphdr_t) == ODPH_ICMPHDR_LEN, "ODPH_ICMPHDR_T__SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(odph_icmphdr_t) == ODPH_ICMPHDR_LEN,
+		  "ODPH_ICMPHDR_T__SIZE_ERROR");
 
 /**
  * @}
diff --git a/helper/include/odp/helper/ip.h b/helper/include/odp/helper/ip.h
index 3789d54..4df41d9 100644
--- a/helper/include/odp/helper/ip.h
+++ b/helper/include/odp/helper/ip.h
@@ -71,7 +71,8 @@  typedef struct ODP_PACKED {
 } odph_ipv4hdr_t;
 
 /** @internal Compile time assert */
-_ODP_STATIC_ASSERT(sizeof(odph_ipv4hdr_t) == ODPH_IPV4HDR_LEN, "ODPH_IPV4HDR_T__SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(odph_ipv4hdr_t) == ODPH_IPV4HDR_LEN,
+		  "ODPH_IPV4HDR_T__SIZE_ERROR");
 
 /**
  * Check if IPv4 checksum is valid
@@ -146,7 +147,8 @@  typedef struct ODP_PACKED {
 } odph_ipv6hdr_t;
 
 /** @internal Compile time assert */
-_ODP_STATIC_ASSERT(sizeof(odph_ipv6hdr_t) == ODPH_IPV6HDR_LEN, "ODPH_IPV6HDR_T__SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(odph_ipv6hdr_t) == ODPH_IPV6HDR_LEN,
+		  "ODPH_IPV6HDR_T__SIZE_ERROR");
 
 /**
  * IPv6 Header extensions
diff --git a/helper/include/odp/helper/ipsec.h b/helper/include/odp/helper/ipsec.h
index af3de87..034a341 100644
--- a/helper/include/odp/helper/ipsec.h
+++ b/helper/include/odp/helper/ipsec.h
@@ -38,7 +38,8 @@  typedef struct ODP_PACKED {
 } odph_esphdr_t;
 
 /** @internal Compile time assert */
-_ODP_STATIC_ASSERT(sizeof(odph_esphdr_t) == ODPH_ESPHDR_LEN, "ODPH_ESPHDR_T__SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(odph_esphdr_t) == ODPH_ESPHDR_LEN,
+		  "ODPH_ESPHDR_T__SIZE_ERROR");
 
 /**
  * IPSec ESP trailer
@@ -50,7 +51,8 @@  typedef struct ODP_PACKED {
 } odph_esptrl_t;
 
 /** @internal Compile time assert */
-_ODP_STATIC_ASSERT(sizeof(odph_esptrl_t) == ODPH_ESPTRL_LEN, "ODPH_ESPTRL_T__SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(odph_esptrl_t) == ODPH_ESPTRL_LEN,
+		  "ODPH_ESPTRL_T__SIZE_ERROR");
 
 /**
  * IPSec AH header
@@ -65,7 +67,8 @@  typedef struct ODP_PACKED {
 } odph_ahhdr_t;
 
 /** @internal Compile time assert */
-_ODP_STATIC_ASSERT(sizeof(odph_ahhdr_t) == ODPH_AHHDR_LEN, "ODPH_AHHDR_T__SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(odph_ahhdr_t) == ODPH_AHHDR_LEN,
+		  "ODPH_AHHDR_T__SIZE_ERROR");
 
 /**
  * @}
diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 812f5b9..6f0621b 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -87,7 +87,8 @@  static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 }
 
 /** @internal Compile time assert */
-_ODP_STATIC_ASSERT(sizeof(odph_udphdr_t) == ODPH_UDPHDR_LEN, "ODPH_UDPHDR_T__SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(odph_udphdr_t) == ODPH_UDPHDR_LEN,
+		  "ODPH_UDPHDR_T__SIZE_ERROR");
 
 /**
  * @}
diff --git a/include/odp/api/spec/debug.h b/include/odp/api/spec/debug.h
index 252a82f..0540268 100644
--- a/include/odp/api/spec/debug.h
+++ b/include/odp/api/spec/debug.h
@@ -17,31 +17,14 @@ 
 extern "C" {
 #endif
 
-#if defined(__GNUC__) && !defined(__clang__)
-
-
-#if __GNUC__ < 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ < 6))
-
-/**
- * @internal _Static_assert was only added in GCC 4.6. Provide a weak replacement
- * for previous versions.
- */
-#define _Static_assert(e, s) (extern int (*static_assert_checker(void)) \
-	[sizeof(struct { unsigned int error_if_negative:(e) ? 1 : -1; })])
-
-#endif
-
-
-
-#endif
-
-
 /**
- * @internal Compile time assertion-macro - fail compilation if cond is false.
- * This macro has zero runtime overhead
+ * @def ODP_STATIC_ASSERT
+ * Compile time assertion macro - fail compilation if cond if false.
+ *
+ * @param cond Conditional expression to be evaluated at compile time
+ *
+ * @param msg  Compile time error message to be displayed if cond is false
  */
-#define _ODP_STATIC_ASSERT(cond, msg)  _Static_assert(cond, msg)
-
 
 #ifdef __cplusplus
 }
diff --git a/platform/linux-generic/include/odp/api/debug.h b/platform/linux-generic/include/odp/api/debug.h
index dc1fce0..047b49d 100644
--- a/platform/linux-generic/include/odp/api/debug.h
+++ b/platform/linux-generic/include/odp/api/debug.h
@@ -19,6 +19,27 @@  extern "C" {
 
 #include <odp/api/spec/debug.h>
 
+#if defined(__GNUC__) && !defined(__clang__)
+
+#if __GNUC__ < 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ < 6))
+
+/**
+ * @internal _Static_assert was only added in GCC 4.6. Provide a weak replacement
+ * for previous versions.
+ */
+#define _Static_assert(e, s) (extern int (*static_assert_checker(void)) \
+	[sizeof(struct { unsigned int error_if_negative:(e) ? 1 : -1; })])
+
+#endif
+
+#endif
+
+/**
+ * @internal Compile time assertion-macro - fail compilation if cond is false.
+ * This macro has zero runtime overhead
+ */
+#define ODP_STATIC_ASSERT(cond, msg)  _Static_assert(cond, msg)
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h
index ea092ca..a7a3ffd 100644
--- a/platform/linux-generic/include/odp_buffer_internal.h
+++ b/platform/linux-generic/include/odp_buffer_internal.h
@@ -50,10 +50,10 @@  extern "C" {
 	((x) <= 65536 ? 16 : \
 	 (0/0)))))))))))))))))
 
-_ODP_STATIC_ASSERT(ODP_CONFIG_PACKET_SEG_LEN_MIN >= 256,
-		   "ODP Segment size must be a minimum of 256 bytes");
+ODP_STATIC_ASSERT(ODP_CONFIG_PACKET_SEG_LEN_MIN >= 256,
+		  "ODP Segment size must be a minimum of 256 bytes");
 
-_ODP_STATIC_ASSERT((ODP_CONFIG_PACKET_BUF_LEN_MAX %
+ODP_STATIC_ASSERT((ODP_CONFIG_PACKET_BUF_LEN_MAX %
 		   ODP_CONFIG_PACKET_SEG_LEN_MIN) == 0,
 		  "Packet max size must be a multiple of segment size");
 
@@ -146,8 +146,8 @@  struct odp_buffer_hdr_t {
 
 /** @internal Compile time assert that the
  * allocator field can handle any allocator id*/
-_ODP_STATIC_ASSERT(INT16_MAX >= ODP_THREAD_COUNT_MAX,
-		   "ODP_BUFFER_HDR_T__ALLOCATOR__SIZE_ERROR");
+ODP_STATIC_ASSERT(INT16_MAX >= ODP_THREAD_COUNT_MAX,
+		  "ODP_BUFFER_HDR_T__ALLOCATOR__SIZE_ERROR");
 
 typedef struct odp_buffer_hdr_stride {
 	uint8_t pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_buffer_hdr_t))];
diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index 92b770f..47f4ff8 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -74,8 +74,8 @@  typedef union {
 	};
 } input_flags_t;
 
-_ODP_STATIC_ASSERT(sizeof(input_flags_t) == sizeof(uint32_t),
-		   "INPUT_FLAGS_SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(input_flags_t) == sizeof(uint32_t),
+		  "INPUT_FLAGS_SIZE_ERROR");
 
 /**
  * Packet error flags
@@ -96,8 +96,8 @@  typedef union {
 	};
 } error_flags_t;
 
-_ODP_STATIC_ASSERT(sizeof(error_flags_t) == sizeof(uint32_t),
-		   "ERROR_FLAGS_SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(error_flags_t) == sizeof(uint32_t),
+		  "ERROR_FLAGS_SIZE_ERROR");
 
 /**
  * Packet output flags
@@ -117,8 +117,8 @@  typedef union {
 	};
 } output_flags_t;
 
-_ODP_STATIC_ASSERT(sizeof(output_flags_t) == sizeof(uint32_t),
-		   "OUTPUT_FLAGS_SIZE_ERROR");
+ODP_STATIC_ASSERT(sizeof(output_flags_t) == sizeof(uint32_t),
+		  "OUTPUT_FLAGS_SIZE_ERROR");
 
 /**
  * Internal Packet header
diff --git a/platform/linux-generic/include/odp_packet_io_queue.h b/platform/linux-generic/include/odp_packet_io_queue.h
index 12e2b9f..5843f6a 100644
--- a/platform/linux-generic/include/odp_packet_io_queue.h
+++ b/platform/linux-generic/include/odp_packet_io_queue.h
@@ -24,8 +24,8 @@  extern "C" {
 /** Max nbr of pkts to receive in one burst (keep same as QUEUE_MULTI_MAX) */
 #define ODP_PKTIN_QUEUE_MAX_BURST 16
 /* pktin_deq_multi() depends on the condition: */
-_ODP_STATIC_ASSERT(ODP_PKTIN_QUEUE_MAX_BURST >= QUEUE_MULTI_MAX,
-		   "ODP_PKTIN_DEQ_MULTI_MAX_ERROR");
+ODP_STATIC_ASSERT(ODP_PKTIN_QUEUE_MAX_BURST >= QUEUE_MULTI_MAX,
+		  "ODP_PKTIN_DEQ_MULTI_MAX_ERROR");
 
 int pktin_enqueue(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr, int sustain);
 odp_buffer_hdr_t *pktin_dequeue(queue_entry_t *queue);
diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h
index bc83e80..09a571b 100644
--- a/platform/linux-generic/include/odp_packet_socket.h
+++ b/platform/linux-generic/include/odp_packet_socket.h
@@ -65,8 +65,9 @@  struct ring {
 
 	struct tpacket_req req;
 };
-_ODP_STATIC_ASSERT(offsetof(struct ring, mm_space) <= ODP_CACHE_LINE_SIZE,
-		   "ERR_STRUCT_RING");
+
+ODP_STATIC_ASSERT(offsetof(struct ring, mm_space) <= ODP_CACHE_LINE_SIZE,
+		  "ERR_STRUCT_RING");
 
 /** Packet socket using mmap rings for both Rx and Tx */
 typedef struct {
diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c
index fd672e2..3d35ade 100644
--- a/platform/linux-generic/odp_cpumask.c
+++ b/platform/linux-generic/odp_cpumask.c
@@ -21,8 +21,8 @@ 
 #include <sys/types.h>
 
 /** @internal Compile time assert */
-_ODP_STATIC_ASSERT(CPU_SETSIZE >= ODP_CPUMASK_SIZE,
-		   "ODP_CPUMASK_SIZE__SIZE_ERROR");
+ODP_STATIC_ASSERT(CPU_SETSIZE >= ODP_CPUMASK_SIZE,
+		  "ODP_CPUMASK_SIZE__SIZE_ERROR");
 
 void odp_cpumask_from_str(odp_cpumask_t *mask, const char *str_in)
 {
diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c
index 14a1197..0595e70 100644
--- a/platform/linux-generic/odp_schedule.c
+++ b/platform/linux-generic/odp_schedule.c
@@ -45,8 +45,8 @@  odp_thrmask_t sched_mask_all;
 /* Mask of queues per priority */
 typedef uint8_t pri_mask_t;
 
-_ODP_STATIC_ASSERT((8*sizeof(pri_mask_t)) >= QUEUES_PER_PRIO,
-		   "pri_mask_t_is_too_small");
+ODP_STATIC_ASSERT((8 * sizeof(pri_mask_t)) >= QUEUES_PER_PRIO,
+		  "pri_mask_t_is_too_small");
 
 /* Internal: Start of named groups in group mask arrays */
 #define _ODP_SCHED_GROUP_NAMED (ODP_SCHED_GROUP_CONTROL + 1)
diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c
index 6364105..0beff37 100644
--- a/platform/linux-generic/odp_shared_memory.c
+++ b/platform/linux-generic/odp_shared_memory.c
@@ -28,8 +28,8 @@ 
 #include <string.h>
 #include <errno.h>
 
-_ODP_STATIC_ASSERT(ODP_CONFIG_SHM_BLOCKS >= ODP_CONFIG_POOLS,
-		   "ODP_CONFIG_SHM_BLOCKS < ODP_CONFIG_POOLS");
+ODP_STATIC_ASSERT(ODP_CONFIG_SHM_BLOCKS >= ODP_CONFIG_POOLS,
+		  "ODP_CONFIG_SHM_BLOCKS < ODP_CONFIG_POOLS");
 
 typedef struct {
 	char      name[ODP_SHM_NAME_LEN];
diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
index ac72709..f4fb1f6 100644
--- a/platform/linux-generic/odp_timer.c
+++ b/platform/linux-generic/odp_timer.c
@@ -107,7 +107,7 @@  ODP_ALIGNED(16) /* 16-byte atomic operations need properly aligned addresses */
 #endif
 ;
 
-_ODP_STATIC_ASSERT(sizeof(tick_buf_t) == 16, "sizeof(tick_buf_t) == 16");
+ODP_STATIC_ASSERT(sizeof(tick_buf_t) == 16, "sizeof(tick_buf_t) == 16");
 
 typedef struct odp_timer_s {
 	void *user_ptr;
diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c
index ad8dc55..18fa5c6 100644
--- a/platform/linux-generic/pktio/ipc.c
+++ b/platform/linux-generic/pktio/ipc.c
@@ -396,8 +396,8 @@  static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED,
 	int ret = -1;
 	int slave;
 
-	_ODP_STATIC_ASSERT(ODP_POOL_NAME_LEN == _RING_NAMESIZE,
-			   "mismatch pool and ring name arrays");
+	ODP_STATIC_ASSERT(ODP_POOL_NAME_LEN == _RING_NAMESIZE,
+			  "mismatch pool and ring name arrays");
 
 	if (strncmp(dev, "ipc", 3))
 		return -1;