Browse Source

Merge pull request #26069 from hpvb/align-variant

Align the Variant data member
Rémi Verschelde 6 years ago
parent
commit
75c89aaaef
1 changed files with 8 additions and 2 deletions
  1. 8 2
      core/variant.h

+ 8 - 2
core/variant.h

@@ -69,6 +69,13 @@ typedef PoolVector<Vector2> PoolVector2Array;
 typedef PoolVector<Vector3> PoolVector3Array;
 typedef PoolVector<Vector3> PoolVector3Array;
 typedef PoolVector<Color> PoolColorArray;
 typedef PoolVector<Color> PoolColorArray;
 
 
+// Temporary workaround until c++11 alignas()
+#ifdef __GNUC__
+#define GCC_ALIGNED_8 __attribute__((aligned(8)))
+#else
+#define GCC_ALIGNED_8
+#endif
+
 class Variant {
 class Variant {
 public:
 public:
 	// If this changes the table in variant_op must be updated
 	// If this changes the table in variant_op must be updated
@@ -132,7 +139,6 @@ private:
 	_FORCE_INLINE_ const ObjData &_get_obj() const;
 	_FORCE_INLINE_ const ObjData &_get_obj() const;
 
 
 	union {
 	union {
-
 		bool _bool;
 		bool _bool;
 		int64_t _int;
 		int64_t _int;
 		double _real;
 		double _real;
@@ -142,7 +148,7 @@ private:
 		Transform *_transform;
 		Transform *_transform;
 		void *_ptr; //generic pointer
 		void *_ptr; //generic pointer
 		uint8_t _mem[sizeof(ObjData) > (sizeof(real_t) * 4) ? sizeof(ObjData) : (sizeof(real_t) * 4)];
 		uint8_t _mem[sizeof(ObjData) > (sizeof(real_t) * 4) ? sizeof(ObjData) : (sizeof(real_t) * 4)];
-	} _data;
+	} _data GCC_ALIGNED_8;
 
 
 	void reference(const Variant &p_variant);
 	void reference(const Variant &p_variant);
 	void clear();
 	void clear();