From: Date: March 23 2007 8:54pm Subject: bk commit into 5.0 tree (lzhou:1.2470) BUG#26986 List-Archive: http://lists.mysql.com/commits/22766 X-Bug: 26986 Message-Id: <200703231954.l2NJscUb000711@dev3-63.dev.cn.tlan> Below is the list of changes that have just been committed into a local 5.0 repository of zhl. When zhl does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-03-23 19:54:22+00:00, lzhou@dev3-63.(none) +2 -0 BUG#26986 Correct insert and select operation of BIT(33) on solaris. ndb/include/util/Bitmask.hpp@stripped, 2007-03-23 19:54:17+00:00, lzhou@dev3-63.(none) +31 -7 Modify setField and getField to copy right value to bits on solaris. ndb/src/common/util/Bitmask.cpp@stripped, 2007-03-23 19:54:17+00:00, lzhou@dev3-63.(none) +67 -10 Modify getFieldImpl and setFieldImpl to copy right value to bits on solaris # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: lzhou # Host: dev3-63.(none) # Root: /home/zhl/mysql/mysql-5.0/bug26986 --- 1.11/ndb/src/common/util/Bitmask.cpp 2007-03-23 19:54:38 +00:00 +++ 1.12/ndb/src/common/util/Bitmask.cpp 2007-03-23 19:54:38 +00:00 @@ -20,36 +20,59 @@ void BitmaskImpl::getFieldImpl(const Uint32 src[], - unsigned shiftL, unsigned len, Uint32 dst[]) + unsigned shiftL, unsigned len, Uint32 dst[], bool reverse) { assert(shiftL < 32); unsigned shiftR = 32 - shiftL; unsigned undefined = shiftL ? ~0 : 0; - * dst = shiftL ? * dst : 0; - + if(reverse) + { + if(shiftL == 0) + dst[0] = 0; + } + else + * dst = shiftL ? * dst : 0; + while(len >= 32) { - * dst++ |= (* src) << shiftL; - * dst = ((* src++) >> shiftR) & undefined; + if(reverse && (shiftL != 0)) + dst[1] |= (* src) << shiftL; + else + * dst++ |= (* src) << shiftL; + + if(shiftL != 0) + * dst = ((* src++) >> shiftR) & undefined; + len -= 32; } + if(len == 0) + return; + if(len < shiftR) { * dst |= ((* src) & ((1 << len) - 1)) << shiftL; } + else if(len == shiftR) + { + * dst |= ((* src) << shiftL); + } else { - * dst++ |= ((* src) << shiftL); + if(reverse) + dst[1] |= ((* src) << shiftL); + else + * dst++ |= ((* src) << shiftL); + * dst = ((* src) >> shiftR) & ((1 << (len - shiftR)) - 1) & undefined; } } void BitmaskImpl::setFieldImpl(Uint32 dst[], - unsigned shiftL, unsigned len, const Uint32 src[]) + unsigned shiftL, unsigned len, const Uint32 src[], bool reverse) { /** * @@ -59,25 +82,59 @@ BitmaskImpl::setFieldImpl(Uint32 dst[], assert(shiftL < 32); unsigned shiftR = 32 - shiftL; unsigned undefined = shiftL ? ~0 : 0; + while(len >= 32) { - * dst = (* src++) >> shiftL; - * dst++ |= ((* src) << shiftR) & undefined; + if(reverse && (shiftL != 0)) + * dst = (src[1]) >> shiftL; + else + * dst = (* src++) >> shiftL; + + if(shiftL != 0) + * dst++ |= ((* src) << shiftR) & undefined; + len -= 32; } + if(len == 0) + return; + Uint32 mask = ((1 << len) -1); * dst = (* dst & ~mask); if(len < shiftR) { * dst |= ((* src++) >> shiftL) & mask; } - else + else if(len == shiftR) { * dst |= ((* src++) >> shiftL); + } + else + { + if(reverse) + * dst |= ((src[1]) >> shiftL); + else + * dst |= ((* src++) >> shiftL); + * dst |= ((* src) & ((1 << (len - shiftR)) - 1)) << shiftR ; } } + +Uint32 +BitmaskImpl::checkEndian() +{ +//ndbout_c("david: enter checkEndian"); + union + { + long l; + char c[sizeof(long)]; + } endian_check; + + endian_check.l = 1; + + return (endian_check.c[sizeof(long)-1]); +} + #else static --- 1.18/ndb/include/util/Bitmask.hpp 2007-03-23 19:54:38 +00:00 +++ 1.19/ndb/include/util/Bitmask.hpp 2007-03-23 19:54:38 +00:00 @@ -148,8 +148,9 @@ public: */ static char* getText(unsigned size, const Uint32 data[], char* buf); private: - static void getFieldImpl(const Uint32 data[], unsigned, unsigned, Uint32 []); - static void setFieldImpl(Uint32 data[], unsigned, unsigned, const Uint32 []); + static void getFieldImpl(const Uint32 data[], unsigned, unsigned, Uint32 [], bool reverse = false); + static void setFieldImpl(Uint32 data[], unsigned, unsigned, const Uint32 [], bool reverse = false); + static Uint32 checkEndian(); }; inline bool @@ -815,17 +816,29 @@ BitmaskImpl::getField(unsigned size, con { assert(pos + len <= (size << 5)); + bool bigEndian = checkEndian(); + bool reverse = 0; src += (pos >> 5); Uint32 offset = pos & 31; - * dst = (* src >> offset) & (len >= 32 ? ~0 : (1 << len) - 1); - + + if(bigEndian && (len > 32)) + reverse = 1; + + if(reverse) + dst[1] = (* src >> offset) & (len >= 32 ? ~0 : (1 << len) - 1); + else + * dst = (* src >> offset) & (len >= 32 ? ~0 : (1 << len) - 1); + if(offset + len <= 32) { return; } Uint32 used = (32 - offset); assert(len > used); - getFieldImpl(src+1, used & 31, len-used, dst+(used >> 5)); + if(reverse) + getFieldImpl(src+1, used & 31, len-used, dst, reverse); + else + getFieldImpl(src+1, used & 31, len-used, dst+(used >> 5)); } inline void @@ -834,11 +847,19 @@ BitmaskImpl::setField(unsigned size, Uin { assert(pos + len <= (size << 5)); + bool bigEndian = checkEndian(); + bool reverse = 0; dst += (pos >> 5); Uint32 offset = pos & 31; Uint32 mask = (len >= 32 ? ~0 : (1 << len) - 1) << offset; - * dst = (* dst & ~mask) | ((*src << offset) & mask); + if(bigEndian && (len > 32)) + reverse = 1; + + if(reverse) + * dst = (* dst & ~mask) | ((src[1] << offset) & mask); + else + * dst = (* dst & ~mask) | ((*src << offset) & mask); if(offset + len <= 32) { @@ -846,7 +867,10 @@ BitmaskImpl::setField(unsigned size, Uin } Uint32 used = (32 - offset); assert(len > used); - setFieldImpl(dst+1, used & 31, len-used, src+(used >> 5)); + if(reverse) + setFieldImpl(dst+1, used & 31, len-used, src , reverse); + else + setFieldImpl(dst+1, used & 31, len-used, src+(used >> 5)); }