* [dpdk-dev] [PATCH] eal: fix type of pointer arithmetic result
@ 2013-07-26 11:34 Thomas Monjalon
2013-07-26 12:12 ` Adrien Mazarguil
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Monjalon @ 2013-07-26 11:34 UTC (permalink / raw)
To: dev
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@6wind.com>
---
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 [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] eal: fix type of pointer arithmetic result
2013-07-26 11:34 [dpdk-dev] [PATCH] eal: fix type of pointer arithmetic result Thomas Monjalon
@ 2013-07-26 12:12 ` Adrien Mazarguil
2013-07-26 13:21 ` Thomas Monjalon
0 siblings, 1 reply; 3+ messages in thread
From: Adrien Mazarguil @ 2013-07-26 12:12 UTC (permalink / raw)
To: Thomas Monjalon; +Cc: dev
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@6wind.com>
> ---
> lib/librte_eal/common/include/rte_common.h | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
Acked-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
--
Adrien Mazarguil
6WIND
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] eal: fix type of pointer arithmetic result
2013-07-26 12:12 ` Adrien Mazarguil
@ 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
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@6wind.com>
> > ---
> >
> > lib/librte_eal/common/include/rte_common.h | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
>
> Acked-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
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 [dpdk-dev] [PATCH] eal: fix type of pointer arithmetic result Thomas Monjalon
2013-07-26 12:12 ` Adrien Mazarguil
2013-07-26 13:21 ` 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).