[ovs-dev] util: Update OVS_TYPEOF macro for Windows.
diff mbox series

Message ID 1584637395-25000-1-git-send-email-harchana@vmware.com
State New
Headers show
Series
  • [ovs-dev] util: Update OVS_TYPEOF macro for Windows.
Related show

Commit Message

姜立东 via dev March 19, 2020, 5:03 p.m. UTC
OVS_TYPEOF macro doesn’t return the type of object for non __GNUC__ platforms.
Updating it for _WIN32 platforms when used from C++ code.

Signed-off-by: Archana Holla <harchana@vmware.com>
---
 include/openvswitch/util.h | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Ben Pfaff March 19, 2020, 5:35 p.m. UTC | #1
On Thu, Mar 19, 2020 at 10:03:15AM -0700, Archana Holla via dev wrote:
> OVS_TYPEOF macro doesn’t return the type of object for non __GNUC__ platforms.
> Updating it for _WIN32 platforms when used from C++ code.
> 
> Signed-off-by: Archana Holla <harchana@vmware.com>
> ---
>  include/openvswitch/util.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
> index 9189e64..af7d1b0 100644
> --- a/include/openvswitch/util.h
> +++ b/include/openvswitch/util.h
> @@ -86,8 +86,12 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
>  #ifdef __GNUC__
>  #define OVS_TYPEOF(OBJECT) typeof(OBJECT)
>  #else
> +#if defined (__cplusplus) && defined(_WIN32)
> +#define OVS_TYPEOF(OBJECT) decltype(OBJECT)
> +#else
>  #define OVS_TYPEOF(OBJECT) void *
>  #endif
> +#endif

Thanks for submitting a patch.

Does this solve a problem?

decltype is a C++ feature.  How is it specific to Windows?

Please use #elif instead of introducing a nested #if...#endif.

Thanks,

Ben.
姜立东 via dev April 7, 2020, 6:10 p.m. UTC | #2
Thanks Ben for the review comments.
Please find my answers for the questions and could you please take a look at v2 of patch with review commented addressed.

>>Does this solve a problem?
 Yes,
  #define OBJECT_CONTAINING(POINTER, OBJECT, MEMBER) \
     ((OVS_TYPEOF(OBJECT)) (void *) \
     ((char *) (POINTER) - OBJECT_OFFSETOF(OBJECT, MEMBER)))
    
  On using ovs macro OBJECT_CONTAINING(which references OVS_TYPEOF), following compilation error is observed on windows C++ application:
  "
  error C2440: '=': cannot convert from 'void *' to 'object *'
  note: Conversion from 'void*' to pointer to non-'void' requires an explicit cast
   "
  With "decltype" keyword, this issue isn't seen as object is type casted to the right type.

>>decltype is a C++ feature.  How is it specific to Windows?
  Agree with the review comment, as decltype is a C++ construct we can use it for all C++ enabled application, addressed in patch V2.
                    
>>Please use #elif instead of introducing a nested #if...#endif.
  Yes, taken care in patch V2.

Thanks,
Archana


    On 3/19/20, 10:35 AM, "dev on behalf of Ben Pfaff" <ovs-dev-bounces@openvswitch.org on behalf of blp@ovn.org> wrote:
    
        On Thu, Mar 19, 2020 at 10:03:15AM -0700, Archana Holla via dev wrote:
        > OVS_TYPEOF macro doesn’t return the type of object for non __GNUC__ platforms.
        > Updating it for _WIN32 platforms when used from C++ code.
        > 
        > Signed-off-by: Archana Holla <harchana@vmware.com>
        > ---
        >  include/openvswitch/util.h | 4 ++++
        >  1 file changed, 4 insertions(+)
        > 
        > diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
        > index 9189e64..af7d1b0 100644
        > --- a/include/openvswitch/util.h
        > +++ b/include/openvswitch/util.h
        > @@ -86,8 +86,12 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
        >  #ifdef __GNUC__
        >  #define OVS_TYPEOF(OBJECT) typeof(OBJECT)
        >  #else
        > +#if defined (__cplusplus) && defined(_WIN32)
        > +#define OVS_TYPEOF(OBJECT) decltype(OBJECT)
        > +#else
        >  #define OVS_TYPEOF(OBJECT) void *
        >  #endif
        > +#endif
        
        Thanks for submitting a patch.
        
        Does this solve a problem?
        
        decltype is a C++ feature.  How is it specific to Windows?
        
        Please use #elif instead of introducing a nested #if...#endif.
        
        Thanks,
        
        Ben.
        _______________________________________________
        dev mailing list
        dev@openvswitch.org
        https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.openvswitch.org%2Fmailman%2Flistinfo%2Fovs-dev&amp;data=02%7C01%7Ckumaranand%40vmware.com%7C0a5436579e8649e0f82808d7cc2be960%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C637202361299974072&amp;sdata=9MXAsT5tmBCUNKNrccv0knGJe5MLeXy8RGWvpIncd9g%3D&amp;reserved=0
