List:Commits« Previous MessageNext Message »
From:Martin Zaun Date:February 19 2011 2:47am
Subject:bzr commit into mysql-5.1-telco-6.3 branch (martin.zaun:3389)
View as plain text  
#At file:///Users/mz/mysql/ndb-6.3-wl5421/ based on revid:martin.zaun@stripped

 3389 Martin Zaun	2011-02-18
      ndb_restore - fix pedantic compiler warnings in template refactorization

    modified:
      storage/ndb/include/util/NdbTypesUtil.hpp
      storage/ndb/tools/restore/consumer_restore.cpp
=== modified file 'storage/ndb/include/util/NdbTypesUtil.hpp'
--- a/storage/ndb/include/util/NdbTypesUtil.hpp	2011-02-18 18:07:44 +0000
+++ b/storage/ndb/include/util/NdbTypesUtil.hpp	2011-02-19 02:47:10 +0000
@@ -66,7 +66,7 @@ struct ArrayTypeTraits {
   static bool isFixedSized();
 
   // the size of the length prefix in bytes, or zero if a fixed-sized array
-  static size_t lengthPrefixSize();
+  static Uint32 lengthPrefixSize();
 };
 
 // aliases for array type traits
@@ -109,7 +109,7 @@ struct NumTypeTraits {
   static bool isSigned() { return NumTypeMap< T >::isSigned(); };
 
   // the width of the type in bytes
-  static size_t size();
+  static Uint32 size();
 
   // the minimum finite value
   static T lowest();
@@ -184,7 +184,7 @@ struct ArrayTypeHelper : ArrayTypeTraits
   static Uint32 readLengthPrefix(const void * a);
 
   // write the length prefix (not available if a fixed-sized array)
-  // the upper (non-length-prefix) bytes of 'l' must be zero
+  // the non-length-prefix bytes of 'l' must be zero
   static void writeLengthPrefix(void * a, Uint32 l);
 };
 
@@ -275,7 +275,7 @@ typedef NonStdNumTypeHelper< Uint32 > Hu
 #define NDB_SPECIALIZE_ARRAY_TYPE_TRAITS( TR, B, FS, LPS )              \
   template<> inline bool TR::isBinary() { return B; }                   \
   template<> inline bool TR::isFixedSized() { return FS; }              \
-  template<> inline size_t TR::lengthPrefixSize() { return LPS; }
+  template<> inline Uint32 TR::lengthPrefixSize() { return LPS; }
 
 // coincidentally, we could use ndb constants
 //   NDB_ARRAYTYPE_FIXED, NDB_ARRAYTYPE_SHORT_VAR, NDB_ARRAYTYPE_MEDIUM_VAR
