Skip to content

Commit

Permalink
ARMv7 portability issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rupnikj committed Nov 13, 2015
1 parent 254e7f4 commit f682240
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
5 changes: 3 additions & 2 deletions binding.gyp
Expand Up @@ -57,8 +57,9 @@
"link_settings": {
"ldflags": [ '-Wl,--allow-multiple-definition' ]
},
'cflags!': [ '-g' ],
'cflags': [ '-fsigned-char' ],
'cflags!': [ ], # add -g if low on memory and gcc fails in debug mode
'cflags': [ '-fsigned-char' ], # add -g if you need symbols in release mode
'defines': [ "ARM" ]
}]
]
}],
Expand Down
19 changes: 19 additions & 0 deletions src/glib/base/dt.h
Expand Up @@ -1670,6 +1670,16 @@ static TStr GetHexStr(const TNum& Int){return TStr::Fmt("%llX", Int.Val);}
else if (Val>1000000000){
return GetStr(Val/1000000000)+"."+GetStr((Val%1000000000)/100000000)+"G";}
else {return GetMegaStr(Val);}}*/

static uint64 GetFromBufSafe(const char * Bf) {
#ifdef ARM
uint64 Val;
memcpy(&Val, Bf, sizeof(uint64)); //we cannot use a cast on ARM (needs 8byte memory aligned doubles)
return Val;
#else
return *((uint64*)Bf);
#endif
}
};

/////////////////////////////////////////////////
Expand Down Expand Up @@ -1778,6 +1788,15 @@ class TNum<double>{
if (fabs(Val)>100*1000000000.0){return TStr::Fmt("%.0fG", Val/1000000000.0);}
else if (fabs(Val)>1000000000.0){return TStr::Fmt("%.1fG", Val/1000000000.0);}
else {return GetMegaStr(Val);}}
static double GetFromBufSafe(const char * Bf) {
#ifdef ARM
double Val;
memcpy(&Val, Bf, sizeof(double)); //we cannot use a cast on ARM (needs 8byte memory aligned doubles)
return Val;
#else
return *((double*)Bf);
#endif
}
};

/////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/glib/base/json.h
Expand Up @@ -114,7 +114,7 @@ class TJsonVal {
bool GetBool() const {EAssert(IsBool()); return Bool;}
double GetNum() const {EAssert(IsNum()); return Num;}
int GetInt() const {EAssert(IsNum()); return TFlt::Round(Num);}
uint64 GetUInt64() const {EAssert(IsNum()); return uint64(Num);}
uint64 GetUInt64() const {EAssert(IsNum()); return (unsigned)(int64)(Num);}
int64 GetInt64() const { EAssert(IsNum()); return int64(Num); }
const TStr& GetStr() const {EAssert(IsStr()); return Str;}
uint64 GetTmMSecs() const { return TTm::GetMSecsFromTm(GetTm()); }
Expand Down
12 changes: 6 additions & 6 deletions src/qminer/qminer_storage.cpp
Expand Up @@ -1469,8 +1469,8 @@ void TRecSerializator::GetFieldIntV(TThinMIn& min, const int& FieldId, TIntV& In
}
/// Field getter
uint64 TRecSerializator::GetFieldUInt64(TThinMIn& min, const int& FieldId) const {
const char* bf = GetLocationFixed(min, GetFieldSerialDesc(FieldId));
return *((uint64*)bf);
const char* Bf = GetLocationFixed(min, GetFieldSerialDesc(FieldId));
return TUInt64::GetFromBufSafe(Bf);
}
/// Field getter
TStr TRecSerializator::GetFieldStr(TThinMIn& min, const int& FieldId) const {
Expand Down Expand Up @@ -1525,13 +1525,13 @@ bool TRecSerializator::GetFieldBool(TThinMIn& min, const int& FieldId) const {
}
/// Field getter
double TRecSerializator::GetFieldFlt(TThinMIn& min, const int& FieldId) const {
const char* bf = GetLocationFixed(min, GetFieldSerialDesc(FieldId));
return *((double*)bf);
const char* Bf = GetLocationFixed(min, GetFieldSerialDesc(FieldId));
return TFlt::GetFromBufSafe(Bf); // do not cast (not portable to ARM)
}
/// Field getter
TFltPr TRecSerializator::GetFieldFltPr(TThinMIn& min, const int& FieldId) const {
const char* bf = GetLocationFixed(min, GetFieldSerialDesc(FieldId));
return TFltPr(*((double*)bf), *(((double*)bf) + 1));
const char* Bf = GetLocationFixed(min, GetFieldSerialDesc(FieldId));
return TFltPr(TFlt::GetFromBufSafe(Bf), TFlt::GetFromBufSafe(Bf + sizeof(double))); // do not cast (not portable to ARM)
}
/// Field getter
void TRecSerializator::GetFieldFltV(TThinMIn& min, const int& FieldId, TFltV& FltV) const {
Expand Down

0 comments on commit f682240

Please sign in to comment.