Skip to contentSkip to conversation

opensm: fixing compilation issues in some header files

PATCH Applied Yevgeny Kliteynik 4 participants 11 messages Mar 24, 2010 – Jun 2, 2010 5 messages not in the archive InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 opensm: fixing compilation issues in some header files

All the compilation issues refer to implicit casting from "void*" to "some_struct_t*"

---
 opensm/include/opensm/osm_pkey.h   |    8 +++++---
 opensm/include/opensm/osm_port.h   |    4 ++--
 opensm/include/opensm/osm_subnet.h |    2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)
opensm/include/opensm/osm_pkey.h +5 -3
index d10479d..53e9657 100644
@@ -252,7 +252,8 @@ static inline ib_pkey_table_t *osm_pkey_tbl_block_get(const osm_pkey_tbl_t *
 						      uint16_t block)
 {
 	return ((block < cl_ptr_vector_get_size(&p_pkey_tbl->blocks)) ?
-		cl_ptr_vector_get(&p_pkey_tbl->blocks, block) : NULL);
+		(ib_pkey_table_t *)cl_ptr_vector_get(
+		&p_pkey_tbl->blocks, block) : NULL);
 };
 
 /*
@@ -282,8 +283,9 @@ static inline ib_pkey_table_t *osm_pkey_tbl_new_block_get(const osm_pkey_tbl_t *
 							  p_pkey_tbl,
 							  uint16_t block)
 {
-	return (block < cl_ptr_vector_get_size(&p_pkey_tbl->new_blocks)) ?
-	    cl_ptr_vector_get(&p_pkey_tbl->new_blocks, block) : NULL;
+	return ((block < cl_ptr_vector_get_size(&p_pkey_tbl->new_blocks)) ?
+		(ib_pkey_table_t *)cl_ptr_vector_get(
+		&p_pkey_tbl->new_blocks, block) : NULL);
 };
 
 /****f* OpenSM: osm_pkey_tbl_set_new_entry
opensm/include/opensm/osm_port.h +2 -2
index ff0a178..8c68c99 100644
@@ -549,7 +549,7 @@ static inline void osm_physp_set_slvl_tbl(IN osm_physp_t * p_physp,
 
 	CL_ASSERT(p_slvl_tbl);
 	CL_ASSERT(osm_physp_is_valid(p_physp));
-	p_tbl = cl_ptr_vector_get(&p_physp->slvl_by_port, in_port_num);
+	p_tbl = (ib_slvl_table_t *)cl_ptr_vector_get(&p_physp->slvl_by_port, in_port_num);
 	*p_tbl = *p_slvl_tbl;
 }
 
@@ -590,7 +590,7 @@ static inline ib_slvl_table_t *osm_physp_get_slvl_tbl(IN const osm_physp_t *
 	ib_slvl_table_t *p_tbl;
 
 	CL_ASSERT(osm_physp_is_valid(p_physp));
-	p_tbl = cl_ptr_vector_get(&p_physp->slvl_by_port, in_port_num);
+	p_tbl = (ib_slvl_table_t *)cl_ptr_vector_get(&p_physp->slvl_by_port, in_port_num);
 	return p_tbl;
 }
 
opensm/include/opensm/osm_subnet.h +1 -1
index 3970e98..2eef9c7 100644
@@ -1015,7 +1015,7 @@ struct osm_mgrp *osm_get_mgrp_by_mgid(IN osm_subn_t * subn, IN ib_gid_t * mgid);
 */
 static inline struct osm_mgrp_box *osm_get_mbox_by_mlid(osm_subn_t const *p_subn, ib_net16_t mlid)
 {
-	return p_subn->mboxes[cl_ntoh16(mlid) - IB_LID_MCAST_START_HO];
+	return (struct osm_mgrp_box *)p_subn->mboxes[cl_ntoh16(mlid) - IB_LID_MCAST_START_HO];
 }
 /*
 * PARAMETERS
Signature · 6 lines
1.5.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 4BAA34B2.9060808-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org

#2 lore raw

Sasha,

Quoted 2 lines · Yevgeny Kliteynik

All the compilation issues refer to implicit casting from "void*" to "some_struct_t*"

This was detected when compiling a code that includes these headers with g++ compiler. The headers should be able to compile by g++ (they have 'extern "C"'). But the problem is not only with g++ - it is with typing in general. I may be wrong, but I feel that every new gcc version is more strongly typed. Moreover, it appears that it would be more strongly typed in the future, as GCC folks themselves are starting to compile GCC with G++:

http://gcc.gnu.org/ml/gcc/2010-05/msg00705.html

-- Yevgeny

Quoted 60 lines
---
  opensm/include/opensm/osm_pkey.h   |    8 +++++---
  opensm/include/opensm/osm_port.h   |    4 ++--
  opensm/include/opensm/osm_subnet.h |    2 +-
  3 files changed, 8 insertions(+), 6 deletions(-)
opensm/include/opensm/osm_pkey.h +5 -3
index d10479d..53e9657 100644
@@ -252,7 +252,8 @@ static inline ib_pkey_table_t *osm_pkey_tbl_block_get(const osm_pkey_tbl_t *
  						      uint16_t block)
  {
  	return ((block<  cl_ptr_vector_get_size(&p_pkey_tbl->blocks)) ?
-		cl_ptr_vector_get(&p_pkey_tbl->blocks, block) : NULL);
+		(ib_pkey_table_t *)cl_ptr_vector_get(
+		&p_pkey_tbl->blocks, block) : NULL);
  };
 
  /*
@@ -282,8 +283,9 @@ static inline ib_pkey_table_t *osm_pkey_tbl_new_block_get(const osm_pkey_tbl_t *
  							  p_pkey_tbl,
  							  uint16_t block)
  {
-	return (block<  cl_ptr_vector_get_size(&p_pkey_tbl->new_blocks)) ?
-	    cl_ptr_vector_get(&p_pkey_tbl->new_blocks, block) : NULL;
+	return ((block<  cl_ptr_vector_get_size(&p_pkey_tbl->new_blocks)) ?
+		(ib_pkey_table_t *)cl_ptr_vector_get(
+		&p_pkey_tbl->new_blocks, block) : NULL);
  };
 
  /****f* OpenSM: osm_pkey_tbl_set_new_entry
opensm/include/opensm/osm_port.h +2 -2
index ff0a178..8c68c99 100644
@@ -549,7 +549,7 @@ static inline void osm_physp_set_slvl_tbl(IN osm_physp_t * p_physp,
 
  	CL_ASSERT(p_slvl_tbl);
  	CL_ASSERT(osm_physp_is_valid(p_physp));
-	p_tbl = cl_ptr_vector_get(&p_physp->slvl_by_port, in_port_num);
+	p_tbl = (ib_slvl_table_t *)cl_ptr_vector_get(&p_physp->slvl_by_port, in_port_num);
  	*p_tbl = *p_slvl_tbl;
  }
 
@@ -590,7 +590,7 @@ static inline ib_slvl_table_t *osm_physp_get_slvl_tbl(IN const osm_physp_t *
  	ib_slvl_table_t *p_tbl;
 
  	CL_ASSERT(osm_physp_is_valid(p_physp));
-	p_tbl = cl_ptr_vector_get(&p_physp->slvl_by_port, in_port_num);
+	p_tbl = (ib_slvl_table_t *)cl_ptr_vector_get(&p_physp->slvl_by_port, in_port_num);
  	return p_tbl;
  }
 
opensm/include/opensm/osm_subnet.h +0 -0
index 3970e98..2eef9c7 100644

opensm/include/opensm/osm_subnet.h struct osm_mgrp *osm_get_mgrp_by_mgid(IN osm_subn_t * subn, IN ib_gid_t * mgid); · line 1021

Quoted 8 lines
opensm/include/opensm/osm_subnet.h +1 -1
@@ -1015,7 +1015,7 @@ struct osm_mgrp *osm_get_mgrp_by_mgid(IN osm_subn_t * subn, IN ib_gid_t * mgid);
  */
  static inline struct osm_mgrp_box *osm_get_mbox_by_mlid(osm_subn_t const *p_subn, ib_net16_t mlid)
  {
-	return p_subn->mboxes[cl_ntoh16(mlid) - IB_LID_MCAST_START_HO];
+	return (struct osm_mgrp_box *)p_subn->mboxes[cl_ntoh16(mlid) - IB_LID_MCAST_START_HO];
  }
  /*
  * PARAMETERS

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 4C04F5E7.8030904-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org

#4 lore raw

Hi Yevgeny,

Quoted 8 lines · Yevgeny Kliteynik
Quoted 2 lines · Yevgeny Kliteynik

All the compilation issues refer to implicit casting from "void*" to "some_struct_t*"

This was detected when compiling a code that includes these headers with g++ compiler. The headers should be able to compile by g++ (they have 'extern "C"').

Well let's apply the patch since we have 'extern "C"'.

But this raises another question. All affected header files are OpenSM internals and OpenSM is written in C (not C++). So why 'extern "C"' should be here at all? Do you know?

Quoted 3 lines

But the problem is not only
with g++ - it is with typing in general. I may be wrong, but I feel that every new gcc version is more strongly typed.

AFAIR (anytype *) to (void *) casting is not needed (doing implicitly) in C and this is already part of some basic standards.

Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 18 lines · Sasha Khapyorsky

Hi Yevgeny,

Quoted 8 lines · Yevgeny Kliteynik
Quoted 2 lines · Yevgeny Kliteynik

All the compilation issues refer to implicit casting from "void*" to "some_struct_t*"

This was detected when compiling a code that includes these headers with g++ compiler. The headers should be able to compile by g++ (they have 'extern "C"').

Well let's apply the patch since we have 'extern "C"'.

But this raises another question. All affected header files are OpenSM internals and OpenSM is written in C (not C++). So why 'extern "C"' should be here at all? Do you know?

Quoted 6 lines
Quoted 3 lines

But the problem is not only
with g++ - it is with typing in general. I may be wrong, but I feel that every new gcc version is more strongly typed.

AFAIR (anytype *) to (void *) casting is not needed (doing implicitly) in C and this is already part of some basic standards.

True, but the problem is not (anytype *) to (void *) casting. It's the other way around: (void *) to (anytype *) casting.

-- Yevgeny

Quoted 2 lines

Sasha

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 4C057940.1020106-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org

#7 lore raw
Quoted 6 lines · Yevgeny Kliteynik
Quoted 3 lines

AFAIR (anytype *) to (void *) casting is not needed (doing implicitly) in C and this is already part of some basic standards.

True, but the problem is not (anytype *) to (void *) casting. It's the other way around: (void *) to (anytype *) casting.

It is the same meaning. Otherwise it would be useless.

Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
Quoted 9 lines · Sasha Khapyorsky
Quoted 6 lines · Yevgeny Kliteynik
Quoted 3 lines

AFAIR (anytype *) to (void *) casting is not needed (doing implicitly) in C and this is already part of some basic standards.

True, but the problem is not (anytype *) to (void *) casting. It's the other way around: (void *) to (anytype *) casting.

It is the same meaning. Otherwise it would be useless.

No, it's not.
Casting TO void* is not dangerous - void* is just a "place holder". Casting FROM void* is more dangerous - it means your program would actually be using this pointer's content.

Right now gcc allows you to do implicit casting in both ways, g++ doesn't.

Try compiling this code:

#include <stdlib.h>
int main()

{
        void * v = NULL;
        int * t = NULL;
        v = t;
        t = v;
        return 0;
}

try.cc:7: error: invalid conversion from 'void*' to 'int*'

Here are more details:

http://www2.research.att.com/~bs/bs_faq2.html#void-ptr

-- Yevgeny

Quoted 2 lines

Sasha

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 4C06084D.3070101-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org

#11 lore raw
Quoted 5 lines · Sasha Khapyorsky
Quoted 2 lines · Yevgeny Kliteynik

Right now gcc allows you to do implicit casting in both ways, g++ doesn't.

OpenSM is written in C, not C++.

g++ can be used as a (better) C compiler. Shouldn't compilation with g++ be supported ?

-- Hal

Quoted 7 lines

Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): AANLkTinyMA8WyFPee755nelj9gxJKTP7mQChYlDkUF4J-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#14 lore raw
In reply to a message not in the archive
Quoted 2 lines

g++ can be used as a (better) C compiler. Shouldn't compilation with g++ be supported ?

g++ is not a C compiler. C++ is not just a superset of C The differences in the semantics of void* pointers are just one example; in addition C++ does not have designated initializers for structures, some valid C names are reserved words in C++, etc.

- R.

Signature · 6 lines
Roland Dreier <[email protected]> || For corporate legal information go to:
http://www.cisco.com/web/about/doing_business/legal/cri/index.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#15 lore raw
In reply to a message not in the archive
Quoted 4 lines · Yevgeny Kliteynik

All the compilation issues refer to implicit casting from "void*" to "some_struct_t*"

Applied. Thanks. However see a comment below.

Quoted 59 lines
---
 opensm/include/opensm/osm_pkey.h   |    8 +++++---
 opensm/include/opensm/osm_port.h   |    4 ++--
 opensm/include/opensm/osm_subnet.h |    2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)
opensm/include/opensm/osm_pkey.h +5 -3
index d10479d..53e9657 100644
@@ -252,7 +252,8 @@ static inline ib_pkey_table_t *osm_pkey_tbl_block_get(const osm_pkey_tbl_t *
 						      uint16_t block)
 {
 	return ((block < cl_ptr_vector_get_size(&p_pkey_tbl->blocks)) ?
-		cl_ptr_vector_get(&p_pkey_tbl->blocks, block) : NULL);
+		(ib_pkey_table_t *)cl_ptr_vector_get(
+		&p_pkey_tbl->blocks, block) : NULL);
 };
 
 /*
@@ -282,8 +283,9 @@ static inline ib_pkey_table_t *osm_pkey_tbl_new_block_get(const osm_pkey_tbl_t *
 							  p_pkey_tbl,
 							  uint16_t block)
 {
-	return (block < cl_ptr_vector_get_size(&p_pkey_tbl->new_blocks)) ?
-	    cl_ptr_vector_get(&p_pkey_tbl->new_blocks, block) : NULL;
+	return ((block < cl_ptr_vector_get_size(&p_pkey_tbl->new_blocks)) ?
+		(ib_pkey_table_t *)cl_ptr_vector_get(
+		&p_pkey_tbl->new_blocks, block) : NULL);
 };
 
 /****f* OpenSM: osm_pkey_tbl_set_new_entry
opensm/include/opensm/osm_port.h +2 -2
index ff0a178..8c68c99 100644
@@ -549,7 +549,7 @@ static inline void osm_physp_set_slvl_tbl(IN osm_physp_t * p_physp,
 
 	CL_ASSERT(p_slvl_tbl);
 	CL_ASSERT(osm_physp_is_valid(p_physp));
-	p_tbl = cl_ptr_vector_get(&p_physp->slvl_by_port, in_port_num);
+	p_tbl = (ib_slvl_table_t *)cl_ptr_vector_get(&p_physp->slvl_by_port, in_port_num);
 	*p_tbl = *p_slvl_tbl;
 }
 
@@ -590,7 +590,7 @@ static inline ib_slvl_table_t *osm_physp_get_slvl_tbl(IN const osm_physp_t *
 	ib_slvl_table_t *p_tbl;
 
 	CL_ASSERT(osm_physp_is_valid(p_physp));
-	p_tbl = cl_ptr_vector_get(&p_physp->slvl_by_port, in_port_num);
+	p_tbl = (ib_slvl_table_t *)cl_ptr_vector_get(&p_physp->slvl_by_port, in_port_num);
 	return p_tbl;
 }
 
opensm/include/opensm/osm_subnet.h +0 -0
index 3970e98..2eef9c7 100644

opensm/include/opensm/osm_subnet.h struct osm_mgrp *osm_get_mgrp_by_mgid(IN osm_subn_t * subn, IN ib_gid_t * mgid); · line 1018

Quoted 5 lines
opensm/include/opensm/osm_subnet.h +1 -1
@@ -1015,7 +1015,7 @@ struct osm_mgrp *osm_get_mgrp_by_mgid(IN osm_subn_t * subn, IN ib_gid_t * mgid);
 */
 static inline struct osm_mgrp_box *osm_get_mbox_by_mlid(osm_subn_t const *p_subn, ib_net16_t mlid)
 {
-	return p_subn->mboxes[cl_ntoh16(mlid) - IB_LID_MCAST_START_HO];
+	return (struct osm_mgrp_box *)p_subn->mboxes[cl_ntoh16(mlid) - IB_LID_MCAST_START_HO];

In this case I would suggest to define p_subn->mboxes[] to have appropriate type and so to avoid the casting issue.

Sasha

Quoted 6 lines
opensm/include/opensm/osm_subnet.h +0 -0
 }
 /*
 * PARAMETERS
Signature · 1 line
1.5.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html