diff mbox

[PATCHv2] linux-generic: strongtypes: use named structs for C++

Message ID 1427144186-29550-1-git-send-email-ola.liljedahl@linaro.org
State Accepted
Commit 2a9794106a29b6f7c5bfabe58cb9853f0a238bff
Headers show

Commit Message

Ola Liljedahl March 23, 2015, 8:56 p.m. UTC
Typedefs to anonymous structs creates problems for C++ programs:
GCC:
warning: ‘odp_crypto_op_params’ has a field ‘odp_crypto_op_params::pkt’
whose type uses the anonymous namespace
error: anonymous type with no linkage used to declare function
‘<anonymous struct>* ppp_packet::get_queue() const’ with linkage
CLANG:
extern odp_pool_t tmo_pool;
warning: variable 'tmo_pool' has internal linkage but is not defined
When linking:
undefined reference to `tmo_pool'

The solution is to add a (unique) name to all structs used by the strong
typing typedefs.

Signed-off-by: Ola Liljedahl <ola.liljedahl@linaro.org>
---
(This document/code contribution attached is provided under the terms of
agreement LES-LTM-21309)

v2:
Restored doxygen support.

 doc/doxygen.cfg                                                | 3 ++-
 platform/linux-generic/include/odp/plat/buffer_types.h         | 4 ++--
 platform/linux-generic/include/odp/plat/classification_types.h | 8 ++++----
 platform/linux-generic/include/odp/plat/crypto_types.h         | 2 +-
 platform/linux-generic/include/odp/plat/event_types.h          | 2 +-
 platform/linux-generic/include/odp/plat/packet_io_types.h      | 2 +-
 platform/linux-generic/include/odp/plat/packet_types.h         | 4 ++--
 platform/linux-generic/include/odp/plat/pool_types.h           | 2 +-
 platform/linux-generic/include/odp/plat/queue_types.h          | 4 ++--
 platform/linux-generic/include/odp/plat/shared_memory_types.h  | 2 +-
 platform/linux-generic/include/odp/plat/strong_types.h         | 6 ++++++
 11 files changed, 23 insertions(+), 16 deletions(-)

Comments

Bill Fischofer March 24, 2015, 12:29 a.m. UTC | #1
On Mon, Mar 23, 2015 at 3:56 PM, Ola Liljedahl <ola.liljedahl@linaro.org>
wrote:

> Typedefs to anonymous structs creates problems for C++ programs:
> GCC:
> warning: ‘odp_crypto_op_params’ has a field ‘odp_crypto_op_params::pkt’
> whose type uses the anonymous namespace
> error: anonymous type with no linkage used to declare function
> ‘<anonymous struct>* ppp_packet::get_queue() const’ with linkage
> CLANG:
> extern odp_pool_t tmo_pool;
> warning: variable 'tmo_pool' has internal linkage but is not defined
> When linking:
> undefined reference to `tmo_pool'
>
> The solution is to add a (unique) name to all structs used by the strong
> typing typedefs.
>
> Signed-off-by: Ola Liljedahl <ola.liljedahl@linaro.org>
>

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


