diff mbox

linux-generic: strong_types: simplify casting

Message ID 1423555540-7820-1-git-send-email-taras.kondratiuk@linaro.org
State Accepted
Commit 4d2b599401303dd050813212086d39ed07b2789f
Headers show

Commit Message

Taras Kondratiuk Feb. 10, 2015, 8:05 a.m. UTC
Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
---
 platform/linux-generic/include/odp/plat/strong_types.h | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

Comments

Bill Fischofer Feb. 10, 2015, 1:20 p.m. UTC | #1
This is a simpler and cleaner version of the original and seems to work
just as well.  Thanks.

On Tue, Feb 10, 2015 at 2:05 AM, Taras Kondratiuk <
taras.kondratiuk@linaro.org> wrote:

> Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
>

Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org>


> ---
>  platform/linux-generic/include/odp/plat/strong_types.h | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
>
> diff --git a/platform/linux-generic/include/odp/plat/strong_types.h
> b/platform/linux-generic/include/odp/plat/strong_types.h
> index a49c9d6..eacabba 100644
> --- a/platform/linux-generic/include/odp/plat/strong_types.h
> +++ b/platform/linux-generic/include/odp/plat/strong_types.h
> @@ -20,21 +20,13 @@
>  /** Use strong typing for ODP types */
>  #define odp_handle_t struct {} *
>
> -/** Internal typedefs for ODP strong type manipulation */
> -typedef odp_handle_t _odp_handle_t;
> -
> -typedef union {
> -       _odp_handle_t hdl;
> -       uint32_t val;
> -} _odp_handle_u;
> -
>  /** Internal macro to get value of an ODP handle */
> -#define _odp_typeval(handle) (((_odp_handle_u)(_odp_handle_t)handle).val)
> +#define _odp_typeval(handle) ((uint32_t)(uintptr_t)(handle))
>
>  /** Internal macro to get printable value of an ODP handle */
>  #define _odp_pri(handle) ((uint64_t)_odp_typeval(handle))
>
>  /** Internal macro to convert a scalar to a typed handle */
> -#define _odp_cast_scalar(type, val) ((type)(size_t)(val))
> +#define _odp_cast_scalar(type, val) ((type)(uintptr_t)(val))
>
>  #endif
> --
> 1.9.1
>
>
Maxim Uvarov Feb. 11, 2015, 4 a.m. UTC | #2
Merged!

Maxim.

On 02/10/2015 04:20 PM, Bill Fischofer wrote:
> This is a simpler and cleaner version of the original and seems to 
> work just as well.  Thanks.
>
> On Tue, Feb 10, 2015 at 2:05 AM, Taras Kondratiuk 
> <taras.kondratiuk@linaro.org <mailto:taras.kondratiuk@linaro.org>> wrote:
>
>     Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org
>     <mailto:taras.kondratiuk@linaro.org>>
>
>
> Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org 
> <mailto:bill.fischofer@linaro.org>>
>
>     ---
>      platform/linux-generic/include/odp/plat/strong_types.h | 12
>     ++----------
>      1 file changed, 2 insertions(+), 10 deletions(-)
>
>     diff --git
>     a/platform/linux-generic/include/odp/plat/strong_types.h
>     b/platform/linux-generic/include/odp/plat/strong_types.h
>     index a49c9d6..eacabba 100644
>     --- a/platform/linux-generic/include/odp/plat/strong_types.h
>     +++ b/platform/linux-generic/include/odp/plat/strong_types.h
>     @@ -20,21 +20,13 @@
>      /** Use strong typing for ODP types */
>      #define odp_handle_t struct {} *
>
>     -/** Internal typedefs for ODP strong type manipulation */
>     -typedef odp_handle_t _odp_handle_t;
>     -
>     -typedef union {
>     -       _odp_handle_t hdl;
>     -       uint32_t val;
>     -} _odp_handle_u;
>     -
>      /** Internal macro to get value of an ODP handle */
>     -#define _odp_typeval(handle)
>     (((_odp_handle_u)(_odp_handle_t)handle).val)
>     +#define _odp_typeval(handle) ((uint32_t)(uintptr_t)(handle))
>
>      /** Internal macro to get printable value of an ODP handle */
>      #define _odp_pri(handle) ((uint64_t)_odp_typeval(handle))
>
>      /** Internal macro to convert a scalar to a typed handle */
>     -#define _odp_cast_scalar(type, val) ((type)(size_t)(val))
>     +#define _odp_cast_scalar(type, val) ((type)(uintptr_t)(val))
>
>      #endif
>     --
>     1.9.1
>
>
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp/plat/strong_types.h b/platform/linux-generic/include/odp/plat/strong_types.h
index a49c9d6..eacabba 100644
--- a/platform/linux-generic/include/odp/plat/strong_types.h
+++ b/platform/linux-generic/include/odp/plat/strong_types.h
@@ -20,21 +20,13 @@ 
 /** Use strong typing for ODP types */
 #define odp_handle_t struct {} *
 
-/** Internal typedefs for ODP strong type manipulation */
-typedef odp_handle_t _odp_handle_t;
-
-typedef union {
-	_odp_handle_t hdl;
-	uint32_t val;
-} _odp_handle_u;
-
 /** Internal macro to get value of an ODP handle */
-#define _odp_typeval(handle) (((_odp_handle_u)(_odp_handle_t)handle).val)
+#define _odp_typeval(handle) ((uint32_t)(uintptr_t)(handle))
 
 /** Internal macro to get printable value of an ODP handle */
 #define _odp_pri(handle) ((uint64_t)_odp_typeval(handle))
 
 /** Internal macro to convert a scalar to a typed handle */
-#define _odp_cast_scalar(type, val) ((type)(size_t)(val))
+#define _odp_cast_scalar(type, val) ((type)(uintptr_t)(val))
 
 #endif