@@ -313,7 +313,7 @@ NDB_SPECIALIZE_NUM_TYPE_MAP(double, doub
 
 // specialize the Traits template members for numeric types
 #define NDB_SPECIALIZE_NUM_TYPE_TRAITS( TR, T, SZ, LO, HI, SM )         \
-  template<> inline size_t TR::size() { return SZ; }                    \
+  template<> inline Uint32 TR::size() { return SZ; }                    \
   template<> inline T TR::lowest() { return LO; }                       \
   template<> inline T TR::highest() { return HI; }                      \
   template<> inline T TR::smallest() { return SM; }
@@ -347,10 +347,12 @@ NDB_SPECIALIZE_NON_STD_NUM_TYPE_TRAITS(T
 #define NDB_SPECIALIZE_ARRAY_TYPE_HELPER_LPS0( H )                      \
   template<> inline Uint32 H::readLengthPrefix(const void * a) {        \
     assert(false);                                                      \
+    (void)a;                                                            \
     return 0;                                                           \
   };                                                                    \
   template<> inline void H::writeLengthPrefix(void * a, Uint32 l) {     \
     assert(false);                                                      \
+    (void)a; (void)l;                                                   \
   }
 
 NDB_SPECIALIZE_ARRAY_TYPE_HELPER_LPS0(Hchar)
@@ -361,13 +363,13 @@ NDB_SPECIALIZE_ARRAY_TYPE_HELPER_LPS0(Hb
 #define NDB_SPECIALIZE_ARRAY_TYPE_HELPER_LPS1( H )                      \
   template<> inline Uint32 H::readLengthPrefix(const void * a) {        \
     assert(a);                                                          \
-    const unsigned char * s = static_cast<const unsigned char *>(a);    \
+    const Uint8 * s = static_cast<const Uint8 *>(a);                    \
     return s[0];                                                        \
   };                                                                    \
   template<> inline void H::writeLengthPrefix(void * a, Uint32 l) {     \
     assert(a);                                                          \
     assert(l >> (lengthPrefixSize() * 8) == 0);                         \
-    unsigned char * t = static_cast<unsigned char *>(a);                \
+    Uint8 * t = static_cast<Uint8 *>(a);                                \
     t[0] = l & 0x000000FF;                                              \
   }
 
@@ -379,15 +381,15 @@ NDB_SPECIALIZE_ARRAY_TYPE_HELPER_LPS1(Hv
 #define NDB_SPECIALIZE_ARRAY_TYPE_HELPER_LPS2( H )                      \
   template<> inline Uint32 H::readLengthPrefix(const void * a) {        \
     assert(a);                                                          \
-    const unsigned char * s = static_cast<const unsigned char *>(a);    \
-    return s[0] + (s[1] << 8);                                          \
+    const Uint8 * s = static_cast<const Uint8 *>(a);                    \
+    return static_cast<Uint32>(s[0] + (s[1] << 8));                     \
   };                                                                    \
   template<> inline void H::writeLengthPrefix(void * a, Uint32 l) {     \
     assert(a);                                                          \
     assert(l >> (lengthPrefixSize() * 8) == 0);                         \
-    unsigned char * t = static_cast<unsigned char *>(a);                \
-    t[0] = l & 0x000000FF;                                              \
-    t[1] = (l & 0x0000FF00) >> 8;                                       \
+    Uint8 * t = static_cast<Uint8 *>(a);                                \
+    t[0] = static_cast<Uint8>(l & 0x000000FF);                          \
+    t[1] = static_cast<Uint8>((l & 0x0000FF00) >> 8);                   \
   }
 
 NDB_SPECIALIZE_ARRAY_TYPE_HELPER_LPS2(Hlongvarchar)
@@ -398,10 +400,11 @@ NDB_SPECIALIZE_ARRAY_TYPE_HELPER_LPS2(Hl
 #define NDB_SPECIALIZE_NUM_TYPE_HELPER_BYTE( H, T )                     \
   template<> inline void H::load(T * t, const char * s) {               \
     assert(t); assert(s); assert(t != (const T *)s);                    \
-    *t = *s;                                                            \
+    *t = static_cast<T>(*s);                                            \
   }                                                                     \
   template<> inline void H::store(char * t, const T * s) {              \
-    H::load((T *)t, (const char *)s);                                   \
+    H::load(reinterpret_cast<T *>(t),                                   \
+            reinterpret_cast<const char *>(s));                         \
   }
 
 NDB_SPECIALIZE_NUM_TYPE_HELPER_BYTE(Hint8, Int8);
@@ -411,12 +414,12 @@ NDB_SPECIALIZE_NUM_TYPE_HELPER_BYTE(Huin
 // specialize the Helper template members for numeric types
 #define NDB_SPECIALIZE_NUM_TYPE_HELPER( H, T )                          \
   template<> inline void H::load(T * t, const char * s) {               \
-    assert(t); assert(s);                                               \
-    assert(t != (const T *)s);                                          \
+    assert(t); assert(s); assert(t != (const T *)s);                    \
     memcpy(t, s, H::size());                                            \
   }                                                                     \
   template<> inline void H::store(char * t, const T * s) {              \
-    H::load((T *)t, (const char *)s);                                   \
+    H::load(reinterpret_cast<T *>(t),                                   \
+            reinterpret_cast<const char *>(s));                         \
   }
 
 NDB_SPECIALIZE_NUM_TYPE_HELPER(Hint16, Int16);

=== modified file 'storage/ndb/tools/restore/consumer_restore.cpp'
--- a/storage/ndb/tools/restore/consumer_restore.cpp	2011-02-18 18:07:44 +0000
+++ b/storage/ndb/tools/restore/consumer_restore.cpp	2011-02-19 02:47:10 +0000
@@ -155,20 +155,22 @@ BackupRestore::convert_integral(const vo
   // Under ansi (and even more K&R) C promotion rules, if 'T' is unsigned
   // and if there's no larger signed type available, the value 's' gets
   // promoted to unsigned; then, a negative value of 's' becomes (large)
-  // positive -- with a wrong comparison outcome. Furthermore, no "mixed
-  // signedness comparison" compiler warnings should be triggered for any
-  // specialization of integral types 'S' and 'T'.
+  // positive -- with a wrong comparison outcome.
+  //
+  // Furthermore, the code should not trigger compiler warnings for any
+  // selection of integral types 'S', 'T' ("mixed signedness comparison",
+  // "comparison of unsigned expression <0 / >=0 is always false/true").
   //
   // The correct approach: do lower bound comparisons on signed types and
   // upper bound comparisons on unsigned types only; this requires casts.
   // For the casts to be safe, compare the value against the zero literal
-  //    if (s < 0) { check as signed } else if (s > 0) { check as unsigned }
-  // which is always a valid test, for signed and unsigned types.
+  //    if (s <= 0) { check as signed } else { check as unsigned }
+  // which is a valid + nontrivial test for signed and unsigned types.
   //
   // This implies that correct, generic conversion code must test into
   // which of these _four_ subranges value 's' falls
-  //    ... < T's lower bound <= ... <= 0 <= ... <= T's upper bound < ...
-  // while handling 's' as signed/unsigned where less/greater zero.
+  //    ... < T's lower bound <= ... <= 0 < ... <= T's upper bound < ...
+  // while handling 's' as signed/unsigned where less-equal/greater zero.
   //
   // Obviously, simplifications are possible if 'S' is unsigned or known
   // to be a subset of 'T'.  This can be accomplished by a few additional
@@ -177,12 +179,7 @@ BackupRestore::convert_integral(const vo
 
   // write the target value
   typename T::DomainT t;
-  if (s == 0) {               // fast track case
-
-    t = 0;
-    truncated = false;
-
-  } else if (s < 0) {         // compile-time expr if S is unsigned
+  if (s <= 0) {
 
     // check value against lower bound as _signed_, safe since all <= 0
     assert(S::lowest() <= 0 && T::lowest() <= 0 && s <= 0);
@@ -200,8 +197,8 @@ BackupRestore::convert_integral(const vo
 
   } else { // (s > 0)
 
-    // check value against upper bound as _unsigned_, safe since all >= 0
-    assert(S::highest() >= 0 && T::highest() >= 0 && s >= 0);
+    // check value against upper bound as _unsigned_, safe since all > 0
+    assert(S::highest() > 0 && T::highest() > 0 && s > 0);
     const typename S::UnsignedT s_h_u = S::asUnsigned(S::highest());
     const typename T::UnsignedT t_h_u = T::asUnsigned(T::highest());
     const typename S::UnsignedT s_u = S::asUnsigned(s);


Attachment: [text/bzr-bundle] bzr/martin.zaun@oracle.com-20110219024710-cvuy452hcadk1w6b.bundle
Thread
bzr commit into mysql-5.1-telco-6.3 branch (martin.zaun:3389) Martin Zaun19 Feb