public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] typeof() not supported in Windows WDK compiler
@ 2009-10-01 22:41 Stan C. Smith
  2009-10-01 22:59 ` Sean Hefty
  0 siblings, 1 reply; 8+ messages in thread
From: Stan C. Smith @ 2009-10-01 22:41 UTC (permalink / raw)
  To: 'Sasha Khapyorsky'; +Cc: ofw, 'linux-rdma'


Added Obj TypeOf argument to the Windows version of cl_item_obj() macro to compensate for missing typeof() operator.

Signed-off-by: stan smith <stan.smith@intel.com>

diff --git a/opensm/opensm/osm_drop_mgr.c b/opensm/opensm/osm_drop_mgr.c
index 4f98cc9..8fe5129 100644
--- a/opensm/opensm/osm_drop_mgr.c
+++ b/opensm/opensm/osm_drop_mgr.c
@@ -209,8 +209,13 @@ static void drop_mgr_remove_port(osm_sm_t * sm, IN osm_port_t * p_port)
 	drop_mgr_clean_physp(sm, p_port->p_physp);
 
 	while (!cl_is_qlist_empty(&p_port->mcm_list)) {
+#ifndef __WIN__
 		mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
 				       mcm_port, list_item);
+#else
+		mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
+				       mcm_port, list_item, (osm_mcm_port_t*) );
+#endif
 		osm_mgrp_delete_port(sm->p_subn, sm->p_log, mcm_port->mgrp,
 				     p_port->guid);
 	}
diff --git a/opensm/opensm/osm_state_mgr.c b/opensm/opensm/osm_state_mgr.c
index 185c700..a260b8a 100644
--- a/opensm/opensm/osm_state_mgr.c
+++ b/opensm/opensm/osm_state_mgr.c
@@ -503,7 +503,11 @@ Exit:
 static void query_sm_info(cl_map_item_t * item, void *cxt)
 {
 	osm_madw_context_t context;
+#ifndef __WIN__
 	osm_remote_sm_t *r_sm = cl_item_obj(item, r_sm, map_item);
+#else
+	osm_remote_sm_t *r_sm = cl_item_obj(item, r_sm, map_item,(osm_remote_sm_t *));
+#endif
 	osm_sm_t *sm = cxt;
 	ib_api_status_t ret;
 
diff --git a/opensm/opensm/osm_ucast_mgr.c b/opensm/opensm/osm_ucast_mgr.c
index 39d825c..a1f5c72 100644
--- a/opensm/opensm/osm_ucast_mgr.c
+++ b/opensm/opensm/osm_ucast_mgr.c
@@ -388,7 +388,11 @@ static void ucast_mgr_process_tbl(IN cl_map_item_t * p_map_item,
 		cl_list_item_t *item;
 		for (item = cl_qlist_head(list); item != cl_qlist_end(list);
 		     item = cl_qlist_next(item)) {
+#ifndef __WIN__
 			osm_port_t *port = cl_item_obj(item, port, list_item);
+#else
+			osm_port_t *port = cl_item_obj(item, port, list_item,(osm_port_t*));
+#endif
 			ucast_mgr_process_port(p_mgr, p_sw, port, i);
 		}
 	}

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

* RE: [PATCH] typeof() not supported in Windows WDK compiler
  2009-10-01 22:41 [PATCH] typeof() not supported in Windows WDK compiler Stan C. Smith
@ 2009-10-01 22:59 ` Sean Hefty
  2009-10-01 23:14   ` Smith, Stan
       [not found]   ` <2A3759D0AB7F46D59DF8820EFCFAF1F8-Zpru7NauK7drdx17CPfAsdBPR1lH4CV8@public.gmane.org>
  0 siblings, 2 replies; 8+ messages in thread
From: Sean Hefty @ 2009-10-01 22:59 UTC (permalink / raw)
  To: Smith, Stan, 'Sasha Khapyorsky'; +Cc: ofw, 'linux-rdma'

>diff --git a/opensm/opensm/osm_drop_mgr.c b/opensm/opensm/osm_drop_mgr.c
>index 4f98cc9..8fe5129 100644
>--- a/opensm/opensm/osm_drop_mgr.c
>+++ b/opensm/opensm/osm_drop_mgr.c
>@@ -209,8 +209,13 @@ static void drop_mgr_remove_port(osm_sm_t * sm, IN
>osm_port_t * p_port)
> 	drop_mgr_clean_physp(sm, p_port->p_physp);
>
> 	while (!cl_is_qlist_empty(&p_port->mcm_list)) {
>+#ifndef __WIN__
> 		mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
> 				       mcm_port, list_item);
>+#else
>+		mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
>+				       mcm_port, list_item, (osm_mcm_port_t*) );
>+#endif

