[Bf-blender-cvs] [bbeb1b2b529] master: Depsgraph: Use C++ style of guarded allocation of objects

Sergey Sharybin noreply at git.blender.org
Fri Jul 3 12:31:04 CEST 2020


Commit: bbeb1b2b529290b68e5c8f62820f178d50106ac3
Author: Sergey Sharybin
Date:   Fri Jul 3 12:22:16 2020 +0200
Branches: master
https://developer.blender.org/rBbbeb1b2b529290b68e5c8f62820f178d50106ac3

Depsgraph: Use C++ style of guarded allocation of objects

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

M	source/blender/depsgraph/intern/builder/deg_builder_cache.cc
M	source/blender/depsgraph/intern/builder/deg_builder_cache.h
M	source/blender/depsgraph/intern/builder/deg_builder_remove_noop.cc
M	source/blender/depsgraph/intern/builder/deg_builder_transitive.cc
M	source/blender/depsgraph/intern/depsgraph.cc
M	source/blender/depsgraph/intern/depsgraph.h
M	source/blender/depsgraph/intern/depsgraph_relation.h
M	source/blender/depsgraph/intern/node/deg_node.cc
M	source/blender/depsgraph/intern/node/deg_node.h
M	source/blender/depsgraph/intern/node/deg_node_component.cc
M	source/blender/depsgraph/intern/node/deg_node_factory_impl.h
M	source/blender/depsgraph/intern/node/deg_node_id.cc

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

diff --git a/source/blender/depsgraph/intern/builder/deg_builder_cache.cc b/source/blender/depsgraph/intern/builder/deg_builder_cache.cc
index 2faedc4fcd6..1095905c570 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_cache.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_cache.cc
@@ -158,14 +158,14 @@ DepsgraphBuilderCache::~DepsgraphBuilderCache()
 {
   for (AnimatedPropertyStorage *animated_property_storage :
        animated_property_storage_map_.values()) {
-    OBJECT_GUARDED_DELETE(animated_property_storage, AnimatedPropertyStorage);
+    delete animated_property_storage;
   }
 }
 
 AnimatedPropertyStorage *DepsgraphBuilderCache::ensureAnimatedPropertyStorage(ID *id)
 {
   return animated_property_storage_map_.lookup_or_add_cb(
-      id, []() { return OBJECT_GUARDED_NEW(AnimatedPropertyStorage); });
+      id, []() { return new AnimatedPropertyStorage(); });
 }
 
 AnimatedPropertyStorage *DepsgraphBuilderCache::ensureInitializedAnimatedPropertyStorage(ID *id)
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_cache.h b/source/blender/depsgraph/intern/builder/deg_builder_cache.h
index 6e159f55c94..43348e3bf23 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_cache.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_cache.h
@@ -23,6 +23,8 @@
 
 #pragma once
 
+#include "MEM_guardedalloc.h"
+
 #include "intern/depsgraph_type.h"
 
 #include "RNA_access.h"
@@ -51,6 +53,8 @@ class AnimatedPropertyID {
   /* Corresponds to PointerRNA.data. */
   void *data;
   const PropertyRNA *property_rna;
+
+  MEM_CXX_CLASS_ALLOC_FUNCS("AnimatedPropertyID");
 };
 
 class AnimatedPropertyStorage {
@@ -70,6 +74,8 @@ class AnimatedPropertyStorage {
 
   /* indexed by PointerRNA.data. */
   Set<AnimatedPropertyID> animated_properties_set;
+
+  MEM_CXX_CLASS_ALLOC_FUNCS("AnimatedPropertyStorage");
 };
 
 /* Cached data which can be re-used by multiple builders. */
@@ -98,6 +104,8 @@ class DepsgraphBuilderCache {
   }
 
   Map<ID *, AnimatedPropertyStorage *> animated_property_storage_map_;
+
+  MEM_CXX_CLASS_ALLOC_FUNCS("DepsgraphBuilderCache");
 };
 
 }  // namespace deg
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_remove_noop.cc b/source/blender/depsgraph/intern/builder/deg_builder_remove_noop.cc
index a9b405cfb27..8d51fa1422a 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_remove_noop.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_remove_noop.cc
@@ -68,7 +68,7 @@ void deg_graph_remove_unused_noops(Depsgraph *graph)
 
       /* Remove the relation. */
       rel_in->unlink();
-      OBJECT_GUARDED_DELETE(rel_in, Relation);
+      delete rel_in;
       num_removed_relations++;
 
       /* Queue parent no-op node that has now become unused. */
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc b/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc
index 8ffb20a9999..bd6a364e08a 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc
@@ -102,7 +102,7 @@ void deg_graph_transitive_reduction(Depsgraph *graph)
     }
     for (Relation *rel : relations_to_remove) {
       rel->unlink();
-      OBJECT_GUARDED_DELETE(rel, Relation);
+      delete rel;
     }
     num_removed_relations += relations_to_remove.size();
     relations_to_remove.clear();
diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc
index ce2c7110aee..4a9c840dd9f 100644
--- a/source/blender/depsgraph/intern/depsgraph.cc
+++ b/source/blender/depsgraph/intern/depsgraph.cc
@@ -83,9 +83,7 @@ Depsgraph::Depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluati
 Depsgraph::~Depsgraph()
 {
   clear_id_nodes();
-  if (time_source != nullptr) {
-    OBJECT_GUARDED_DELETE(time_source, TimeSourceNode);
-  }
+  delete time_source;
   BLI_spin_end(&lock);
 }
 
@@ -157,7 +155,7 @@ void Depsgraph::clear_id_nodes()
   clear_id_nodes_conditional([](ID_Type id_type) { return id_type != ID_PA; });
 
   for (IDNode *id_node : id_nodes) {
-    OBJECT_GUARDED_DELETE(id_node, IDNode);
+    delete id_node;
   }
   /* Clear containers. */
   id_hash.clear();
@@ -188,7 +186,7 @@ Relation *Depsgraph::add_new_relation(Node *from, Node *to, const char *descript
 #endif
 
   /* Create new relation, and add it to the graph. */
-  rel = OBJECT_GUARDED_NEW(Relation, from, to, description);
+  rel = new Relation(from, to, description);
   rel->flag |= flags;
   return rel;
 }
@@ -229,10 +227,8 @@ void Depsgraph::add_entry_tag(OperationNode *node)
 void Depsgraph::clear_all_nodes()
 {
   clear_id_nodes();
-  if (time_source != nullptr) {
-    OBJECT_GUARDED_DELETE(time_source, TimeSourceNode);
-    time_source = nullptr;
-  }
+  delete time_source;
+  time_source = nullptr;
 }
 
 ID *Depsgraph::get_cow_id(const ID *id_orig) const
@@ -270,8 +266,7 @@ ID *Depsgraph::get_cow_id(const ID *id_orig) const
 /* Initialize a new Depsgraph */
 Depsgraph *DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
 {
-  deg::Depsgraph *deg_depsgraph = OBJECT_GUARDED_NEW(
-      deg::Depsgraph, bmain, scene, view_layer, mode);
+  deg::Depsgraph *deg_depsgraph = new deg::Depsgraph(bmain, scene, view_layer, mode);
   deg::register_graph(deg_depsgraph);
   return reinterpret_cast<Depsgraph *>(deg_depsgraph);
 }
@@ -308,7 +303,7 @@ void DEG_graph_free(Depsgraph *graph)
   using deg::Depsgraph;
   deg::Depsgraph *deg_depsgraph = reinterpret_cast<deg::Depsgraph *>(graph);
   deg::unregister_graph(deg_depsgraph);
-  OBJECT_GUARDED_DELETE(deg_depsgraph, Depsgraph);
+  delete deg_depsgraph;
 }
 
 bool DEG_is_evaluating(const struct Depsgraph *depsgraph)
diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h
index 9dea518b89c..ea579a4958e 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -31,6 +31,8 @@
 
 #include <stdlib.h>
 
+#include "MEM_guardedalloc.h"
+
 #include "DNA_ID.h" /* for ID_Type */
 
 #include "BKE_main.h" /* for MAX_LIBARRAY */
@@ -168,6 +170,8 @@ struct Depsgraph {
   /* Cached list of colliders/effectors for collections and the scene
    * created along with relations, for fast lookup during evaluation. */
   Map<const ID *, ListBase *> *physics_relations[DEG_PHYSICS_RELATIONS_NUM];
+
+  MEM_CXX_CLASS_ALLOC_FUNCS("Depsgraph");
 };
 
 }  // namespace deg
