Skip to content

Commit 2c0bcff

Browse files
author
Alexander Barkov
committed
MDEV-8693 Tests connect.bin connect.endian fail on armhf (on Debian build system)
1 parent d546d1c commit 2c0bcff

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

storage/connect/tabfix.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,29 +511,29 @@ void BINCOL::ReadColumn(PGLOBAL g)
511511
switch (Fmt) {
512512
case 'X': // Standard not converted values
513513
if (Eds && IsTypeChar(Buf_Type))
514-
Value->SetValue(*(longlong*)p);
514+
Value->SetValueNonAligned<longlong>(p);
515515
else
516516
Value->SetBinValue(p);
517517

518518
break;
519519
case 'S': // Short integer
520-
Value->SetValue(*(short*)p);
520+
Value->SetValueNonAligned<short>(p);
521521
break;
522522
case 'T': // Tiny integer
523523
Value->SetValue(*p);
524524
break;
525525
case 'I': // Integer
526-
Value->SetValue(*(int*)p);
526+
Value->SetValueNonAligned<int>(p);
527527
break;
528528
case 'G': // Large (great) integer
529-
Value->SetValue(*(longlong*)p);
529+
Value->SetValueNonAligned<longlong>(p);
530530
break;
531531
case 'F': // Float
532532
case 'R': // Real
533-
Value->SetValue((double)*(float*)p);
533+
Value->SetValueNonAligned<float>(p);
534534
break;
535535
case 'D': // Double
536-
Value->SetValue(*(double*)p);
536+
Value->SetValueNonAligned<double>(p);
537537
break;
538538
case 'C': // Text
539539
if (Value->SetValue_char(p, Long)) {

storage/connect/value.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@ class DllExport VALUE : public BLOCK {
116116
virtual bool Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op);
117117
virtual bool FormatValue(PVAL vp, char *fmt) = 0;
118118

119+
/**
120+
Set value from a non-aligned in-memory value in the machine byte order.
121+
TYPE can be either of:
122+
- int, short, longlong
123+
- uint, ushort, ulonglong
124+
- float, double
125+
@param - a pointer to a non-aligned value of type TYPE.
126+
*/
127+
template<typename TYPE>
128+
void SetValueNonAligned(const char *p)
129+
{
130+
#if defined(__i386__) || defined(__x86_64__)
131+
SetValue(*((TYPE*) p)); // x86 can cast non-aligned memory directly
132+
#else
133+
TYPE tmp; // a slower version for non-x86 platforms
134+
memcpy(&tmp, p, sizeof(tmp));
135+
SetValue(tmp);
136+
#endif
137+
}
138+
119139
protected:
120140
virtual bool SetConstFormat(PGLOBAL, FORMAT&) = 0;
121141
const char *GetXfmt(void);

0 commit comments

Comments
 (0)