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
This commit is contained in:
Ankit Meel 2020-11-17 17:10:03 +05:30 committed by Ankit Meel
parent 417224a31b
commit 88de58fd1a
7 changed files with 5 additions and 38 deletions

View File

@ -29,7 +29,6 @@ Checks: >
-bugprone-sizeof-expression,
-bugprone-integer-division,
-bugprone-exception-escape,
-bugprone-redundant-branch-condition,
modernize-*,

View File

@ -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;

View File

@ -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);

View File

@ -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 */

View File

@ -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;
};

View File

@ -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 */

View File

@ -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;
};