Skip to contentSkip to conversation

opensm/complib/cl_passivelock.h: some casting issues

PATCH Superseded Yevgeny Kliteynik 1 participant 2 messages Feb 1, 2010 – Feb 2, 2010 1 message not in the archive InfiniBand

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 opensm/complib/cl_passivelock.h: some casting issues

Sasha,

There are couple of problematic castings in complib/cl_passivelock.h:

(cl_status_t) pthread_rwlock_*()

Turns out that compiler doesn't like casting directly from int to enum, probably because int can be negative:

cl_passivelock.h:199: warning: cast from function call of type 'int' to non-matching type 'enum _cl_status' cl_passivelock.h:241: warning: cast from function call of type 'int' to non-matching type 'enum _cl_status' cl_passivelock.h:274: warning: cast from function call of type 'int' to non-matching type 'enum _cl_status' cl_passivelock.h:306: warning: cast from function call of type 'int' to non-matching type 'enum _cl_status'

Se we can cast the return value in two stages - to unsigned and then to enum, but casting it once to unsigned solves the problem - the compiler can cast unsigned to enum w/o explicit casting.

---

Changes from v1: cosmetics - there was '//' at the
end of each fixed line, removed now.

 opensm/include/complib/cl_passivelock.h |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
opensm/include/complib/cl_passivelock.h +4 -4
index bafd339..aba4e64 100644
@@ -196,7 +196,7 @@ static inline cl_status_t cl_plock_init(IN cl_plock_t * const p_lock)
 	cl_status_t status;
 
 	CL_ASSERT(p_lock);
-	status = (cl_status_t) pthread_rwlock_init(&p_lock->lock, NULL);
+	status = (unsigned) pthread_rwlock_init(&p_lock->lock, NULL);
 	if (status)
 		return CL_ERROR;
 	p_lock->state = CL_INITIALIZED;
@@ -238,7 +238,7 @@ static inline void cl_plock_acquire(IN cl_plock_t * const p_lock)
 	CL_ASSERT(p_lock);
 	CL_ASSERT(p_lock->state == CL_INITIALIZED);
 
-	status = (cl_status_t) pthread_rwlock_rdlock(&p_lock->lock);
+	status = (unsigned) pthread_rwlock_rdlock(&p_lock->lock);
 	CL_ASSERT(status == 0);
 }
 
@@ -271,7 +271,7 @@ static inline void cl_plock_excl_acquire(IN cl_plock_t * const p_lock)
 	CL_ASSERT(p_lock);
 	CL_ASSERT(p_lock->state == CL_INITIALIZED);
 
-	status = (cl_status_t) pthread_rwlock_wrlock(&p_lock->lock);
+	status = (unsigned) pthread_rwlock_wrlock(&p_lock->lock);
 	CL_ASSERT(status == 0);
 }
 
@@ -303,7 +303,7 @@ static inline void cl_plock_release(IN cl_plock_t * const p_lock)
 	CL_ASSERT(p_lock);
 	CL_ASSERT(p_lock->state == CL_INITIALIZED);
 
-	status = (cl_status_t) pthread_rwlock_unlock(&p_lock->lock);
+	status = (unsigned) pthread_rwlock_unlock(&p_lock->lock);
 	CL_ASSERT(status == 0);
 }
 
Signature · 7 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): 4B66FAD2.3010808-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org

#2 lore raw
Quoted 14 lines · Yevgeny Kliteynik

Sasha,

There are couple of problematic castings in complib/cl_passivelock.h:

(cl_status_t) pthread_rwlock_*()

Turns out that compiler doesn't like casting directly from int to enum, probably because int can be negative:

cl_passivelock.h:199: warning: cast from function call of type 'int' to non-matching type 'enum _cl_status' cl_passivelock.h:241: warning: cast from function call of type 'int' to non-matching type 'enum _cl_status' cl_passivelock.h:274: warning: cast from function call of type 'int' to non-matching type 'enum _cl_status' cl_passivelock.h:306: warning: cast from function call of type 'int' to non-matching type 'enum _cl_status'

Quoted 4 lines

Se we can cast the return value in two stages - to unsigned and then to enum, but casting it once to unsigned solves the problem - the compiler can cast unsigned to enum w/o explicit casting.

Well, no. It can't do implicit casting in this case, so there should be implicit casting in two stages. V3 shortly...

-- Yevgeny

Quoted 41 lines

---

Changes from v1: cosmetics - there was '//' at the
end of each fixed line, removed now.

  opensm/include/complib/cl_passivelock.h |    8 ++++----
  1 files changed, 4 insertions(+), 4 deletions(-)
opensm/include/complib/cl_passivelock.h +3 -3
index bafd339..aba4e64 100644
@@ -196,7 +196,7 @@ static inline cl_status_t cl_plock_init(IN cl_plock_t * const p_lock)
  	cl_status_t status;
 
  	CL_ASSERT(p_lock);
-	status = (cl_status_t) pthread_rwlock_init(&p_lock->lock, NULL);
+	status = (unsigned) pthread_rwlock_init(&p_lock->lock, NULL);
  	if (status)
  		return CL_ERROR;
  	p_lock->state = CL_INITIALIZED;
@@ -238,7 +238,7 @@ static inline void cl_plock_acquire(IN cl_plock_t * const p_lock)
  	CL_ASSERT(p_lock);
  	CL_ASSERT(p_lock->state == CL_INITIALIZED);
 
-	status = (cl_status_t) pthread_rwlock_rdlock(&p_lock->lock);
+	status = (unsigned) pthread_rwlock_rdlock(&p_lock->lock);
  	CL_ASSERT(status == 0);
  }
 
@@ -271,7 +271,7 @@ static inline void cl_plock_excl_acquire(IN cl_plock_t * const p_lock)
  	CL_ASSERT(p_lock);
  	CL_ASSERT(p_lock->state == CL_INITIALIZED);
 
-	status = (cl_status_t) pthread_rwlock_wrlock(&p_lock->lock);
+	status = (unsigned) pthread_rwlock_wrlock(&p_lock->lock);
  	CL_ASSERT(status == 0);
  }
 

opensm/include/complib/cl_passivelock.h static inline void cl_plock_release(IN cl_plock_t * const p_lock) · line 309

Quoted 8 lines
opensm/include/complib/cl_passivelock.h +1 -1
@@ -303,7 +303,7 @@ static inline void cl_plock_release(IN cl_plock_t * const p_lock)
  	CL_ASSERT(p_lock);
  	CL_ASSERT(p_lock->state == CL_INITIALIZED);
 
-	status = (cl_status_t) pthread_rwlock_unlock(&p_lock->lock);
+	status = (unsigned) pthread_rwlock_unlock(&p_lock->lock);
  	CL_ASSERT(status == 0);
  }
 

--
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