File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -511,29 +511,29 @@ void BINCOL::ReadColumn(PGLOBAL g)
511
511
switch (Fmt) {
512
512
case ' X' : // Standard not converted values
513
513
if (Eds && IsTypeChar (Buf_Type))
514
- Value->SetValue (*( longlong*) p);
514
+ Value->SetValueNonAligned < longlong>( p);
515
515
else
516
516
Value->SetBinValue (p);
517
517
518
518
break ;
519
519
case ' S' : // Short integer
520
- Value->SetValue (*( short *) p);
520
+ Value->SetValueNonAligned < short >( p);
521
521
break ;
522
522
case ' T' : // Tiny integer
523
523
Value->SetValue (*p);
524
524
break ;
525
525
case ' I' : // Integer
526
- Value->SetValue (*( int *) p);
526
+ Value->SetValueNonAligned < int >( p);
527
527
break ;
528
528
case ' G' : // Large (great) integer
529
- Value->SetValue (*( longlong*) p);
529
+ Value->SetValueNonAligned < longlong>( p);
530
530
break ;
531
531
case ' F' : // Float
532
532
case ' R' : // Real
533
- Value->SetValue (( double )*( float *) p);
533
+ Value->SetValueNonAligned < float >( p);
534
534
break ;
535
535
case ' D' : // Double
536
- Value->SetValue (*( double *) p);
536
+ Value->SetValueNonAligned < double >( p);
537
537
break ;
538
538
case ' C' : // Text
539
539
if (Value->SetValue_char (p, Long)) {
Original file line number Diff line number Diff line change @@ -116,6 +116,26 @@ class DllExport VALUE : public BLOCK {
116
116
virtual bool Compute (PGLOBAL g, PVAL *vp, int np, OPVAL op);
117
117
virtual bool FormatValue (PVAL vp, char *fmt) = 0;
118
118
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
+
119
139
protected:
120
140
virtual bool SetConstFormat (PGLOBAL, FORMAT&) = 0;
121
141
const char *GetXfmt (void );
You can’t perform that action at this time.
0 commit comments