姜立东 via dev April 7, 2020, 6:17 p.m. UTC | #3
Thanks Ben for the review comments.
Please find my answers for the questions and could you please take a look at v2 of patch with review commented addressed.
    
    >>Does this solve a problem?
     Yes,
      #define OBJECT_CONTAINING(POINTER, OBJECT, MEMBER) \
         ((OVS_TYPEOF(OBJECT)) (void *) \
         ((char *) (POINTER) - OBJECT_OFFSETOF(OBJECT, MEMBER)))
        
      On using ovs macro OBJECT_CONTAINING(which references OVS_TYPEOF), following compilation error is observed on windows C++ application:
      "
      error C2440: '=': cannot convert from 'void *' to 'object *'
      note: Conversion from 'void*' to pointer to non-'void' requires an explicit cast
       "
      With "decltype" keyword, this issue isn't seen as object is type casted to the right type.
    
    >>decltype is a C++ feature.  How is it specific to Windows?
      Agree with the review comment, as decltype is a C++ construct we can use it for all C++ enabled application, addressed in patch V2.
                        
    >>Please use #elif instead of introducing a nested #if...#endif.
      Yes, taken care in patch V2.
    
Thanks,
Archana
    
    
        On 3/19/20, 10:35 AM, "dev on behalf of Ben Pfaff" <ovs-dev-bounces@openvswitch.org on behalf of blp@ovn.org> wrote:
        
            On Thu, Mar 19, 2020 at 10:03:15AM -0700, Archana Holla via dev wrote:
            > OVS_TYPEOF macro doesn’t return the type of object for non __GNUC__ platforms.
            > Updating it for _WIN32 platforms when used from C++ code.
            > 
            > Signed-off-by: Archana Holla <harchana@vmware.com>
            > ---
            >  include/openvswitch/util.h | 4 ++++
            >  1 file changed, 4 insertions(+)
            > 
            > diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
            > index 9189e64..af7d1b0 100644
            > --- a/include/openvswitch/util.h
            > +++ b/include/openvswitch/util.h
            > @@ -86,8 +86,12 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
            >  #ifdef __GNUC__
            >  #define OVS_TYPEOF(OBJECT) typeof(OBJECT)
            >  #else
            > +#if defined (__cplusplus) && defined(_WIN32)
            > +#define OVS_TYPEOF(OBJECT) decltype(OBJECT)
            > +#else
            >  #define OVS_TYPEOF(OBJECT) void *
            >  #endif
            > +#endif
            
            Thanks for submitting a patch.
            
            Does this solve a problem?
            
            decltype is a C++ feature.  How is it specific to Windows?
            
            Please use #elif instead of introducing a nested #if...#endif.
            
            Thanks,
            
            Ben.
            _______________________________________________
            dev mailing list
            dev@openvswitch.org
            https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.openvswitch.org%2Fmailman%2Flistinfo%2Fovs-dev&amp;data=02%7C01%7Ckumaranand%40vmware.com%7C0a5436579e8649e0f82808d7cc2be960%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C637202361299974072&amp;sdata=9MXAsT5tmBCUNKNrccv0knGJe5MLeXy8RGWvpIncd9g%3D&amp;reserved=0
姜立东 via dev April 7, 2020, 6:24 p.m. UTC | #4
Thanks Ben for the review comments.
Please find my answers for the questions and could you please take a look at v2 of patch with review commented addressed.
        
        >>Does this solve a problem?
         Yes,
          #define OBJECT_CONTAINING(POINTER, OBJECT, MEMBER) \
             ((OVS_TYPEOF(OBJECT)) (void *) \
             ((char *) (POINTER) - OBJECT_OFFSETOF(OBJECT, MEMBER)))
            
          On using ovs macro OBJECT_CONTAINING(which references OVS_TYPEOF), following compilation error is observed on windows C++ application:
          "
          error C2440: '=': cannot convert from 'void *' to 'object *'
          note: Conversion from 'void*' to pointer to non-'void' requires an explicit cast
           "
          With "decltype" keyword, this issue isn't seen as object is type casted to the right type.
        
        >>decltype is a C++ feature.  How is it specific to Windows?
          Agree with the review comment, as decltype is a C++ construct we can use it for all C++ enabled application, addressed in patch V2.
                            
        >>Please use #elif instead of introducing a nested #if...#endif.
          Yes, taken care in patch V2.
        
