[Bf-blender-cvs] [cdcae9d22e2] functions: remove run_destructors member from Tuple

Jacques Lucke noreply at git.blender.org
Thu Sep 26 16:51:48 CEST 2019


Commit: cdcae9d22e2af4c6a38d5abf2dc6a09c0b049ca4
Author: Jacques Lucke
Date:   Thu Sep 26 15:21:17 2019 +0200
Branches: functions
https://developer.blender.org/rBcdcae9d22e2af4c6a38d5abf2dc6a09c0b049ca4

remove run_destructors member from Tuple

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

M	source/blender/functions/backends/cpp/tuple.hpp
M	source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp

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

diff --git a/source/blender/functions/backends/cpp/tuple.hpp b/source/blender/functions/backends/cpp/tuple.hpp
index e99bbb55511..c348be3b809 100644
--- a/source/blender/functions/backends/cpp/tuple.hpp
+++ b/source/blender/functions/backends/cpp/tuple.hpp
@@ -143,14 +143,9 @@ class Tuple {
     m_initialized = (bool *)MEM_calloc_arrayN(m_meta->size(), sizeof(bool), __func__);
     m_data = MEM_mallocN(m_meta->size_of_data(), __func__);
     m_owns_mem = true;
-    m_run_destructors = true;
   }
 
-  Tuple(TupleMeta &meta,
-        void *data,
-        bool *initialized,
-        bool was_initialized = false,
-        bool run_destructors = true)
+  Tuple(TupleMeta &meta, void *data, bool *initialized, bool was_initialized = false)
       : m_meta(&meta)
   {
     BLI_assert(data != nullptr);
@@ -158,7 +153,6 @@ class Tuple {
     m_data = data;
     m_initialized = initialized;
     m_owns_mem = false;
-    m_run_destructors = run_destructors;
     if (!was_initialized) {
       this->set_all_uninitialized();
     }
@@ -183,9 +177,7 @@ class Tuple {
 
   ~Tuple()
   {
-    if (m_run_destructors) {
-      this->destruct_all();
-    }
+    this->destruct_all();
     if (m_owns_mem) {
       MEM_freeN(m_data);
       MEM_freeN(m_initialized);
@@ -563,7 +555,6 @@ class Tuple {
   void *m_data;
   bool *m_initialized;
   uint8_t m_owns_mem : 1;
-  uint8_t m_run_destructors : 1;
   TupleMeta *m_meta;
 };
 
diff --git a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
index abe9479aa64..2f0e71bdbe8 100644
--- a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
+++ b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
@@ -244,17 +244,18 @@ class ExecuteFGraph : public TupleCallBody {
     }
   };
 
+/* They are allocated like this to avoid that the destructor is called. */
 #define SETUP_SUB_TUPLES(node_id, body, body_in, body_out) \
-  Tuple body_in(body->meta_in(), \
-                storage.node_input_values_ptr(node_id), \
-                storage.node_input_inits_ptr(node_id), \
-                true, \
-                false); \
-  Tuple body_out(body->meta_out(), \
-                 storage.node_output_values_ptr(node_id), \
-                 storage.node_output_inits_ptr(node_id), \
-                 true, \
-                 false);
+  char body_in_##buffer[sizeof(Tuple)]; \
+  char body_out_##buffer[sizeof(Tuple)]; \
+  Tuple &body_in = *new (body_in_##buffer) Tuple(body->meta_in(), \
+                                                 storage.node_input_values_ptr(node_id), \
+                                                 storage.node_input_inits_ptr(node_id), \
+                                                 true); \
+  Tuple &body_out = *new (body_out_##buffer) Tuple(body->meta_out(), \
+                                                   storage.node_output_values_ptr(node_id), \
+                                                   storage.node_output_inits_ptr(node_id), \
+                                                   true);
 
   using SocketsToComputeStack = Stack<DataSocket, 64>;
   using LazyStatesStack = Stack<LazyStateOfNode>;



More information about the Bf-blender-cvs mailing list