68 lines
2.0 KiB
Diff
68 lines
2.0 KiB
Diff
|
From: Robie Basak <robie.basak@canonical.com>
|
||
|
Date: Sat, 20 Apr 2013 22:05:50 -0300
|
||
|
Subject: Fix ARM alignment problems
|
||
|
|
||
|
This is a temporary workaround. We avoid double alignment issues by using
|
||
|
memcpy to make sure that all doubles are aligned before accessing them.
|
||
|
|
||
|
Last-Update: 2013-03-15
|
||
|
---
|
||
|
src/mongo/bson/bsonelement.h | 16 +++++++++++++++-
|
||
|
src/mongo/db/key.cpp | 2 +-
|
||
|
2 files changed, 16 insertions(+), 2 deletions(-)
|
||
|
|
||
|
diff --git src/mongo/bson/bsonelement.h src/mongo/bson/bsonelement.h
|
||
|
index f094ab9..1ecb47f 100644
|
||
|
--- src/mongo/bson/bsonelement.h
|
||
|
+++ src/mongo/bson/bsonelement.h
|
||
|
@@ -17,7 +17,7 @@
|
||
|
|
||
|
#pragma once
|
||
|
|
||
|
-#include <string.h> // strlen
|
||
|
+#include <string.h> // strlen, memcpy
|
||
|
#include <string>
|
||
|
#include <vector>
|
||
|
|
||
|
@@ -529,13 +529,27 @@ namespace mongo {
|
||
|
}
|
||
|
|
||
|
inline double BSONElement::numberDouble() const {
|
||
|
+#if defined(__arm__)
|
||
|
+ int int_result;
|
||
|
+ long long long_long_result;
|
||
|
+#endif
|
||
|
switch( type() ) {
|
||
|
case NumberDouble:
|
||
|
return _numberDouble();
|
||
|
case NumberInt:
|
||
|
+#if defined(__arm__)
|
||
|
+ memcpy(&int_result, value(), sizeof(int_result));
|
||
|
+ return int_result;
|
||
|
+#else
|
||
|
return *reinterpret_cast< const int* >( value() );
|
||
|
+#endif
|
||
|
case NumberLong:
|
||
|
+#if defined(__arm__)
|
||
|
+ memcpy(&long_long_result, value(), sizeof(long_long_result));
|
||
|
+ return (double)long_long_result;
|
||
|
+#else
|
||
|
return (double) *reinterpret_cast< const long long* >( value() );
|
||
|
+#endif
|
||
|
default:
|
||
|
return 0;
|
||
|
}
|
||
|
diff --git src/mongo/db/key.cpp src/mongo/db/key.cpp
|
||
|
index 3d9eaa7..95959d8 100644
|
||
|
--- src/mongo/db/key.cpp
|
||
|
+++ src/mongo/db/key.cpp
|
||
|
@@ -406,7 +406,7 @@ namespace mongo {
|
||
|
p += 8;
|
||
|
break;
|
||
|
case cdouble:
|
||
|
- b.append("", (double&) *p);
|
||
|
+ b.append("", (reinterpret_cast< const PackedDouble& >(*p)).d);
|
||
|
p += sizeof(double);
|
||
|
break;
|
||
|
case cint:
|