[v2,10/21] test: use C11 alignof

Message ID 1707849292-19519-11-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series use C11 alignof |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff Feb. 13, 2024, 6:34 p.m. UTC
  Replace use of __alignof__(T) with C11 alignof(T) to improve portability
between toolchains.

Replace use of __alignof__(e) with C11 alignof(typeof(e)) to improve
portability between toolchains

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 app/test/test_distributor.c      | 3 ++-
 app/test/test_graph.c            | 3 ++-
 app/test/test_mbuf.c             | 9 +++++----
 app/test/test_ring_stress_impl.h | 6 ++++--
 4 files changed, 13 insertions(+), 8 deletions(-)
  

Patch

diff --git a/app/test/test_distributor.c b/app/test/test_distributor.c
index 6cb27f4..d2037b7 100644
--- a/app/test/test_distributor.c
+++ b/app/test/test_distributor.c
@@ -5,6 +5,7 @@ 
 #include "test.h"
 
 #include <unistd.h>
+#include <stdalign.h>
 #include <string.h>
 #include <rte_cycles.h>
 #include <rte_errno.h>
@@ -831,7 +832,7 @@  int test_error_distributor_create_numworkers(void)
 	static const struct rte_mbuf_dynfield seq_dynfield_desc = {
 		.name = "test_distributor_dynfield_seq",
 		.size = sizeof(seq_dynfield_t),
-		.align = __alignof__(seq_dynfield_t),
+		.align = alignof(seq_dynfield_t),
 	};
 	seq_dynfield_offset =
 		rte_mbuf_dynfield_register(&seq_dynfield_desc);
diff --git a/app/test/test_graph.c b/app/test/test_graph.c
index 3dd017e..b8409bc 100644
--- a/app/test/test_graph.c
+++ b/app/test/test_graph.c
@@ -7,6 +7,7 @@ 
 #include <assert.h>
 #include <inttypes.h>
 #include <signal.h>
+#include <stdalign.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
@@ -935,7 +936,7 @@  struct test_node_register {
 	static const struct rte_mbuf_dynfield graph_dynfield_desc = {
 		.name = "test_graph_dynfield",
 		.size = sizeof(graph_dynfield_t),
-		.align = __alignof__(graph_dynfield_t),
+		.align = alignof(graph_dynfield_t),
 	};
 	graph_dynfield_offset =
 		rte_mbuf_dynfield_register(&graph_dynfield_desc);
diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c
index d7393df..51ea6ef 100644
--- a/app/test/test_mbuf.c
+++ b/app/test/test_mbuf.c
@@ -5,6 +5,7 @@ 
 #include "test.h"
 
 #include <string.h>
+#include <stdalign.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -2534,19 +2535,19 @@  struct test_case {
 	const struct rte_mbuf_dynfield dynfield = {
 		.name = "test-dynfield",
 		.size = sizeof(uint8_t),
-		.align = __alignof__(uint8_t),
+		.align = alignof(uint8_t),
 		.flags = 0,
 	};
 	const struct rte_mbuf_dynfield dynfield2 = {
 		.name = "test-dynfield2",
 		.size = sizeof(uint16_t),
-		.align = __alignof__(uint16_t),
+		.align = alignof(uint16_t),
 		.flags = 0,
 	};
 	const struct rte_mbuf_dynfield dynfield3 = {
 		.name = "test-dynfield3",
 		.size = sizeof(uint8_t),
-		.align = __alignof__(uint8_t),
+		.align = alignof(uint8_t),
 		.flags = 0,
 	};
 	const struct rte_mbuf_dynfield dynfield_fail_big = {
@@ -2564,7 +2565,7 @@  struct test_case {
 	const struct rte_mbuf_dynfield dynfield_fail_flag = {
 		.name = "test-dynfield",
 		.size = sizeof(uint8_t),
-		.align = __alignof__(uint8_t),
+		.align = alignof(uint8_t),
 		.flags = 1,
 	};
 	const struct rte_mbuf_dynflag dynflag_fail_flag = {
diff --git a/app/test/test_ring_stress_impl.h b/app/test/test_ring_stress_impl.h
index 62f046a..2dec897 100644
--- a/app/test/test_ring_stress_impl.h
+++ b/app/test/test_ring_stress_impl.h
@@ -2,6 +2,8 @@ 
  * Copyright(c) 2020 Intel Corporation
  */
 
+#include <stdalign.h>
+
 #include "test_ring_stress.h"
 
 /**
@@ -285,7 +287,7 @@  struct ring_elem {
 	*data = NULL;
 
 	sz = num * sizeof(*elm);
-	elm = rte_zmalloc(NULL, sz, __alignof__(*elm));
+	elm = rte_zmalloc(NULL, sz, alignof(typeof(*elm)));
 	if (elm == NULL) {
 		printf("%s: alloc(%zu) for %u elems data failed",
 			__func__, sz, num);
@@ -297,7 +299,7 @@  struct ring_elem {
 	/* alloc ring */
 	nr = 2 * num;
 	sz = rte_ring_get_memsize(nr);
-	r = rte_zmalloc(NULL, sz, __alignof__(*r));
+	r = rte_zmalloc(NULL, sz, alignof(typeof(*r)));
 	if (r == NULL) {
 		printf("%s: alloc(%zu) for FIFO with %u elems failed",
 			__func__, sz, nr);