[Bf-blender-cvs] [0982fdccd91] functions: fix alignment in BLI::Optional

Jacques Lucke noreply at git.blender.org
Sat Jan 18 20:17:45 CET 2020


Commit: 0982fdccd913c87da21682080f8b5d76e595c86f
Author: Jacques Lucke
Date:   Thu Jan 16 21:59:00 2020 +0100
Branches: functions
https://developer.blender.org/rB0982fdccd913c87da21682080f8b5d76e595c86f

fix alignment in BLI::Optional

===================================================================

M	source/blender/blenlib/BLI_allocator.h
M	source/blender/blenlib/BLI_optional.h

===================================================================

diff --git a/source/blender/blenlib/BLI_allocator.h b/source/blender/blenlib/BLI_allocator.h
index 568ff5c74e1..a9fbba63ee3 100644
--- a/source/blender/blenlib/BLI_allocator.h
+++ b/source/blender/blenlib/BLI_allocator.h
@@ -53,7 +53,6 @@ class GuardedAllocator {
 
   void *allocate_aligned(uint size, uint alignment, const char *name)
   {
-    alignment = std::max<uint>(alignment, 8);
     return MEM_mallocN_aligned(size, alignment, name);
   }
 
diff --git a/source/blender/blenlib/BLI_optional.h b/source/blender/blenlib/BLI_optional.h
index 6ffff38cc0d..92e64996ede 100644
--- a/source/blender/blenlib/BLI_optional.h
+++ b/source/blender/blenlib/BLI_optional.h
@@ -23,6 +23,7 @@
 #pragma once
 
 #include "BLI_utildefines.h"
+#include "BLI_memory_utils_cxx.h"
 
 #include <algorithm>
 #include <memory>
@@ -31,7 +32,7 @@ namespace BLI {
 
 template<typename T> class Optional {
  private:
-  char m_raw_data[sizeof(T)];
+  AlignedBuffer<sizeof(T), alignof(T)> m_storage;
   bool m_set;
 
  public:
@@ -174,7 +175,7 @@ template<typename T> class Optional {
  private:
   T *value_ptr() const
   {
-    return (T *)m_raw_data;
+    return (T *)m_storage.ptr();
   }
 };



More information about the Bf-blender-cvs mailing list