> ---
> (This document/code contribution attached is provided under the terms of
> agreement LES-LTM-21309)
>
> v2:
> Restored doxygen support.
>
>  doc/doxygen.cfg                                                | 3 ++-
>  platform/linux-generic/include/odp/plat/buffer_types.h         | 4 ++--
>  platform/linux-generic/include/odp/plat/classification_types.h | 8
> ++++----
>  platform/linux-generic/include/odp/plat/crypto_types.h         | 2 +-
>  platform/linux-generic/include/odp/plat/event_types.h          | 2 +-
>  platform/linux-generic/include/odp/plat/packet_io_types.h      | 2 +-
>  platform/linux-generic/include/odp/plat/packet_types.h         | 4 ++--
>  platform/linux-generic/include/odp/plat/pool_types.h           | 2 +-
>  platform/linux-generic/include/odp/plat/queue_types.h          | 4 ++--
>  platform/linux-generic/include/odp/plat/shared_memory_types.h  | 2 +-
>  platform/linux-generic/include/odp/plat/strong_types.h         | 6 ++++++
>  11 files changed, 23 insertions(+), 16 deletions(-)
>
> diff --git a/doc/doxygen.cfg b/doc/doxygen.cfg
> index 2d45a76..52c83a9 100644
> --- a/doc/doxygen.cfg
> +++ b/doc/doxygen.cfg
> @@ -38,5 +38,6 @@ PREDEFINED = __GNUC__ \
>              __BIG_ENDIAN_BITFIELD \
>              __LITTLE_ENDIAN_BITFIELD \
>              __x86_64__ \
> -            ODP_PACKED
> +            ODP_PACKED \
> +            "ODP_HANDLE_T(type)=odp_handle_t type"
>  INTERNAL_DOCS = YES
> diff --git a/platform/linux-generic/include/odp/plat/buffer_types.h
> b/platform/linux-generic/include/odp/plat/buffer_types.h
> index 3e7070e..0c017ae 100644
> --- a/platform/linux-generic/include/odp/plat/buffer_types.h
> +++ b/platform/linux-generic/include/odp/plat/buffer_types.h
> @@ -26,13 +26,13 @@ extern "C" {
>   */
>
>  /** ODP buffer */
> -typedef odp_handle_t odp_buffer_t;
> +typedef ODP_HANDLE_T(odp_buffer_t);
>
>  /** Invalid buffer */
>  #define ODP_BUFFER_INVALID _odp_cast_scalar(odp_buffer_t, 0xffffffff)
>
>  /** ODP buffer segment */
> -typedef odp_handle_t odp_buffer_seg_t;
> +typedef ODP_HANDLE_T(odp_buffer_seg_t);
>
>  /** Invalid segment */
>  #define ODP_SEGMENT_INVALID ((odp_buffer_seg_t)ODP_BUFFER_INVALID)
> diff --git
> a/platform/linux-generic/include/odp/plat/classification_types.h
> b/platform/linux-generic/include/odp/plat/classification_types.h
> index 042d8c8..767da7d 100644
> --- a/platform/linux-generic/include/odp/plat/classification_types.h
> +++ b/platform/linux-generic/include/odp/plat/classification_types.h
> @@ -23,18 +23,18 @@ extern "C" {
>   *  @{
>   */
>
> -typedef odp_handle_t odp_cos_t;
> -typedef odp_handle_t odp_flowsig_t;
> +typedef ODP_HANDLE_T(odp_cos_t);
> +typedef ODP_HANDLE_T(odp_flowsig_t);
>
>  #define ODP_COS_INVALID  _odp_cast_scalar(odp_cos_t, ~0)
>  #define ODP_COS_NAME_LEN 32
>
>  typedef uint16_t odp_cos_flow_set_t;
>
> -typedef odp_handle_t odp_pmr_t;
> +typedef ODP_HANDLE_T(odp_pmr_t);
>  #define ODP_PMR_INVAL _odp_cast_scalar(odp_pmr_t, ~0)
>
> -typedef odp_handle_t odp_pmr_set_t;
> +typedef ODP_HANDLE_T(odp_pmr_set_t);
>  #define ODP_PMR_SET_INVAL _odp_cast_scalar(odp_pmr_set_t, ~0)
>
>  /** Get printable format of odp_cos_t */
> diff --git a/platform/linux-generic/include/odp/plat/crypto_types.h
> b/platform/linux-generic/include/odp/plat/crypto_types.h
> index 1b10a5d..a91d88e 100644
> --- a/platform/linux-generic/include/odp/plat/crypto_types.h
> +++ b/platform/linux-generic/include/odp/plat/crypto_types.h
> @@ -25,7 +25,7 @@ extern "C" {
>  #define ODP_CRYPTO_SESSION_INVALID (0xffffffffffffffffULL)
>
>  typedef uint64_t odp_crypto_session_t;
> -typedef odp_handle_t odp_crypto_compl_t;
> +typedef ODP_HANDLE_T(odp_crypto_compl_t);
>
>  enum odp_crypto_op_mode {
>         ODP_CRYPTO_SYNC,
> diff --git a/platform/linux-generic/include/odp/plat/event_types.h
> b/platform/linux-generic/include/odp/plat/event_types.h
> index 24be22f..d91937d 100644
> --- a/platform/linux-generic/include/odp/plat/event_types.h
> +++ b/platform/linux-generic/include/odp/plat/event_types.h
> @@ -26,7 +26,7 @@ extern "C" {
>   *  @{
>   */
>
> -typedef odp_handle_t odp_event_t;
> +typedef ODP_HANDLE_T(odp_event_t);
>
>  #define ODP_EVENT_INVALID _odp_cast_scalar(odp_event_t, 0xffffffff)
>
> diff --git a/platform/linux-generic/include/odp/plat/packet_io_types.h
> b/platform/linux-generic/include/odp/plat/packet_io_types.h
> index 60592e3..3cc64c6 100644
> --- a/platform/linux-generic/include/odp/plat/packet_io_types.h
> +++ b/platform/linux-generic/include/odp/plat/packet_io_types.h
> @@ -26,7 +26,7 @@ extern "C" {
>   *  @{
>   */
>
> -typedef odp_handle_t odp_pktio_t;
> +typedef ODP_HANDLE_T(odp_pktio_t);
>
>  #define ODP_PKTIO_INVALID _odp_cast_scalar(odp_pktio_t, 0)
>
> diff --git a/platform/linux-generic/include/odp/plat/packet_types.h
> b/platform/linux-generic/include/odp/plat/packet_types.h
> index 57e9662..45cb801 100644
> --- a/platform/linux-generic/include/odp/plat/packet_types.h
> +++ b/platform/linux-generic/include/odp/plat/packet_types.h
> @@ -26,13 +26,13 @@ extern "C" {
>   *  @{
>   */
>
> -typedef odp_handle_t odp_packet_t;
> +typedef ODP_HANDLE_T(odp_packet_t);
>
>  #define ODP_PACKET_INVALID _odp_cast_scalar(odp_packet_t, 0xffffffff)
>
>  #define ODP_PACKET_OFFSET_INVALID (0x0fffffff)
>
> -typedef odp_handle_t odp_packet_seg_t;
> +typedef ODP_HANDLE_T(odp_packet_seg_t);
>
>  #define ODP_PACKET_SEG_INVALID _odp_cast_scalar(odp_packet_seg_t,
> 0xffffffff)
>
> diff --git a/platform/linux-generic/include/odp/plat/pool_types.h
> b/platform/linux-generic/include/odp/plat/pool_types.h
> index 71c7783..568556f 100644
> --- a/platform/linux-generic/include/odp/plat/pool_types.h
> +++ b/platform/linux-generic/include/odp/plat/pool_types.h
> @@ -25,7 +25,7 @@ extern "C" {
>   *  @{
>   */
>
> -typedef odp_handle_t odp_pool_t;
> +typedef ODP_HANDLE_T(odp_pool_t);
>
>  #define ODP_POOL_INVALID _odp_cast_scalar(odp_pool_t, 0xffffffff)
>
> diff --git a/platform/linux-generic/include/odp/plat/queue_types.h
> b/platform/linux-generic/include/odp/plat/queue_types.h
> index 04a0be9..1cecc90 100644
> --- a/platform/linux-generic/include/odp/plat/queue_types.h
> +++ b/platform/linux-generic/include/odp/plat/queue_types.h
> @@ -25,9 +25,9 @@ extern "C" {
>   *  @{
>   */
>
> -typedef odp_handle_t odp_queue_t;
> +typedef ODP_HANDLE_T(odp_queue_t);
>
> -typedef odp_handle_t odp_queue_group_t;
> +typedef ODP_HANDLE_T(odp_queue_group_t);
>
>  #define ODP_QUEUE_INVALID  _odp_cast_scalar(odp_queue_t, 0)
>
> diff --git a/platform/linux-generic/include/odp/plat/shared_memory_types.h
> b/platform/linux-generic/include/odp/plat/shared_memory_types.h
> index d2e92cf..4be7356 100644
> --- a/platform/linux-generic/include/odp/plat/shared_memory_types.h
> +++ b/platform/linux-generic/include/odp/plat/shared_memory_types.h
> @@ -26,7 +26,7 @@ extern "C" {
>   *  @{
>   */
>
> -typedef odp_handle_t odp_shm_t;
> +typedef ODP_HANDLE_T(odp_shm_t);
>
>  #define ODP_SHM_INVALID _odp_cast_scalar(odp_shm_t, 0)
>  #define ODP_SHM_NULL ODP_SHM_INVALID
> diff --git a/platform/linux-generic/include/odp/plat/strong_types.h
> b/platform/linux-generic/include/odp/plat/strong_types.h
> index cd15853..a53d763 100644
> --- a/platform/linux-generic/include/odp/plat/strong_types.h
> +++ b/platform/linux-generic/include/odp/plat/strong_types.h
> @@ -16,7 +16,13 @@
>  #define STRONG_TYPES_H_
>
>  /** Use strong typing for ODP types */
> +#ifdef __cplusplus
> +#define ODP_HANDLE_T(type) struct _##type { uint8_t unused_dummy_var; }
> *type
> +#else
>  #define odp_handle_t struct { uint8_t unused_dummy_var; } *
> +/** C/C++ helper macro for strong typing */
> +#define ODP_HANDLE_T(type) odp_handle_t type
> +#endif
>
>  /** Internal macro to get value of an ODP handle */
>  #define _odp_typeval(handle) ((uint32_t)(uintptr_t)(handle))
> --
> 1.9.1
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
Maxim Uvarov March 25, 2015, 3:15 p.m. UTC | #2
Merged,
Maxim.

On 03/24/15 03:29, Bill Fischofer wrote:
>
>
> On Mon, Mar 23, 2015 at 3:56 PM, Ola Liljedahl 
> <ola.liljedahl@linaro.org <mailto:ola.liljedahl@linaro.org>> wrote:
>
>     Typedefs to anonymous structs creates problems for C++ programs:
>     GCC:
>     warning: ‘odp_crypto_op_params’ has a field
>     ‘odp_crypto_op_params::pkt’
>     whose type uses the anonymous namespace
>     error: anonymous type with no linkage used to declare function
>     ‘<anonymous struct>* ppp_packet::get_queue() const’ with linkage
>     CLANG:
>     extern odp_pool_t tmo_pool;
>     warning: variable 'tmo_pool' has internal linkage but is not defined
>     When linking:
>     undefined reference to `tmo_pool'
>
>     The solution is to add a (unique) name to all structs used by the
>     strong
>     typing typedefs.
>
>     Signed-off-by: Ola Liljedahl <ola.liljedahl@linaro.org
>     <mailto:ola.liljedahl@linaro.org>>
>
>
> Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org 
> <mailto:bill.fischofer@linaro.org>>
>
>     ---
>     (This document/code contribution attached is provided under the
>     terms of
>     agreement LES-LTM-21309)
>
>     v2:
>     Restored doxygen support.
>
>      doc/doxygen.cfg       | 3 ++-
>      platform/linux-generic/include/odp/plat/buffer_types.h        | 4
>     ++--
>      platform/linux-generic/include/odp/plat/classification_types.h |
>     8 ++++----
>      platform/linux-generic/include/odp/plat/crypto_types.h        | 2 +-
>      platform/linux-generic/include/odp/plat/event_types.h         | 2 +-
>      platform/linux-generic/include/odp/plat/packet_io_types.h     | 2 +-
>      platform/linux-generic/include/odp/plat/packet_types.h        | 4
>     ++--
>      platform/linux-generic/include/odp/plat/pool_types.h        | 2 +-
>      platform/linux-generic/include/odp/plat/queue_types.h         | 4
>     ++--
>      platform/linux-generic/include/odp/plat/shared_memory_types.h | 2 +-
>      platform/linux-generic/include/odp/plat/strong_types.h        | 6
>     ++++++
>      11 files changed, 23 insertions(+), 16 deletions(-)
>
>     diff --git a/doc/doxygen.cfg b/doc/doxygen.cfg
>     index 2d45a76..52c83a9 100644
>     --- a/doc/doxygen.cfg
>     +++ b/doc/doxygen.cfg
>     @@ -38,5 +38,6 @@ PREDEFINED = __GNUC__ \
>                  __BIG_ENDIAN_BITFIELD \
>                  __LITTLE_ENDIAN_BITFIELD \
>                  __x86_64__ \
>     -            ODP_PACKED
>     +            ODP_PACKED \
>     +            "ODP_HANDLE_T(type)=odp_handle_t type"
>      INTERNAL_DOCS = YES
>     diff --git
>     a/platform/linux-generic/include/odp/plat/buffer_types.h
>     b/platform/linux-generic/include/odp/plat/buffer_types.h
>     index 3e7070e..0c017ae 100644
>     --- a/platform/linux-generic/include/odp/plat/buffer_types.h
>     +++ b/platform/linux-generic/include/odp/plat/buffer_types.h
>     @@ -26,13 +26,13 @@ extern "C" {
>       */
>
>      /** ODP buffer */
>     -typedef odp_handle_t odp_buffer_t;
>     +typedef ODP_HANDLE_T(odp_buffer_t);
>
>      /** Invalid buffer */
>      #define ODP_BUFFER_INVALID _odp_cast_scalar(odp_buffer_t, 0xffffffff)
>
>      /** ODP buffer segment */
>     -typedef odp_handle_t odp_buffer_seg_t;
>     +typedef ODP_HANDLE_T(odp_buffer_seg_t);
>
>      /** Invalid segment */
>      #define ODP_SEGMENT_INVALID ((odp_buffer_seg_t)ODP_BUFFER_INVALID)
>     diff --git
>     a/platform/linux-generic/include/odp/plat/classification_types.h
>     b/platform/linux-generic/include/odp/plat/classification_types.h
>     index 042d8c8..767da7d 100644
>     --- a/platform/linux-generic/include/odp/plat/classification_types.h
>     +++ b/platform/linux-generic/include/odp/plat/classification_types.h
>     @@ -23,18 +23,18 @@ extern "C" {
>       *  @{
>       */
>
>     -typedef odp_handle_t odp_cos_t;
>     -typedef odp_handle_t odp_flowsig_t;
>     +typedef ODP_HANDLE_T(odp_cos_t);
>     +typedef ODP_HANDLE_T(odp_flowsig_t);
>
>      #define ODP_COS_INVALID  _odp_cast_scalar(odp_cos_t, ~0)
>      #define ODP_COS_NAME_LEN 32
>
>      typedef uint16_t odp_cos_flow_set_t;
>
>     -typedef odp_handle_t odp_pmr_t;
>     +typedef ODP_HANDLE_T(odp_pmr_t);
>      #define ODP_PMR_INVAL _odp_cast_scalar(odp_pmr_t, ~0)
>
>     -typedef odp_handle_t odp_pmr_set_t;
>     +typedef ODP_HANDLE_T(odp_pmr_set_t);
>      #define ODP_PMR_SET_INVAL _odp_cast_scalar(odp_pmr_set_t, ~0)
>
>      /** Get printable format of odp_cos_t */
>     diff --git
>     a/platform/linux-generic/include/odp/plat/crypto_types.h
>     b/platform/linux-generic/include/odp/plat/crypto_types.h
>     index 1b10a5d..a91d88e 100644
>     --- a/platform/linux-generic/include/odp/plat/crypto_types.h
>     +++ b/platform/linux-generic/include/odp/plat/crypto_types.h
>     @@ -25,7 +25,7 @@ extern "C" {
>      #define ODP_CRYPTO_SESSION_INVALID (0xffffffffffffffffULL)
>
>      typedef uint64_t odp_crypto_session_t;
>     -typedef odp_handle_t odp_crypto_compl_t;
>     +typedef ODP_HANDLE_T(odp_crypto_compl_t);
>
>      enum odp_crypto_op_mode {
>             ODP_CRYPTO_SYNC,
>     diff --git a/platform/linux-generic/include/odp/plat/event_types.h
>     b/platform/linux-generic/include/odp/plat/event_types.h
>     index 24be22f..d91937d 100644
>     --- a/platform/linux-generic/include/odp/plat/event_types.h
>     +++ b/platform/linux-generic/include/odp/plat/event_types.h
>     @@ -26,7 +26,7 @@ extern "C" {
>       *  @{
>       */
>
>     -typedef odp_handle_t odp_event_t;
>     +typedef ODP_HANDLE_T(odp_event_t);
>
>      #define ODP_EVENT_INVALID _odp_cast_scalar(odp_event_t, 0xffffffff)
>
>     diff --git
>     a/platform/linux-generic/include/odp/plat/packet_io_types.h
>     b/platform/linux-generic/include/odp/plat/packet_io_types.h
>     index 60592e3..3cc64c6 100644
>     --- a/platform/linux-generic/include/odp/plat/packet_io_types.h
>     +++ b/platform/linux-generic/include/odp/plat/packet_io_types.h
>     @@ -26,7 +26,7 @@ extern "C" {
>       *  @{
>       */
>
>     -typedef odp_handle_t odp_pktio_t;
>     +typedef ODP_HANDLE_T(odp_pktio_t);
>
>      #define ODP_PKTIO_INVALID _odp_cast_scalar(odp_pktio_t, 0)
>
>     diff --git
>     a/platform/linux-generic/include/odp/plat/packet_types.h
>     b/platform/linux-generic/include/odp/plat/packet_types.h
>     index 57e9662..45cb801 100644
>     --- a/platform/linux-generic/include/odp/plat/packet_types.h
>     +++ b/platform/linux-generic/include/odp/plat/packet_types.h
>     @@ -26,13 +26,13 @@ extern "C" {
>       *  @{
>       */
>
>     -typedef odp_handle_t odp_packet_t;
>     +typedef ODP_HANDLE_T(odp_packet_t);
>
>      #define ODP_PACKET_INVALID _odp_cast_scalar(odp_packet_t, 0xffffffff)
>
>      #define ODP_PACKET_OFFSET_INVALID (0x0fffffff)
>
>     -typedef odp_handle_t odp_packet_seg_t;
>     +typedef ODP_HANDLE_T(odp_packet_seg_t);
>
>      #define ODP_PACKET_SEG_INVALID _odp_cast_scalar(odp_packet_seg_t,
>     0xffffffff)
>
>     diff --git a/platform/linux-generic/include/odp/plat/pool_types.h
>     b/platform/linux-generic/include/odp/plat/pool_types.h
>     index 71c7783..568556f 100644
>     --- a/platform/linux-generic/include/odp/plat/pool_types.h
>     +++ b/platform/linux-generic/include/odp/plat/pool_types.h
>     @@ -25,7 +25,7 @@ extern "C" {
>       *  @{
>       */
>
>     -typedef odp_handle_t odp_pool_t;
>     +typedef ODP_HANDLE_T(odp_pool_t);
>
>      #define ODP_POOL_INVALID _odp_cast_scalar(odp_pool_t, 0xffffffff)
>
>     diff --git a/platform/linux-generic/include/odp/plat/queue_types.h
>     b/platform/linux-generic/include/odp/plat/queue_types.h
>     index 04a0be9..1cecc90 100644
>     --- a/platform/linux-generic/include/odp/plat/queue_types.h
>     +++ b/platform/linux-generic/include/odp/plat/queue_types.h
>     @@ -25,9 +25,9 @@ extern "C" {
>       *  @{
>       */
>
>     -typedef odp_handle_t odp_queue_t;
>     +typedef ODP_HANDLE_T(odp_queue_t);
>
>     -typedef odp_handle_t odp_queue_group_t;
>     +typedef ODP_HANDLE_T(odp_queue_group_t);
>
>      #define ODP_QUEUE_INVALID _odp_cast_scalar(odp_queue_t, 0)
>
>     diff --git
>     a/platform/linux-generic/include/odp/plat/shared_memory_types.h
>     b/platform/linux-generic/include/odp/plat/shared_memory_types.h
>     index d2e92cf..4be7356 100644
>     --- a/platform/linux-generic/include/odp/plat/shared_memory_types.h
>     +++ b/platform/linux-generic/include/odp/plat/shared_memory_types.h
>     @@ -26,7 +26,7 @@ extern "C" {
>       *  @{
>       */
>
>     -typedef odp_handle_t odp_shm_t;
>     +typedef ODP_HANDLE_T(odp_shm_t);
>
>      #define ODP_SHM_INVALID _odp_cast_scalar(odp_shm_t, 0)
>      #define ODP_SHM_NULL ODP_SHM_INVALID
>     diff --git
>     a/platform/linux-generic/include/odp/plat/strong_types.h
>     b/platform/linux-generic/include/odp/plat/strong_types.h
>     index cd15853..a53d763 100644
>     --- a/platform/linux-generic/include/odp/plat/strong_types.h
>     +++ b/platform/linux-generic/include/odp/plat/strong_types.h
>     @@ -16,7 +16,13 @@
>      #define STRONG_TYPES_H_
>
>      /** Use strong typing for ODP types */
>     +#ifdef __cplusplus
>     +#define ODP_HANDLE_T(type) struct _##type { uint8_t
>     unused_dummy_var; } *type
>     +#else
>      #define odp_handle_t struct { uint8_t unused_dummy_var; } *
>     +/** C/C++ helper macro for strong typing */
>     +#define ODP_HANDLE_T(type) odp_handle_t type
>     +#endif
>
>      /** Internal macro to get value of an ODP handle */
>      #define _odp_typeval(handle) ((uint32_t)(uintptr_t)(handle))
>     --
>     1.9.1
>
>
>     _______________________________________________
>     lng-odp mailing list
>     lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>
>     http://lists.linaro.org/mailman/listinfo/lng-odp
>
>
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/doc/doxygen.cfg b/doc/doxygen.cfg
index 2d45a76..52c83a9 100644
--- a/doc/doxygen.cfg
+++ b/doc/doxygen.cfg
@@ -38,5 +38,6 @@  PREDEFINED = __GNUC__ \
 	     __BIG_ENDIAN_BITFIELD \
 	     __LITTLE_ENDIAN_BITFIELD \
 	     __x86_64__ \
-	     ODP_PACKED
+	     ODP_PACKED \
+	     "ODP_HANDLE_T(type)=odp_handle_t type"
 INTERNAL_DOCS = YES
diff --git a/platform/linux-generic/include/odp/plat/buffer_types.h b/platform/linux-generic/include/odp/plat/buffer_types.h
index 3e7070e..0c017ae 100644
--- a/platform/linux-generic/include/odp/plat/buffer_types.h
+++ b/platform/linux-generic/include/odp/plat/buffer_types.h
@@ -26,13 +26,13 @@  extern "C" {
  */
 
 /** ODP buffer */
-typedef odp_handle_t odp_buffer_t;
+typedef ODP_HANDLE_T(odp_buffer_t);
 
 /** Invalid buffer */
 #define ODP_BUFFER_INVALID _odp_cast_scalar(odp_buffer_t, 0xffffffff)
 
 /** ODP buffer segment */
-typedef odp_handle_t odp_buffer_seg_t;
+typedef ODP_HANDLE_T(odp_buffer_seg_t);
 
 /** Invalid segment */
 #define ODP_SEGMENT_INVALID ((odp_buffer_seg_t)ODP_BUFFER_INVALID)
diff --git a/platform/linux-generic/include/odp/plat/classification_types.h b/platform/linux-generic/include/odp/plat/classification_types.h
index 042d8c8..767da7d 100644
--- a/platform/linux-generic/include/odp/plat/classification_types.h
+++ b/platform/linux-generic/include/odp/plat/classification_types.h
@@ -23,18 +23,18 @@  extern "C" {
  *  @{
  */
 
-typedef odp_handle_t odp_cos_t;
-typedef odp_handle_t odp_flowsig_t;
+typedef ODP_HANDLE_T(odp_cos_t);
+typedef ODP_HANDLE_T(odp_flowsig_t);
 
 #define ODP_COS_INVALID  _odp_cast_scalar(odp_cos_t, ~0)
 #define ODP_COS_NAME_LEN 32
 
 typedef uint16_t odp_cos_flow_set_t;
 
-typedef odp_handle_t odp_pmr_t;
+typedef ODP_HANDLE_T(odp_pmr_t);
 #define ODP_PMR_INVAL _odp_cast_scalar(odp_pmr_t, ~0)
 
-typedef odp_handle_t odp_pmr_set_t;
+typedef ODP_HANDLE_T(odp_pmr_set_t);
 #define ODP_PMR_SET_INVAL _odp_cast_scalar(odp_pmr_set_t, ~0)
 
 /** Get printable format of odp_cos_t */
diff --git a/platform/linux-generic/include/odp/plat/crypto_types.h b/platform/linux-generic/include/odp/plat/crypto_types.h
index 1b10a5d..a91d88e 100644
--- a/platform/linux-generic/include/odp/plat/crypto_types.h
+++ b/platform/linux-generic/include/odp/plat/crypto_types.h
@@ -25,7 +25,7 @@  extern "C" {
 #define ODP_CRYPTO_SESSION_INVALID (0xffffffffffffffffULL)
 
 typedef uint64_t odp_crypto_session_t;
-typedef odp_handle_t odp_crypto_compl_t;
+typedef ODP_HANDLE_T(odp_crypto_compl_t);
 
 enum odp_crypto_op_mode {
 	ODP_CRYPTO_SYNC,
diff --git a/platform/linux-generic/include/odp/plat/event_types.h b/platform/linux-generic/include/odp/plat/event_types.h
index 24be22f..d91937d 100644
--- a/platform/linux-generic/include/odp/plat/event_types.h
+++ b/platform/linux-generic/include/odp/plat/event_types.h
@@ -26,7 +26,7 @@  extern "C" {
  *  @{
  */
 
-typedef odp_handle_t odp_event_t;
+typedef ODP_HANDLE_T(odp_event_t);
 
 #define ODP_EVENT_INVALID _odp_cast_scalar(odp_event_t, 0xffffffff)
 
diff --git a/platform/linux-generic/include/odp/plat/packet_io_types.h b/platform/linux-generic/include/odp/plat/packet_io_types.h
index 60592e3..3cc64c6 100644
--- a/platform/linux-generic/include/odp/plat/packet_io_types.h
+++ b/platform/linux-generic/include/odp/plat/packet_io_types.h
@@ -26,7 +26,7 @@  extern "C" {
  *  @{
  */
 
-typedef odp_handle_t odp_pktio_t;
+typedef ODP_HANDLE_T(odp_pktio_t);
 
 #define ODP_PKTIO_INVALID _odp_cast_scalar(odp_pktio_t, 0)
 
diff --git a/platform/linux-generic/include/odp/plat/packet_types.h b/platform/linux-generic/include/odp/plat/packet_types.h
index 57e9662..45cb801 100644
--- a/platform/linux-generic/include/odp/plat/packet_types.h
+++ b/platform/linux-generic/include/odp/plat/packet_types.h
@@ -26,13 +26,13 @@  extern "C" {
  *  @{
  */
 
-typedef odp_handle_t odp_packet_t;
+typedef ODP_HANDLE_T(odp_packet_t);
 
 #define ODP_PACKET_INVALID _odp_cast_scalar(odp_packet_t, 0xffffffff)
 
 #define ODP_PACKET_OFFSET_INVALID (0x0fffffff)
 
-typedef odp_handle_t odp_packet_seg_t;
+typedef ODP_HANDLE_T(odp_packet_seg_t);
 
 #define ODP_PACKET_SEG_INVALID _odp_cast_scalar(odp_packet_seg_t, 0xffffffff)
 
diff --git a/platform/linux-generic/include/odp/plat/pool_types.h b/platform/linux-generic/include/odp/plat/pool_types.h
index 71c7783..568556f 100644
--- a/platform/linux-generic/include/odp/plat/pool_types.h
+++ b/platform/linux-generic/include/odp/plat/pool_types.h
@@ -25,7 +25,7 @@  extern "C" {
  *  @{
  */
 
-typedef odp_handle_t odp_pool_t;
+typedef ODP_HANDLE_T(odp_pool_t);
 
 #define ODP_POOL_INVALID _odp_cast_scalar(odp_pool_t, 0xffffffff)
 
diff --git a/platform/linux-generic/include/odp/plat/queue_types.h b/platform/linux-generic/include/odp/plat/queue_types.h
index 04a0be9..1cecc90 100644
--- a/platform/linux-generic/include/odp/plat/queue_types.h
+++ b/platform/linux-generic/include/odp/plat/queue_types.h
@@ -25,9 +25,9 @@  extern "C" {
  *  @{
  */
 
-typedef odp_handle_t odp_queue_t;
+typedef ODP_HANDLE_T(odp_queue_t);
 
-typedef odp_handle_t odp_queue_group_t;
+typedef ODP_HANDLE_T(odp_queue_group_t);
 
 #define ODP_QUEUE_INVALID  _odp_cast_scalar(odp_queue_t, 0)
 
diff --git a/platform/linux-generic/include/odp/plat/shared_memory_types.h b/platform/linux-generic/include/odp/plat/shared_memory_types.h
index d2e92cf..4be7356 100644
--- a/platform/linux-generic/include/odp/plat/shared_memory_types.h
+++ b/platform/linux-generic/include/odp/plat/shared_memory_types.h
@@ -26,7 +26,7 @@  extern "C" {
  *  @{
  */
 
-typedef odp_handle_t odp_shm_t;
+typedef ODP_HANDLE_T(odp_shm_t);
 
 #define ODP_SHM_INVALID _odp_cast_scalar(odp_shm_t, 0)
 #define ODP_SHM_NULL ODP_SHM_INVALID
diff --git a/platform/linux-generic/include/odp/plat/strong_types.h b/platform/linux-generic/include/odp/plat/strong_types.h
index cd15853..a53d763 100644
--- a/platform/linux-generic/include/odp/plat/strong_types.h
+++ b/platform/linux-generic/include/odp/plat/strong_types.h
@@ -16,7 +16,13 @@ 
 #define STRONG_TYPES_H_
 
 /** Use strong typing for ODP types */
+#ifdef __cplusplus
+#define ODP_HANDLE_T(type) struct _##type { uint8_t unused_dummy_var; } *type
+#else
 #define odp_handle_t struct { uint8_t unused_dummy_var; } *
+/** C/C++ helper macro for strong typing */
+#define ODP_HANDLE_T(type) odp_handle_t type
+#endif
 
 /** Internal macro to get value of an ODP handle */
 #define _odp_typeval(handle) ((uint32_t)(uintptr_t)(handle))