All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] eal: fix type of pointer arithmetic result
@ 2013-07-26 11:34 Thomas Monjalon
       [not found] ` <1374838440-21429-1-git-send-email-thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Monjalon @ 2013-07-26 11:34 UTC (permalink / raw)
  To: dev-VfR2kkLFssw

Adding or subtracting a value to a pointer makes a new pointer
of unknown type.
So typeof() is replaced by (void*) in RTE_PTR_ADD() and RTE_PTR_SUB().

But RTE_PTR_ALIGN_* macros have in their explicit API to return a pointer
of the same type. Since RTE_PTR_ALIGN_CEIL is based on RTE_PTR_ADD, a
typeof() is added to keep the original behaviour.

Signed-off-by: Thomas Monjalon <thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
---
 lib/librte_eal/common/include/rte_common.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 96aeeee..d2e096d 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -70,12 +70,12 @@ extern "C" {
 /**
  * add a byte-value offset from a pointer
  */
-#define RTE_PTR_ADD(ptr, x) ((typeof(ptr))((uintptr_t)ptr + (x)))
+#define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)ptr + (x)))
 
 /**
  * subtract a byte-value offset from a pointer
  */
-#define RTE_PTR_SUB(ptr, x) ((typeof(ptr))((uintptr_t)ptr - (x)))
+#define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x)))
 
 /**
  * get the difference between two pointer values, i.e. how far apart
@@ -131,7 +131,7 @@ rte_align_floor_int(uintptr_t ptr, uintptr_t align)
  * must be a power-of-two value.
  */
 #define RTE_PTR_ALIGN_CEIL(ptr, align) \
-	RTE_PTR_ALIGN_FLOOR(RTE_PTR_ADD(ptr, align - 1), align)
+	RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, align - 1), align)
 
 /**
  * Macro to align a value to a given power-of-two. The resultant value
-- 
1.7.10.4

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

* Re: [PATCH] eal: fix type of pointer arithmetic result
       [not found] ` <1374838440-21429-1-git-send-email-thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
@ 2013-07-26 12:12   ` Adrien Mazarguil
       [not found]     ` <20130726121244.GK7849-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Adrien Mazarguil @ 2013-07-26 12:12 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev-VfR2kkLFssw

On Fri, Jul 26, 2013 at 01:34:00PM +0200, Thomas Monjalon wrote:
> Adding or subtracting a value to a pointer makes a new pointer
> of unknown type.
> So typeof() is replaced by (void*) in RTE_PTR_ADD() and RTE_PTR_SUB().
> 
> But RTE_PTR_ALIGN_* macros have in their explicit API to return a pointer
> of the same type. Since RTE_PTR_ALIGN_CEIL is based on RTE_PTR_ADD, a
> typeof() is added to keep the original behaviour.
> 
> Signed-off-by: Thomas Monjalon <thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
> ---
>  lib/librte_eal/common/include/rte_common.h |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Acked-by: Adrien Mazarguil <adrien.mazarguil-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>

-- 
Adrien Mazarguil
6WIND

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

* Re: [PATCH] eal: fix type of pointer arithmetic result
       [not found]     ` <20130726121244.GK7849-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
@ 2013-07-26 13:21       ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2013-07-26 13:21 UTC (permalink / raw)
  To: Adrien Mazarguil; +Cc: dev-VfR2kkLFssw

26/07/2013 14:12, Adrien Mazarguil :
> On Fri, Jul 26, 2013 at 01:34:00PM +0200, Thomas Monjalon wrote:
> > Adding or subtracting a value to a pointer makes a new pointer
> > of unknown type.
> > So typeof() is replaced by (void*) in RTE_PTR_ADD() and RTE_PTR_SUB().
> > 
> > But RTE_PTR_ALIGN_* macros have in their explicit API to return a pointer
> > of the same type. Since RTE_PTR_ALIGN_CEIL is based on RTE_PTR_ADD, a
> > typeof() is added to keep the original behaviour.
> > 
> > Signed-off-by: Thomas Monjalon <thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
> > ---
> > 
> >  lib/librte_eal/common/include/rte_common.h |    6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> Acked-by: Adrien Mazarguil <adrien.mazarguil-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>

pushed

-- 
Thomas

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

end of thread, other threads:[~2013-07-26 13:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-26 11:34 [PATCH] eal: fix type of pointer arithmetic result Thomas Monjalon
     [not found] ` <1374838440-21429-1-git-send-email-thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
2013-07-26 12:12   ` Adrien Mazarguil
     [not found]     ` <20130726121244.GK7849-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
2013-07-26 13:21       ` Thomas Monjalon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.