Skip to content
Snippets Groups Projects
Commit d0071a08 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

Merge pull request #981 from chleh/config-tree-fix-null-this

make ConfigTreeNew more robust against nullptr accesses
parents f5347b99 a6436a58
No related branches found
No related tags found
No related merge requests found
...@@ -246,4 +246,20 @@ ConfigTreeNew::checkAndInvalidate() ...@@ -246,4 +246,20 @@ ConfigTreeNew::checkAndInvalidate()
_tree = nullptr; _tree = nullptr;
} }
void checkAndInvalidate(ConfigTreeNew &conf)
{
conf.checkAndInvalidate();
}
void checkAndInvalidate(ConfigTreeNew* const conf)
{
if (conf) conf->checkAndInvalidate();
}
void checkAndInvalidate(std::unique_ptr<ConfigTreeNew> const& conf)
{
if (conf) conf->checkAndInvalidate();
}
} }
...@@ -15,10 +15,27 @@ ...@@ -15,10 +15,27 @@
#include <map> #include <map>
#include <functional> #include <functional>
#include <memory>
namespace BaseLib namespace BaseLib
{ {
class ConfigTreeNew;
/*! Check if \c conf has been read entirely and invalidate it.
*
* This method can savely be called on \c nullptr's.
*
* \see ConfigTreeNew::checkAndInvalidate()
*/
void checkAndInvalidate(ConfigTreeNew* const conf);
//! \overload
void checkAndInvalidate(std::unique_ptr<ConfigTreeNew> const& conf);
//! \overload
void checkAndInvalidate(ConfigTreeNew& conf);
template<typename Iterator> class Range; template<typename Iterator> class Range;
/*! /*!
...@@ -306,13 +323,6 @@ public: ...@@ -306,13 +323,6 @@ public:
*/ */
void ignoreConfParamAll(std::string const& param) const; void ignoreConfParamAll(std::string const& param) const;
/*! Checks if the top level of this tree has been read entirely (and not too often).
*
* Caution: This method also invalidates the instance, i.e., afterwards it can not
* be read from the tree anymore!
*/
void checkAndInvalidate();
//! The destructor performs the check if all nodes at the current level of the tree //! The destructor performs the check if all nodes at the current level of the tree
//! have been read. //! have been read.
~ConfigTreeNew(); ~ConfigTreeNew();
...@@ -373,6 +383,13 @@ private: ...@@ -373,6 +383,13 @@ private:
//! and the number of times it exists in the ConfigTree //! and the number of times it exists in the ConfigTree
void markVisitedDecrement(std::string const& key) const; void markVisitedDecrement(std::string const& key) const;
/*! Checks if the top level of this tree has been read entirely (and not too often).
*
* Caution: This method also invalidates the instance, i.e., afterwards it can not
* be read from the tree anymore!
*/
void checkAndInvalidate();
//! returns a short string at suitable for error/warning messages //! returns a short string at suitable for error/warning messages
static std::string shortString(std::string const& s); static std::string shortString(std::string const& s);
...@@ -402,6 +419,10 @@ private: ...@@ -402,6 +419,10 @@ private:
//! Set of allowed characters in a key name. //! Set of allowed characters in a key name.
static const std::string key_chars; static const std::string key_chars;
friend void checkAndInvalidate(ConfigTreeNew* const conf);
friend void checkAndInvalidate(ConfigTreeNew& conf);
friend void checkAndInvalidate(std::unique_ptr<ConfigTreeNew> const& conf);
}; };
} }
......
...@@ -150,7 +150,7 @@ private: ...@@ -150,7 +150,7 @@ private:
_rhs.reset(_global_setup.createVector(num_unknowns)); _rhs.reset(_global_setup.createVector(num_unknowns));
_linear_solver.reset(new typename GlobalSetup::LinearSolver( _linear_solver.reset(new typename GlobalSetup::LinearSolver(
*_A, solver_name, _linear_solver_options.get())); *_A, solver_name, _linear_solver_options.get()));
_linear_solver_options->checkAndInvalidate(); checkAndInvalidate(_linear_solver_options);
} }
/// Computes and stores global matrix' sparsity pattern from given /// Computes and stores global matrix' sparsity pattern from given
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment