[Bf-blender-cvs] [eb403083c67] functions: support that tuples own their meta data

Jacques Lucke noreply at git.blender.org
Thu Aug 1 18:23:39 CEST 2019


Commit: eb403083c67fbecaad7c8bed525fea4e77929bdc
Author: Jacques Lucke
Date:   Thu Aug 1 17:17:36 2019 +0200
Branches: functions
https://developer.blender.org/rBeb403083c67fbecaad7c8bed525fea4e77929bdc

support that tuples own their meta data

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

M	source/blender/functions/backends/tuple/tuple.hpp

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

diff --git a/source/blender/functions/backends/tuple/tuple.hpp b/source/blender/functions/backends/tuple/tuple.hpp
index 89e46e0b019..e042b9194af 100644
--- a/source/blender/functions/backends/tuple/tuple.hpp
+++ b/source/blender/functions/backends/tuple/tuple.hpp
@@ -133,9 +133,16 @@ class Tuple {
     m_initialized = (bool *)MEM_calloc_arrayN(m_meta->element_amount(), sizeof(bool), __func__);
     m_data = MEM_mallocN(m_meta->size_of_data(), __func__);
     m_owns_mem = true;
+    m_owns_meta = false;
     m_run_destructors = true;
   }
 
+  Tuple(SharedTupleMeta meta) : Tuple(*meta.ptr())
+  {
+    meta->incref();
+    m_owns_meta = true;
+  }
+
   Tuple(TupleMeta &meta,
         void *data,
         bool *initialized,
@@ -148,6 +155,7 @@ class Tuple {
     m_data = data;
     m_initialized = initialized;
     m_owns_mem = false;
+    m_owns_meta = false;
     m_run_destructors = run_destructors;
     if (!was_initialized) {
       this->set_all_uninitialized();
@@ -180,6 +188,9 @@ class Tuple {
       MEM_freeN(m_data);
       MEM_freeN(m_initialized);
     }
+    if (m_owns_meta) {
+      m_meta->decref();
+    }
   }
 
   /**
@@ -531,14 +542,14 @@ class Tuple {
     return *m_meta;
   }
 
-  void print_initialized(std::string name = "");
-
- private:
   inline void *element_ptr(uint index) const
   {
     return (void *)((char *)m_data + m_meta->offsets()[index]);
   }
 
+  void print_initialized(std::string name = "");
+
+ private:
   template<typename T> inline T &element_ref(uint index) const
   {
     return *(T *)this->element_ptr(index);
@@ -546,8 +557,9 @@ class Tuple {
 
   void *m_data;
   bool *m_initialized;
-  bool m_owns_mem;
-  bool m_run_destructors;
+  uint8_t m_owns_mem : 1;
+  uint8_t m_owns_meta : 1;
+  uint8_t m_run_destructors : 1;
   TupleMeta *m_meta;
 };



More information about the Bf-blender-cvs mailing list