[Bf-blender-cvs] [57aae2a3551] master: OpenSubdiv: Refactor, use C++ allocation for internal classes

Sergey Sharybin noreply at git.blender.org
Wed May 27 12:22:26 CEST 2020


Commit: 57aae2a35511e9c4e137016c33f3c44553375aeb
Author: Sergey Sharybin
Date:   Tue May 19 09:42:05 2020 +0200
Branches: master
https://developer.blender.org/rB57aae2a35511e9c4e137016c33f3c44553375aeb

OpenSubdiv: Refactor, use C++ allocation for internal classes

Only use OBJECT_GUARDED_{NEW. DELETE} for structures which are part of
public C-API (and hence can not have new/delete operators overloaded).

Could try being brave and override new/delete from under C++ ifdef.

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

M	intern/opensubdiv/CMakeLists.txt
A	intern/opensubdiv/internal/base/memory.h
M	intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc
M	intern/opensubdiv/internal/opensubdiv_evaluator_internal.h
M	intern/opensubdiv/internal/topology/topology_refiner_capi.cc
M	intern/opensubdiv/internal/topology/topology_refiner_impl.h

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

diff --git a/intern/opensubdiv/CMakeLists.txt b/intern/opensubdiv/CMakeLists.txt
index eae09bf5dd6..0bf3bbcb2b9 100644
--- a/intern/opensubdiv/CMakeLists.txt
+++ b/intern/opensubdiv/CMakeLists.txt
@@ -50,6 +50,9 @@ if(WITH_OPENSUBDIV)
   )
 
   list(APPEND SRC
+    # Base.
+    internal/base/memory.h
+
     # Device.
     internal/device/device_context_cuda.cc
     internal/device/device_context_cuda.h
diff --git a/intern/opensubdiv/internal/base/memory.h b/intern/opensubdiv/internal/base/memory.h
new file mode 100644
index 00000000000..176d9c14694
--- /dev/null
+++ b/intern/opensubdiv/internal/base/memory.h
@@ -0,0 +1,28 @@
+// Copyright 2020 Blender Foundation. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+#ifndef OPENSUBDIV_BASE_MEMORY_H_
+#define OPENSUBDIV_BASE_MEMORY_H_
+
+#include "MEM_guardedalloc.h"
+
+namespace blender {
+namespace opensubdiv {
+
+}  // namespace opensubdiv
+}  // namespace blender
+
+#endif  // OPENSUBDIV_BASE_MEMORY_H_
diff --git a/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc b/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc
index ea345654484..e5b9654c5d9 100644
--- a/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc
+++ b/intern/opensubdiv/internal/opensubdiv_evaluator_internal.cc
@@ -858,7 +858,7 @@ OpenSubdiv_EvaluatorInternal *openSubdiv_createEvaluatorInternal(
   OpenSubdiv::Far::PatchMap *patch_map = new PatchMap(*patch_table);
   // Wrap everything we need into an object which we control from our side.
   OpenSubdiv_EvaluatorInternal *evaluator_descr;
-  evaluator_descr = OBJECT_GUARDED_NEW(OpenSubdiv_EvaluatorInternal);
+  evaluator_descr = new OpenSubdiv_EvaluatorInternal();
   evaluator_descr->eval_output = new blender::opensubdiv::CpuEvalOutputAPI(eval_output, patch_map);
   evaluator_descr->patch_map = patch_map;
   evaluator_descr->patch_table = patch_table;
@@ -873,5 +873,5 @@ OpenSubdiv_EvaluatorInternal *openSubdiv_createEvaluatorInternal(
 
 void openSubdiv_deleteEvaluatorInternal(OpenSubdiv_EvaluatorInternal *evaluator)
 {
-  OBJECT_GUARDED_DELETE(evaluator, OpenSubdiv_EvaluatorInternal);
+  delete evaluator;
 }
diff --git a/intern/opensubdiv/internal/opensubdiv_evaluator_internal.h b/intern/opensubdiv/internal/opensubdiv_evaluator_internal.h
index dbe4d88539f..a60b82b02fe 100644
--- a/intern/opensubdiv/internal/opensubdiv_evaluator_internal.h
+++ b/intern/opensubdiv/internal/opensubdiv_evaluator_internal.h
@@ -26,6 +26,8 @@
 #include <opensubdiv/far/patchMap.h>
 #include <opensubdiv/far/patchTable.h>
 
+#include "internal/base/memory.h"
+
 struct OpenSubdiv_PatchCoord;
 struct OpenSubdiv_TopologyRefiner;
 
@@ -144,6 +146,8 @@ struct OpenSubdiv_EvaluatorInternal {
   blender::opensubdiv::CpuEvalOutputAPI *eval_output;
   const OpenSubdiv::Far::PatchMap *patch_map;
   const OpenSubdiv::Far::PatchTable *patch_table;
+
+  MEM_CXX_CLASS_ALLOC_FUNCS("OpenSubdiv_EvaluatorInternal");
 };
 
 OpenSubdiv_EvaluatorInternal *openSubdiv_createEvaluatorInternal(
diff --git a/intern/opensubdiv/internal/topology/topology_refiner_capi.cc b/intern/opensubdiv/internal/topology/topology_refiner_capi.cc
index 9bfba259671..5014d24a52b 100644
--- a/intern/opensubdiv/internal/topology/topology_refiner_capi.cc
+++ b/intern/opensubdiv/internal/topology/topology_refiner_capi.cc
@@ -230,7 +230,7 @@ void assignFunctionPointers(OpenSubdiv_TopologyRefiner *topology_refiner)
 OpenSubdiv_TopologyRefiner *allocateTopologyRefiner()
 {
   OpenSubdiv_TopologyRefiner *topology_refiner = OBJECT_GUARDED_NEW(OpenSubdiv_TopologyRefiner);
-  topology_refiner->impl = OBJECT_GUARDED_NEW(OpenSubdiv_TopologyRefinerImpl);
+  topology_refiner->impl = new OpenSubdiv_TopologyRefinerImpl();
   assignFunctionPointers(topology_refiner);
   return topology_refiner;
 }
@@ -256,7 +256,7 @@ OpenSubdiv_TopologyRefiner *openSubdiv_createTopologyRefinerFromConverter(
 
 void openSubdiv_deleteTopologyRefiner(OpenSubdiv_TopologyRefiner *topology_refiner)
 {
-  OBJECT_GUARDED_DELETE(topology_refiner->impl, OpenSubdiv_TopologyRefinerImpl);
+  delete topology_refiner->impl;
   OBJECT_GUARDED_DELETE(topology_refiner, OpenSubdiv_TopologyRefiner);
 }
 
diff --git a/intern/opensubdiv/internal/topology/topology_refiner_impl.h b/intern/opensubdiv/internal/topology/topology_refiner_impl.h
index 507f3d0f869..5c7b81c2540 100644
--- a/intern/opensubdiv/internal/topology/topology_refiner_impl.h
+++ b/intern/opensubdiv/internal/topology/topology_refiner_impl.h
@@ -25,6 +25,7 @@
 
 #include <opensubdiv/far/topologyRefiner.h>
 
+#include "internal/base/memory.h"
 #include "opensubdiv_topology_refiner_capi.h"
 
 namespace blender {
@@ -45,6 +46,8 @@ class TopologyRefinerImpl {
   // Ideally, we would also support refining topology without re-importing it
   // from external world, but that is for later.
   OpenSubdiv_TopologyRefinerSettings settings;
+
+  MEM_CXX_CLASS_ALLOC_FUNCS("TopologyRefinerImpl");
 };
 
 }  // namespace opensubdiv



More information about the Bf-blender-cvs mailing list