Thanks,
Archana
        
        
            On 3/19/20, 10:35 AM, "dev on behalf of Ben Pfaff" <ovs-dev-bounces@openvswitch.org on behalf of blp@ovn.org> wrote:
            
                On Thu, Mar 19, 2020 at 10:03:15AM -0700, Archana Holla via dev wrote:
                > OVS_TYPEOF macro doesn’t return the type of object for non __GNUC__ platforms.
                > Updating it for _WIN32 platforms when used from C++ code.
                > 
                > Signed-off-by: Archana Holla <harchana@vmware.com>
                > ---
                >  include/openvswitch/util.h | 4 ++++
                >  1 file changed, 4 insertions(+)
                > 
                > diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
                > index 9189e64..af7d1b0 100644
                > --- a/include/openvswitch/util.h
                > +++ b/include/openvswitch/util.h
                > @@ -86,8 +86,12 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
                >  #ifdef __GNUC__
                >  #define OVS_TYPEOF(OBJECT) typeof(OBJECT)
                >  #else
                > +#if defined (__cplusplus) && defined(_WIN32)
                > +#define OVS_TYPEOF(OBJECT) decltype(OBJECT)
                > +#else
                >  #define OVS_TYPEOF(OBJECT) void *
                >  #endif
                > +#endif
                
                Thanks for submitting a patch.
                
                Does this solve a problem?
                
                decltype is a C++ feature.  How is it specific to Windows?
                
                Please use #elif instead of introducing a nested #if...#endif.
                
                Thanks,
                
                Ben.
                _______________________________________________
                dev mailing list
                dev@openvswitch.org
                https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.openvswitch.org%2Fmailman%2Flistinfo%2Fovs-dev&amp;data=02%7C01%7Ckumaranand%40vmware.com%7C0a5436579e8649e0f82808d7cc2be960%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C637202361299974072&amp;sdata=9MXAsT5tmBCUNKNrccv0knGJe5MLeXy8RGWvpIncd9g%3D&amp;reserved=0
姜立东 via dev April 7, 2020, 6:28 p.m. UTC | #5
Thanks Ben for the review comments.
Please find my answers for the questions and could you please take a look at v2 of patch with review commented addressed.

>>Does this solve a problem?
Yes,
  #define OBJECT_CONTAINING(POINTER, OBJECT, MEMBER) \
     ((OVS_TYPEOF(OBJECT)) (void *) \
     ((char *) (POINTER) - OBJECT_OFFSETOF(OBJECT, MEMBER)))
    
  On using ovs macro OBJECT_CONTAINING(which references OVS_TYPEOF), following compilation error is observed on windows C++ application:
  "
  error C2440: '=': cannot convert from 'void *' to 'object *'
  note: Conversion from 'void*' to pointer to non-'void' requires an explicit cast
   "
  With "decltype" keyword, this issue isn't seen as object is type casted to the right type.

>>decltype is a C++ feature.  How is it specific to Windows?
  Agree with the review comment, as decltype is a C++ construct we can use it for all C++ enabled application, addressed in patch V2.
                    
>>Please use #elif instead of introducing a nested #if...#endif.
  Yes, taken care in patch V2.

Thanks,
Archana

On 3/19/20, 10:35 AM, "dev on behalf of Ben Pfaff" <ovs-dev-bounces@openvswitch.org on behalf of blp@ovn.org> wrote:

    On Thu, Mar 19, 2020 at 10:03:15AM -0700, Archana Holla via dev wrote:
    > OVS_TYPEOF macro doesn’t return the type of object for non __GNUC__ platforms.
    > Updating it for _WIN32 platforms when used from C++ code.
    > 
    > Signed-off-by: Archana Holla <harchana@vmware.com>
    > ---
    >  include/openvswitch/util.h | 4 ++++
    >  1 file changed, 4 insertions(+)
    > 
    > diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
    > index 9189e64..af7d1b0 100644
    > --- a/include/openvswitch/util.h
    > +++ b/include/openvswitch/util.h
    > @@ -86,8 +86,12 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
    >  #ifdef __GNUC__
    >  #define OVS_TYPEOF(OBJECT) typeof(OBJECT)
    >  #else
    > +#if defined (__cplusplus) && defined(_WIN32)
    > +#define OVS_TYPEOF(OBJECT) decltype(OBJECT)
    > +#else
    >  #define OVS_TYPEOF(OBJECT) void *
    >  #endif
    > +#endif
    
    Thanks for submitting a patch.
    
    Does this solve a problem?
    
    decltype is a C++ feature.  How is it specific to Windows?
    
    Please use #elif instead of introducing a nested #if...#endif.
    
    Thanks,
    
    Ben.
    _______________________________________________
    dev mailing list
    dev@openvswitch.org
    https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.openvswitch.org%2Fmailman%2Flistinfo%2Fovs-dev&amp;data=02%7C01%7Ckumaranand%40vmware.com%7C0a5436579e8649e0f82808d7cc2be960%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C637202361299974072&amp;sdata=9MXAsT5tmBCUNKNrccv0knGJe5MLeXy8RGWvpIncd9g%3D&amp;reserved=0

Patch
diff mbox series

diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
index 9189e64..af7d1b0 100644
--- a/include/openvswitch/util.h
+++ b/include/openvswitch/util.h
@@ -86,8 +86,12 @@  OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
 #ifdef __GNUC__
 #define OVS_TYPEOF(OBJECT) typeof(OBJECT)
 #else
+#if defined (__cplusplus) && defined(_WIN32)
+#define OVS_TYPEOF(OBJECT) decltype(OBJECT)
+#else
 #define OVS_TYPEOF(OBJECT) void *
 #endif
+#endif
 
 /* Given OBJECT of type pointer-to-structure, expands to the offset of MEMBER
  * within an instance of the structure.