You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

257 lines
8.7 KiB

  1. From: Debian MySQL Maintainers <pkg-mysql-maint@lists.alioth.debian.org>
  2. Date: Thu, 10 Aug 2017 20:40:28 +0200
  3. Subject: mips-connect-unaligned
  4. ---
  5. storage/connect/valblk.cpp | 41 ++++++++++++++++++-------------------
  6. storage/connect/valblk.h | 51 +++++++++++++++++++++++++++++-----------------
  7. 2 files changed, 52 insertions(+), 40 deletions(-)
  8. --- a/storage/connect/valblk.cpp
  9. +++ b/storage/connect/valblk.cpp
  10. @@ -268,14 +268,14 @@ bool TYPBLK<TYPE>::Init(PGLOBAL g, bool
  11. template <class TYPE>
  12. char *TYPBLK<TYPE>::GetCharString(char *p, int n)
  13. {
  14. - sprintf(p, Fmt, Typp[n]);
  15. + sprintf(p, Fmt, UnalignedRead(n));
  16. return p;
  17. } // end of GetCharString
  18. template <>
  19. char *TYPBLK<double>::GetCharString(char *p, int n)
  20. {
  21. - sprintf(p, Fmt, Prec, Typp[n]);
  22. + sprintf(p, Fmt, Prec, UnalignedRead(n));
  23. return p;
  24. } // end of GetCharString
  25. @@ -291,7 +291,7 @@ void TYPBLK<TYPE>::SetValue(PVAL valp, i
  26. ChkTyp(valp);
  27. if (!(b = valp->IsNull()))
  28. - Typp[n] = GetTypedValue(valp);
  29. + UnalignedWrite(n, GetTypedValue(valp));
  30. else
  31. Reset(n);
  32. @@ -353,9 +353,9 @@ void TYPBLK<TYPE>::SetValue(PCSZ p, int
  33. ulonglong val = CharToNumber(p, strlen(p), maxval, Unsigned, &minus);
  34. if (minus && val < maxval)
  35. - Typp[n] = (TYPE)(-(signed)val);
  36. + UnalignedWrite(n, (TYPE)(-(signed)val));
  37. else
  38. - Typp[n] = (TYPE)val;
  39. + UnalignedWrite(n, (TYPE)val);
  40. SetNull(n, false);
  41. } // end of SetValue
  42. @@ -398,7 +398,7 @@ void TYPBLK<double>::SetValue(PCSZ p, in
  43. throw Type;
  44. } // endif Check
  45. - Typp[n] = atof(p);
  46. + UnalignedWrite(n, atof(p));
  47. SetNull(n, false);
  48. } // end of SetValue
  49. @@ -430,7 +430,7 @@ void TYPBLK<TYPE>::SetValue(PVBLK pv, in
  50. ChkTyp(pv);
  51. if (!(b = pv->IsNull(n2) && Nullable))
  52. - Typp[n1] = GetTypedValue(pv, n2);
  53. + UnalignedWrite(n1, GetTypedValue(pv, n2));
  54. else
  55. Reset(n1);
  56. @@ -481,10 +481,10 @@ void TYPBLK<TYPE>::SetMin(PVAL valp, int
  57. {
  58. CheckParms(valp, n)
  59. TYPE tval = GetTypedValue(valp);
  60. - TYPE& tmin = Typp[n];
  61. + TYPE tmin = UnalignedRead(n);
  62. if (tval < tmin)
  63. - tmin = tval;
  64. + UnalignedWrite(n, tval);
  65. } // end of SetMin
  66. @@ -496,10 +496,10 @@ void TYPBLK<TYPE>::SetMax(PVAL valp, int
  67. {
  68. CheckParms(valp, n)
  69. TYPE tval = GetTypedValue(valp);
  70. - TYPE& tmin = Typp[n];
  71. + TYPE tmin = UnalignedRead(n);
  72. if (tval > tmin)
  73. - tmin = tval;
  74. + UnalignedWrite(n, tval);
  75. } // end of SetMax
  76. @@ -513,8 +513,7 @@ void TYPBLK<TYPE>::SetValues(PVBLK pv, i
  77. CheckType(pv)
  78. TYPE *lp = ((TYPBLK*)pv)->Typp;
  79. - for (int i = k; i < n; i++) // TODO
  80. - Typp[i] = lp[i];
  81. + memcpy(Typp + k, lp + k, sizeof(TYPE) * n);
  82. } // end of SetValues
  83. #endif // 0
  84. @@ -525,7 +524,7 @@ void TYPBLK<TYPE>::SetValues(PVBLK pv, i
  85. template <class TYPE>
  86. void TYPBLK<TYPE>::Move(int i, int j)
  87. {
  88. - Typp[j] = Typp[i];
  89. + UnalignedWrite(j, UnalignedRead(i));
  90. MoveNull(i, j);
  91. } // end of Move
  92. @@ -539,7 +538,7 @@ int TYPBLK<TYPE>::CompVal(PVAL vp, int n
  93. ChkIndx(n);
  94. ChkTyp(vp);
  95. #endif // _DEBUG
  96. - TYPE mlv = Typp[n];
  97. + TYPE mlv = UnalignedRead(n);
  98. TYPE vlv = GetTypedValue(vp);
  99. return (vlv > mlv) ? 1 : (vlv < mlv) ? (-1) : 0;
  100. @@ -551,8 +550,8 @@ int TYPBLK<TYPE>::CompVal(PVAL vp, int n
  101. template <class TYPE>
  102. int TYPBLK<TYPE>::CompVal(int i1, int i2)
  103. {
  104. - TYPE lv1 = Typp[i1];
  105. - TYPE lv2 = Typp[i2];
  106. + TYPE lv1 = UnalignedRead(i1);
  107. + TYPE lv2 = UnalignedRead(i2);
  108. return (lv1 > lv2) ? 1 : (lv1 < lv2) ? (-1) : 0;
  109. } // end of CompVal
  110. @@ -589,7 +588,7 @@ int TYPBLK<TYPE>::Find(PVAL vp)
  111. TYPE n = GetTypedValue(vp);
  112. for (i = 0; i < Nval; i++)
  113. - if (n == Typp[i])
  114. + if (n == UnalignedRead(i))
  115. break;
  116. return (i < Nval) ? i : (-1);
  117. @@ -605,7 +604,7 @@ int TYPBLK<TYPE>::GetMaxLength(void)
  118. int i, n, m;
  119. for (i = n = 0; i < Nval; i++) {
  120. - m = sprintf(buf, Fmt, Typp[i]);
  121. + m = sprintf(buf, Fmt, UnalignedRead(i));
  122. n = MY_MAX(n, m);
  123. } // endfor i
  124. @@ -1335,7 +1334,7 @@ char *DATBLK::GetCharString(char *p, int
  125. char *vp;
  126. if (Dvalp) {
  127. - Dvalp->SetValue(Typp[n]);
  128. + Dvalp->SetValue(UnalignedRead(n));
  129. vp = Dvalp->GetCharString(p);
  130. } else
  131. vp = TYPBLK<int>::GetCharString(p, n);
  132. @@ -1351,7 +1350,7 @@ void DATBLK::SetValue(PCSZ p, int n)
  133. if (Dvalp) {
  134. // Decode the string according to format
  135. Dvalp->SetValue_psz(p);
  136. - Typp[n] = Dvalp->GetIntValue();
  137. + UnalignedWrite(n, Dvalp->GetIntValue());
  138. } else
  139. TYPBLK<int>::SetValue(p, n);
  140. --- a/storage/connect/valblk.h
  141. +++ b/storage/connect/valblk.h
  142. @@ -139,6 +139,7 @@ class VALBLK : public BLOCK {
  143. int Prec; // Precision of float values
  144. }; // end of class VALBLK
  145. +
  146. /***********************************************************************/
  147. /* Class TYPBLK: represents a block of typed values. */
  148. /***********************************************************************/
  149. @@ -151,40 +152,41 @@ class TYPBLK : public VALBLK {
  150. // Implementation
  151. virtual bool Init(PGLOBAL g, bool check);
  152. virtual int GetVlen(void) {return sizeof(TYPE);}
  153. - virtual char GetTinyValue(int n) {return (char)Typp[n];}
  154. - virtual uchar GetUTinyValue(int n) {return (uchar)Typp[n];}
  155. - virtual short GetShortValue(int n) {return (short)Typp[n];}
  156. - virtual ushort GetUShortValue(int n) {return (ushort)Typp[n];}
  157. - virtual int GetIntValue(int n) {return (int)Typp[n];}
  158. - virtual uint GetUIntValue(int n) {return (uint)Typp[n];}
  159. - virtual longlong GetBigintValue(int n) {return (longlong)Typp[n];}
  160. - virtual ulonglong GetUBigintValue(int n) {return (ulonglong)Typp[n];}
  161. - virtual double GetFloatValue(int n) {return (double)Typp[n];}
  162. +
  163. + virtual char GetTinyValue(int n) {return (char)UnalignedRead(n);}
  164. + virtual uchar GetUTinyValue(int n) {return (uchar)UnalignedRead(n);}
  165. + virtual short GetShortValue(int n) {return (short)UnalignedRead(n);}
  166. + virtual ushort GetUShortValue(int n) {return (ushort)UnalignedRead(n);}
  167. + virtual int GetIntValue(int n) {return (int)UnalignedRead(n);}
  168. + virtual uint GetUIntValue(int n) {return (uint)UnalignedRead(n);}
  169. + virtual longlong GetBigintValue(int n) {return (longlong)UnalignedRead(n);}
  170. + virtual ulonglong GetUBigintValue(int n) {return (ulonglong)UnalignedRead(n);}
  171. + virtual double GetFloatValue(int n) {return (double)UnalignedRead(n);}
  172. virtual char *GetCharString(char *p, int n);
  173. - virtual void Reset(int n) {Typp[n] = 0;}
  174. + virtual void Reset(int n) {UnalignedWrite(n, 0);}
  175. // Methods
  176. using VALBLK::SetValue;
  177. virtual void SetValue(PCSZ sp, int n);
  178. virtual void SetValue(const char *sp, uint len, int n);
  179. virtual void SetValue(short sval, int n)
  180. - {Typp[n] = (TYPE)sval; SetNull(n, false);}
  181. + {UnalignedWrite(n, (TYPE)sval); SetNull(n, false);}
  182. virtual void SetValue(ushort sval, int n)
  183. - {Typp[n] = (TYPE)sval; SetNull(n, false);}
  184. + {UnalignedWrite(n, (TYPE)sval); SetNull(n, false);}
  185. virtual void SetValue(int lval, int n)
  186. - {Typp[n] = (TYPE)lval; SetNull(n, false);}
  187. + {UnalignedWrite(n, (TYPE)lval); SetNull(n, false);}
  188. virtual void SetValue(uint lval, int n)
  189. - {Typp[n] = (TYPE)lval; SetNull(n, false);}
  190. + {UnalignedWrite(n, (TYPE)lval); SetNull(n, false);}
  191. virtual void SetValue(longlong lval, int n)
  192. - {Typp[n] = (TYPE)lval; SetNull(n, false);}
  193. + {UnalignedWrite(n, (TYPE)lval); SetNull(n, false);}
  194. virtual void SetValue(ulonglong lval, int n)
  195. - {Typp[n] = (TYPE)lval; SetNull(n, false);}
  196. + {UnalignedWrite(n, (TYPE)lval); SetNull(n, false);}
  197. virtual void SetValue(double fval, int n)
  198. - {Typp[n] = (TYPE)fval; SetNull(n, false);}
  199. + {UnalignedWrite(n, (TYPE)fval); SetNull(n, false);}
  200. virtual void SetValue(char cval, int n)
  201. - {Typp[n] = (TYPE)cval; SetNull(n, false);}
  202. + {UnalignedWrite(n, (TYPE)cval); SetNull(n, false);}
  203. virtual void SetValue(uchar cval, int n)
  204. - {Typp[n] = (TYPE)cval; SetNull(n, false);}
  205. + {UnalignedWrite(n, (TYPE)cval); SetNull(n, false);}
  206. virtual void SetValue(PVAL valp, int n);
  207. virtual void SetValue(PVBLK pv, int n1, int n2);
  208. virtual void SetMin(PVAL valp, int n);
  209. @@ -206,6 +208,17 @@ class TYPBLK : public VALBLK {
  210. // Members
  211. TYPE* const &Typp;
  212. const char *Fmt;
  213. +
  214. + // Unaligned access
  215. + TYPE UnalignedRead(int n) const {
  216. + TYPE result;
  217. + memcpy(&result, Typp + n, sizeof(TYPE));
  218. + return result;
  219. + }
  220. +
  221. + void UnalignedWrite(int n, TYPE value) {
  222. + memcpy(Typp + n, &value, sizeof(TYPE));
  223. + }
  224. }; // end of class TYPBLK
  225. /***********************************************************************/