[Bf-blender-cvs] [88de58fd1af] master: Clang-tidy, fix bugprone-exception-escape.

Ankit Meel noreply at git.blender.org
Tue Nov 17 13:07:15 CET 2020


Commit: 88de58fd1af9ffb1c6afcc53cf6279aadc51f58c
Author: Ankit Meel
Date:   Tue Nov 17 17:10:03 2020 +0530
Branches: master
https://developer.blender.org/rB88de58fd1af9ffb1c6afcc53cf6279aadc51f58c

Clang-tidy, fix bugprone-exception-escape.

Remove redundant call to `ofstream::close()` from `~PSStrokeRenderer`
and `~TextStrokeRenderer`. ofstream will be destructed automatically.

- For `~Depsgraph`, `std::function`'s constructor can throw.
- Passing throwing statements in the lambda will not be detected by
  clang-tidy.
Fix these issues by using lambda as function argument.

Reviewed By: sergey, sybren
Differential Revision: https://developer.blender.org/D9497

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

M	.clang-tidy
M	source/blender/depsgraph/intern/depsgraph.cc
M	source/blender/depsgraph/intern/depsgraph.h
M	source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp
M	source/blender/freestyle/intern/stroke/PSStrokeRenderer.h
M	source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp
M	source/blender/freestyle/intern/stroke/TextStrokeRenderer.h

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

diff --git a/.clang-tidy b/.clang-tidy
index 10738f574d6..49b238d8708 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -29,7 +29,6 @@ Checks:  >
   -bugprone-sizeof-expression,
   -bugprone-integer-division,
 
-  -bugprone-exception-escape,
   -bugprone-redundant-branch-condition,
 
   modernize-*,
diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc
index 870a6d3fce8..17eeba55a27 100644
--- a/source/blender/depsgraph/intern/depsgraph.cc
+++ b/source/blender/depsgraph/intern/depsgraph.cc
@@ -133,9 +133,10 @@ IDNode *Depsgraph::add_id_node(ID *id, ID *id_cow_hint)
   return id_node;
 }
 
-void Depsgraph::clear_id_nodes_conditional(const std::function<bool(ID_Type id_type)> &filter)
+template<typename FilterFunc>
+static void clear_id_nodes_conditional(Depsgraph::IDDepsNodes *id_nodes, const FilterFunc &filter)
 {
-  for (IDNode *id_node : id_nodes) {
+  for (IDNode *id_node : *id_nodes) {
     if (id_node->id_cow == nullptr) {
       /* This means builder "stole" ownership of the copy-on-written
        * datablock for her own dirty needs. */
@@ -156,8 +157,8 @@ void Depsgraph::clear_id_nodes()
   /* Free memory used by ID nodes. */
 
   /* Stupid workaround to ensure we free IDs in a proper order. */
-  clear_id_nodes_conditional([](ID_Type id_type) { return id_type == ID_SCE; });
-  clear_id_nodes_conditional([](ID_Type id_type) { return id_type != ID_PA; });
+  clear_id_nodes_conditional(&id_nodes, [](ID_Type id_type) { return id_type == ID_SCE; });
+  clear_id_nodes_conditional(&id_nodes, [](ID_Type id_type) { return id_type != ID_PA; });
 
   for (IDNode *id_node : id_nodes) {
     delete id_node;
diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h
index e03846f81e2..14c91834739 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -73,7 +73,6 @@ struct Depsgraph {
   IDNode *find_id_node(const ID *id) const;
   IDNode *add_id_node(ID *id, ID *id_cow_hint = nullptr);
   void clear_id_nodes();
-  void clear_id_nodes_conditional(const std::function<bool(ID_Type id_type)> &filter);
 
   /* Add new relationship between two nodes. */
   Relation *add_new_relation(Node *from, Node *to, const char *description, int flags = 0);
diff --git a/source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp b/source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp
index 0e3fea3ddf8..11787e9f2a2 100644
--- a/source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp
+++ b/source/blender/freestyle/intern/stroke/PSStrokeRenderer.cpp
@@ -41,11 +41,6 @@ PSStrokeRenderer::PSStrokeRenderer(const char *iFileName)
   _ofstream << "%%EndComments" << endl;
 }
 
-PSStrokeRenderer::~PSStrokeRenderer()
-{
-  Close();
-}
-
 void PSStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const
 {
   RenderStrokeRepBasic(iStrokeRep);
@@ -90,11 +85,4 @@ void PSStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
   }
 }
 
-void PSStrokeRenderer::Close()
-{
-  if (_ofstream.is_open()) {
-    _ofstream.close();
-  }
-}
-
 } /* namespace Freestyle */
diff --git a/source/blender/freestyle/intern/stroke/PSStrokeRenderer.h b/source/blender/freestyle/intern/stroke/PSStrokeRenderer.h
index 78aa17d26b6..46bb46ad8b2 100644
--- a/source/blender/freestyle/intern/stroke/PSStrokeRenderer.h
+++ b/source/blender/freestyle/intern/stroke/PSStrokeRenderer.h
@@ -40,15 +40,11 @@ namespace Freestyle {
 class PSStrokeRenderer : public StrokeRenderer {
  public:
   PSStrokeRenderer(const char *iFileName = NULL);
-  virtual ~PSStrokeRenderer();
 
   /*! Renders a stroke rep */
   virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const;
   virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const;
 
-  /*! Closes the output PS file */
-  void Close();
-
  protected:
   mutable ofstream _ofstream;
 };
diff --git a/source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp b/source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp
index fa131743afc..dc98096129d 100644
--- a/source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp
+++ b/source/blender/freestyle/intern/stroke/TextStrokeRenderer.cpp
@@ -38,11 +38,6 @@ TextStrokeRenderer::TextStrokeRenderer(const char *iFileName)
   _ofstream << "%u x y z tleft tright r g b ..." << endl;
 }
 
-TextStrokeRenderer::~TextStrokeRenderer()
-{
-  Close();
-}
-
 void TextStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const
 {
   RenderStrokeRepBasic(iStrokeRep);
@@ -68,11 +63,4 @@ void TextStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
   _ofstream << endl;
 }
 
-void TextStrokeRenderer::Close()
-{
-  if (_ofstream.is_open()) {
-    _ofstream.close();
-  }
-}
-
 } /* namespace Freestyle */
diff --git a/source/blender/freestyle/intern/stroke/TextStrokeRenderer.h b/source/blender/freestyle/intern/stroke/TextStrokeRenderer.h
index c6497aba808..bbc3b5058a3 100644
--- a/source/blender/freestyle/intern/stroke/TextStrokeRenderer.h
+++ b/source/blender/freestyle/intern/stroke/TextStrokeRenderer.h
@@ -53,15 +53,11 @@ namespace Freestyle {
 class TextStrokeRenderer : public StrokeRenderer {
  public:
   TextStrokeRenderer(const char *iFileName = NULL);
-  virtual ~TextStrokeRenderer();
 
   /*! Renders a stroke rep */
   virtual void RenderStrokeRep(StrokeRep *iStrokeRep) const;
   virtual void RenderStrokeRepBasic(StrokeRep *iStrokeRep) const;
 
-  /*! Closes the output file */
-  void Close();
-
  protected:
   mutable ofstream _ofstream;
 };



More information about the Bf-blender-cvs mailing list