I'd find this more readable if it were #ifdef rather than #ifndef.

That said, I've got to believe that there's a better way to handle these
changes.  I just don't know what it is.

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

* RE: [PATCH] typeof() not supported in Windows WDK compiler
  2009-10-01 22:59 ` Sean Hefty
@ 2009-10-01 23:14   ` Smith, Stan
  2009-10-01 23:38     ` Sean Hefty
       [not found]   ` <2A3759D0AB7F46D59DF8820EFCFAF1F8-Zpru7NauK7drdx17CPfAsdBPR1lH4CV8@public.gmane.org>
  1 sibling, 1 reply; 8+ messages in thread
From: Smith, Stan @ 2009-10-01 23:14 UTC (permalink / raw)
  To: Hefty, Sean, 'Sasha Khapyorsky'
  Cc: ofw@lists.openfabrics.org, 'linux-rdma'

Hefty, Sean wrote:
>> diff --git a/opensm/opensm/osm_drop_mgr.c
>> b/opensm/opensm/osm_drop_mgr.c index 4f98cc9..8fe5129 100644 ---
>> a/opensm/opensm/osm_drop_mgr.c +++ b/opensm/opensm/osm_drop_mgr.c
>> @@ -209,8 +209,13 @@ static void drop_mgr_remove_port(osm_sm_t * sm,
>>      IN osm_port_t * p_port) drop_mgr_clean_physp(sm, p_port->p_physp);
>>
>>      while (!cl_is_qlist_empty(&p_port->mcm_list)) {
>> +#ifndef __WIN__
>>              mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
>>                                     mcm_port, list_item);
>> +#else
>> +            mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
>> +                                   mcm_port, list_item, (osm_mcm_port_t*) );
>> +#endif
>
> I'd find this more readable if it were #ifdef rather than #ifndef.

So would I, although the convention is to only define something extra for Windows.
Perhaps a gcc/cpp defined item could be recommended and agreed upon?

>
> That said, I've got to believe that there's a better way to handle
> these changes.  I just don't know what it is.

Agreed, I'm listening.

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

* RE: [PATCH] typeof() not supported in Windows WDK compiler
  2009-10-01 23:14   ` Smith, Stan
@ 2009-10-01 23:38     ` Sean Hefty
  0 siblings, 0 replies; 8+ messages in thread
From: Sean Hefty @ 2009-10-01 23:38 UTC (permalink / raw)
  To: Smith, Stan, 'Sasha Khapyorsky'; +Cc: ofw, 'linux-rdma'

>>> 	while (!cl_is_qlist_empty(&p_port->mcm_list)) {
>>> +#ifndef __WIN__
>>> 		mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
>>> 				       mcm_port, list_item);
>>> +#else
>>> +		mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
>>> +				       mcm_port, list_item, (osm_mcm_port_t*) );
>>> +#endif
>>
>> I'd find this more readable if it were #ifdef rather than #ifndef.
>
>So would I, although the convention is to only define something extra for
>Windows.
>Perhaps a gcc/cpp defined item could be recommended and agreed upon?
>
>>
>> That said, I've got to believe that there's a better way to handle
>> these changes.  I just don't know what it is.
>
>Agreed, I'm listening.

How about replacing cl_item_obj with something more common, like container_of()?

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

* Re: [ofw] [PATCH] typeof() not supported in Windows WDK compiler
       [not found]   ` <2A3759D0AB7F46D59DF8820EFCFAF1F8-Zpru7NauK7drdx17CPfAsdBPR1lH4CV8@public.gmane.org>
@ 2009-10-01 23:47     ` Jason Gunthorpe
       [not found]       ` <20091001234701.GD5191-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Jason Gunthorpe @ 2009-10-01 23:47 UTC (permalink / raw)
  To: Sean Hefty
  Cc: Smith, Stan, 'Sasha Khapyorsky',
	ofw-ZwoEplunGu1OwGhvXhtEPSCwEArCW2h5, 'linux-rdma'

On Thu, Oct 01, 2009 at 03:59:00PM -0700, Sean Hefty wrote:
> >diff --git a/opensm/opensm/osm_drop_mgr.c b/opensm/opensm/osm_drop_mgr.c
> >index 4f98cc9..8fe5129 100644
> >+++ b/opensm/opensm/osm_drop_mgr.c
> >@@ -209,8 +209,13 @@ static void drop_mgr_remove_port(osm_sm_t * sm, IN
> >osm_port_t * p_port)
> > 	drop_mgr_clean_physp(sm, p_port->p_physp);
> >
> > 	while (!cl_is_qlist_empty(&p_port->mcm_list)) {
> >+#ifndef __WIN__
> > 		mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
> > 				       mcm_port, list_item);
> >+#else
> >+		mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
> >+				       mcm_port, list_item, (osm_mcm_port_t*) );
> >+#endif
> 
> I'd find this more readable if it were #ifdef rather than #ifndef.
> 
> That said, I've got to believe that there's a better way to handle these
> changes.  I just don't know what it is.

Hmm

How about

#ifdef __GCC_
#define cl_item_obj(item_ptr, obj_ptr, item_field) (typeof(obj_ptr)) \
        ((void *)item_ptr - (unsigned long)&((typeof(obj_ptr))0)->item_field)
#else
#define cl_item_obj(item_ptr, obj_ptr, item_field) (typeof(obj_ptr)) \
  (void *)((uint8_t*)item_ptr - ((uintptr_t)(&(obj_ptr)->item_field) -
  ((uintptr_t)&(obj_ptr))))
#endif

And rely on the C implicit cast from void* to an object type, and rely
on compiles with gcc to do the extra type checking.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* RE: [ofw] [PATCH] typeof() not supported in Windows WDK compiler
       [not found]       ` <20091001234701.GD5191-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