diff --git a/source/blender/depsgraph/intern/depsgraph_relation.h b/source/blender/depsgraph/intern/depsgraph_relation.h
index a5d69c08d1f..7154710e07e 100644
--- a/source/blender/depsgraph/intern/depsgraph_relation.h
+++ b/source/blender/depsgraph/intern/depsgraph_relation.h
@@ -23,6 +23,8 @@
 
 #pragma once
 
+#include "MEM_guardedalloc.h"
+
 namespace blender {
 namespace deg {
 
@@ -59,6 +61,8 @@ struct Relation {
   /* relationship attributes */
   const char *name; /* label for debugging */
   int flag;         /* Bitmask of RelationFlag) */
+
+  MEM_CXX_CLASS_ALLOC_FUNCS("Relation");
 };
 
 }  // namespace deg
diff --git a/source/blender/depsgraph/intern/node/deg_node.cc b/source/blender/depsgraph/intern/node/deg_node.cc
index 54a22a07ee4..9e386f13888 100644
--- a/source/blender/depsgraph/intern/node/deg_node.cc
+++ b/source/blender/depsgraph/intern/node/deg_node.cc
@@ -302,7 +302,7 @@ Node::~Node()
    * when we're trying to free same link from both it's sides. We don't have
    * dangling links so this is not a problem from memory leaks point of view. */
   for (Relation *rel : inlinks) {
-    OBJECT_GUARDED_DELETE(rel, Relation);
+    delete rel;
   }
 }
 
diff --git a/source/blender/depsgraph/intern/node/deg_node.h b/source/blender/depsgraph/intern/node/deg_node.h
index 94953c4ec5d..188022fa2ae 100644
--- a/source/blender/depsgraph/intern/node/deg_node.h
+++ b/source/blender/depsgraph/intern/node/deg_node.h
@@ -23,6 +23,8 @@
 
 #pragma once
 
+#include "MEM_guardedalloc.h"
+
 #include "intern/depsgraph_type.h"
 
 #include "BLI_utildefines.h"
@@ -204,6 +206,8 @@ struct Node {
   }
 
   virtual NodeClass get_class() const;
+
+  MEM_CXX_CLASS_ALLOC_FUNCS("Node");
 };
 
 /* Macros for common static typeinfo. */
diff --git a/source/blender/depsgraph/intern/node/deg_node_component.cc b/source/blender/depsgraph/intern/node/deg_node_component.cc
index c99b3aba312..490598af8f9 100644
--- a/source/blender/depsgraph/intern/node/deg_node_component.cc
+++ b/source/blender/depsgraph/intern/node/deg_node_component.cc
@@ -221,12 +221,12 @@ void ComponentNode::clear_operations()
 {
   if (operations_map != nullptr) {
     for (OperationNode *op_node : operations_map->values()) {
-      OBJECT_GUARDED_DELETE(op_node, OperationNode);
+      delete op_node;
     }
     operations_map->clear();
   }
   for (OperationNode *op_node : operations) {
-    OBJECT_GUARDED_DELETE(op_node, OperationNode);
+    delete op_node;
   }
   operations.clear();
 }
diff --git a/source/blender/depsgraph/intern/node/deg_node_factory_impl.h b/source/blender/depsgraph/intern/node/deg_node_factory_impl.h
index f5dd7122fca..0fc7e496ed9 100644
--- a/source/blender/depsgraph/intern/node/deg_node_factory_impl.h
+++ b/source/blender/depsgraph/intern/node/deg_node_factory_impl.h
@@ -50,7 +50,7 @@ Node *DepsNodeFactoryImpl<ModeObjectType>::create_node(const ID *id,
                                                        const char *subdata,
                                                        const char *name) const
 {
-  Node *node = OBJECT_GUARDED_NEW(ModeObjectType);
+  Node *node = new ModeObjectType();
   /* Populate base node settings. */
   node->type = type();
   /* Set name if provided, or use default type name. */
diff --git a/source/blender/depsgraph/intern/node/deg_node_id.cc b/source/blender/depsgraph/intern/node/deg_node_id.cc
index 843f59b446a..d0c23f326ce 100644
--- a/source/blender/depsgraph/intern/node/deg_node_id.cc
+++ b/source/blender/depsgraph/intern/node/deg_node_id.cc
@@ -133,7 +133,7 @@ void IDNode::destroy()
   }
 
   for (ComponentNode *comp_node : components.values()) {
-    OBJECT_GUARDED_DELETE(comp_node, ComponentNode);
+    delete comp_node;
   }
 
   /

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list