DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] mempool: fix empty structure definition
@ 2016-07-13 12:30 Adrien Mazarguil
  2016-07-13 13:13 ` Olivier MATZ
  0 siblings, 1 reply; 3+ messages in thread
From: Adrien Mazarguil @ 2016-07-13 12:30 UTC (permalink / raw)
  To: dev; +Cc: Olivier Matz

This commit addresses the following warning reported by clang, which
happens by default, as long as CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG is disabled:

 warning: empty struct has size 0 in C, size 1 in C++

C and C++ must use the same size for objects to avoid corruption during run
time.

Fixes: 97e7e685bfcd ("mempool: add structure for object trailers")

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 lib/librte_mempool/rte_mempool.c | 4 ++++
 lib/librte_mempool/rte_mempool.h | 6 ++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index 6ec0906..8806633 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -199,7 +199,11 @@ rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
 		sz->header_size = RTE_ALIGN_CEIL(sz->header_size,
 			RTE_MEMPOOL_ALIGN);
 
+#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
 	sz->trailer_size = sizeof(struct rte_mempool_objtlr);
+#else
+	sz->trailer_size = 0;
+#endif
 
 	/* element size is 8 bytes-aligned at least */
 	sz->elt_size = RTE_ALIGN_CEIL(elt_size, sizeof(uint64_t));
diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h
index fb7052e..4a8fbb1 100644
--- a/lib/librte_mempool/rte_mempool.h
+++ b/lib/librte_mempool/rte_mempool.h
@@ -163,6 +163,8 @@ struct rte_mempool_objhdr {
  */
 STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr);
 
+#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
+
 /**
  * Mempool object trailer structure
  *
@@ -170,11 +172,11 @@ STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr);
  * trailer structure containing a cookie preventing memory corruptions.
  */
 struct rte_mempool_objtlr {
-#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
 	uint64_t cookie;                 /**< Debug cookie. */
-#endif
 };
 
+#endif
+
 /**
  * A list of memory where objects are stored
  */
-- 
2.1.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] mempool: fix empty structure definition
  2016-07-13 12:30 [dpdk-dev] [PATCH] mempool: fix empty structure definition Adrien Mazarguil
@ 2016-07-13 13:13 ` Olivier MATZ
  2016-07-15 15:17   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Olivier MATZ @ 2016-07-13 13:13 UTC (permalink / raw)
  To: Adrien Mazarguil, dev


On 07/13/2016 02:30 PM, Adrien Mazarguil wrote:
> This commit addresses the following warning reported by clang, which
> happens by default, as long as CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG is disabled:
>
>   warning: empty struct has size 0 in C, size 1 in C++
>
> C and C++ must use the same size for objects to avoid corruption during run
> time.
>
> Fixes: 97e7e685bfcd ("mempool: add structure for object trailers")
>
> Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>

Acked-by: Olivier Matz <olivier.matz@6wind.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] mempool: fix empty structure definition
  2016-07-13 13:13 ` Olivier MATZ
@ 2016-07-15 15:17   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2016-07-15 15:17 UTC (permalink / raw)
  To: Adrien Mazarguil; +Cc: dev, Olivier MATZ

> > This commit addresses the following warning reported by clang, which
> > happens by default, as long as CONFIG_RTE_LIBRTE_MEMPOOL_DEBUG is disabled:
> >
> >   warning: empty struct has size 0 in C, size 1 in C++
> >
> > C and C++ must use the same size for objects to avoid corruption during run
> > time.
> >
> > Fixes: 97e7e685bfcd ("mempool: add structure for object trailers")
> >
> > Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
> 
> Acked-by: Olivier Matz <olivier.matz@6wind.com>

Applied, thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-15 15:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-13 12:30 [dpdk-dev] [PATCH] mempool: fix empty structure definition Adrien Mazarguil
2016-07-13 13:13 ` Olivier MATZ
2016-07-15 15:17   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).