@ 2009-10-02  0:29         ` Smith, Stan
       [not found]           ` <3F6F638B8D880340AB536D29CD4C1E1912C86E8C4A-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
  2009-10-02 16:02         ` Smith, Stan
  1 sibling, 1 reply; 8+ messages in thread
From: Smith, Stan @ 2009-10-02  0:29 UTC (permalink / raw)
  To: Jason Gunthorpe, Hefty, Sean
  Cc: 'Sasha Khapyorsky',
	ofw-ZwoEplunGu1OwGhvXhtEPSCwEArCW2h5@public.gmane.org,
	'linux-rdma'

Jason Gunthorpe wrote:
> On Thu, Oct 01, 2009 at 03:59:00PM -0700, Sean Hefty wrote:
>>> diff --git a/opensm/opensm/osm_drop_mgr.c
>>> b/opensm/opensm/osm_drop_mgr.c index 4f98cc9..8fe5129 100644 +++
>>> b/opensm/opensm/osm_drop_mgr.c @@ -209,8 +209,13 @@ static void
>>>     drop_mgr_remove_port(osm_sm_t * sm, IN osm_port_t * p_port)
>>> drop_mgr_clean_physp(sm, p_port->p_physp);
>>>
>>>     while (!cl_is_qlist_empty(&p_port->mcm_list)) {
>>> +#ifndef __WIN__
>>>             mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
>>>                                    mcm_port, list_item);
>>> +#else
>>> +           mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
>>> +                                  mcm_port, list_item, (osm_mcm_port_t*) );
>>> +#endif
>>
>> I'd find this more readable if it were #ifdef rather than #ifndef.
>>
>> That said, I've got to believe that there's a better way to handle
>> these changes.  I just don't know what it is.
>
> Hmm
>
> How about

Do the Sun guys use gcc?

>
> #ifdef __GCC_
> #define cl_item_obj(item_ptr, obj_ptr, item_field) (typeof(obj_ptr)) \
>         ((void *)item_ptr - (unsigned
> long)&((typeof(obj_ptr))0)->item_field) #else
> #define cl_item_obj(item_ptr, obj_ptr, item_field) (typeof(obj_ptr)) \
>   (void *)((uint8_t*)item_ptr - ((uintptr_t)(&(obj_ptr)->item_field) -
>   ((uintptr_t)&(obj_ptr))))
> #endif

Interesting, worth a try.

>
> And rely on the C implicit cast from void* to an object type, and rely
> on compiles with gcc to do the extra type checking.

'compiles with gcc' ?

>
> Jason

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [ofw] [PATCH] typeof() not supported in Windows WDK compiler
       [not found]           ` <3F6F638B8D880340AB536D29CD4C1E1912C86E8C4A-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
@ 2009-10-02  2:04             ` Jason Gunthorpe
  0 siblings, 0 replies; 8+ messages in thread
From: Jason Gunthorpe @ 2009-10-02  2:04 UTC (permalink / raw)
  To: Smith, Stan
  Cc: Hefty, Sean, 'Sasha Khapyorsky',
	ofw-ZwoEplunGu1OwGhvXhtEPSCwEArCW2h5@public.gmane.org,
	'linux-rdma'

On Thu, Oct 01, 2009 at 05:29:45PM -0700, Smith, Stan wrote:

> Do the Sun guys use gcc?

gcc is commonly available on Solaris and it would be a pretty
pointless waste of time to compile opensm with sun studio :)

> > #define cl_item_obj(item_ptr, obj_ptr, item_field) (typeof(obj_ptr)) \
> >   (void *)((uint8_t*)item_ptr - ((uintptr_t)(&(obj_ptr)->item_field) -
> >   ((uintptr_t)&(obj_ptr))))
> > #endif
> 
> Interesting, worth a try.
> 
> >
> > And rely on the C implicit cast from void* to an object type, and rely
> > on compiles with gcc to do the extra type checking.
> 
> 'compiles with gcc' ?

The use of typeof in cl_item_obj (and typically container_of too) is
just a correctness checking feature.
  struct bar *foo = cl_item_obj(..);
Does not compile if 'struct bar' is the wrong type, deduced
automatically from the arguments. By changing it to not use typeof the
runtime functionality is the same but you loose the static
checking. This is a poor mans way to implement C++ templates :)

So 'relying on compiles with gcc' means you rely on builds with gcc to
do the check and detect incorrect code. Since VS C cannot implement
typeof it cannot provide the check, so lets just toss out the
functionality. No big deal.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* RE: [ofw] [PATCH] typeof() not supported in Windows WDK compiler
       [not found]       ` <20091001234701.GD5191-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
  2009-10-02  0:29         ` Smith, Stan
@ 2009-10-02 16:02         ` Smith, Stan
  1 sibling, 0 replies; 8+ messages in thread
From: Smith, Stan @ 2009-10-02 16:02 UTC (permalink / raw)
  To: 'Sasha Khapyorsky'
  Cc: Jason Gunthorpe,
	ofw-ZwoEplunGu1OwGhvXhtEPSCwEArCW2h5@public.gmane.org,
	'linux-rdma'


Hello Sasha,
  Please skip the patch titled 'typeof() not supported in Windows WDK compiler' as Jason's fix does the job thus requiring no src code changes.

Thank you Jason.

Stan.


Jason Gunthorpe wrote:
> On Thu, Oct 01, 2009 at 03:59:00PM -0700, Sean Hefty wrote:
>>> diff --git a/opensm/opensm/osm_drop_mgr.c
>>> b/opensm/opensm/osm_drop_mgr.c index 4f98cc9..8fe5129 100644 +++
>>> b/opensm/opensm/osm_drop_mgr.c @@ -209,8 +209,13 @@ static void
>>>     drop_mgr_remove_port(osm_sm_t * sm, IN osm_port_t * p_port)
>>> drop_mgr_clean_physp(sm, p_port->p_physp);
>>>
>>>     while (!cl_is_qlist_empty(&p_port->mcm_list)) {
>>> +#ifndef __WIN__
>>>             mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
>>>                                    mcm_port, list_item);
>>> +#else
>>> +           mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
>>> +                                  mcm_port, list_item, (osm_mcm_port_t*) );
>>> +#endif
>>
>> I'd find this more readable if it were #ifdef rather than #ifndef.
>>
>> That said, I've got to believe that there's a better way to handle
>> these changes.  I just don't know what it is.
>
> Hmm
>
> How about
>
> #ifdef __GCC_
> #define cl_item_obj(item_ptr, obj_ptr, item_field) (typeof(obj_ptr)) \
>         ((void *)item_ptr - (unsigned
> long)&((typeof(obj_ptr))0)->item_field) #else
> #define cl_item_obj(item_ptr, obj_ptr, item_field) (typeof(obj_ptr)) \
>   (void *)((uint8_t*)item_ptr - ((uintptr_t)(&(obj_ptr)->item_field) -
>   ((uintptr_t)&(obj_ptr))))
> #endif
>
> And rely on the C implicit cast from void* to an object type, and rely
> on compiles with gcc to do the extra type checking.
>
> Jason

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2009-10-02 16:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-01 22:41 [PATCH] typeof() not supported in Windows WDK compiler Stan C. Smith
2009-10-01 22:59 ` Sean Hefty
2009-10-01 23:14   ` Smith, Stan
2009-10-01 23:38     ` Sean Hefty
     [not found]   ` <2A3759D0AB7F46D59DF8820EFCFAF1F8-Zpru7NauK7drdx17CPfAsdBPR1lH4CV8@public.gmane.org>
2009-10-01 23:47     ` [ofw] " Jason Gunthorpe
     [not found]       ` <20091001234701.GD5191-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2009-10-02  0:29         ` Smith, Stan
     [not found]           ` <3F6F638B8D880340AB536D29CD4C1E1912C86E8C4A-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2009-10-02  2:04             ` Jason Gunthorpe
2009-10-02 16:02         ` Smith, Stan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox