Skip to content

Commit 3547708

Browse files
committed
Manage lifetime of Glucose solver pointer using unique_ptr
This has the benefit of allowing the use of a default destructor rather than a hand written destructor. Note that `satcheck_glucose_baset` was already non-copyable because its `solver_hardness` field was non-copyable. The default implementation of the destructor is in the `.cpp` rather than the header file in order to avoid recompiling it every time the header file is included and so that the declaration of the solver destructor is available when instantiating the destructor template of `unique_ptr`.
1 parent 24b4fec commit 3547708

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

scripts/expected_doxygen_warnings.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/home/runner/work/cbmc/cbmc/src/solvers/sat/satcheck_glucose.cpp:246: warning: no matching class member found for
2-
template
3-
satcheck_glucose_baset< Glucose::Solver >::~satcheck_glucose_baset()
4-
5-
/home/runner/work/cbmc/cbmc/src/solvers/sat/satcheck_glucose.cpp:252: warning: no matching class member found for
6-
template
7-
satcheck_glucose_baset< Glucose::SimpSolver >::~satcheck_glucose_baset()
8-
91
warning: Include graph for 'goto_instrument_parse_options.cpp' not generated, too many nodes (97), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
102
warning: Included by graph for 'goto_functions.h' not generated, too many nodes (66), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
113
warning: Included by graph for 'goto_model.h' not generated, too many nodes (111), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.

src/solvers/sat/satcheck_glucose.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected]
1515
#include <stack>
1616

1717
#include <util/invariant.h>
18+
#include <util/make_unique.h>
1819
#include <util/threeval.h>
1920

2021
#include <core/Solver.h>
@@ -244,21 +245,12 @@ void satcheck_glucose_baset<T>::set_assignment(literalt a, bool value)
244245
template <typename T>
245246
satcheck_glucose_baset<T>::satcheck_glucose_baset(
246247
message_handlert &message_handler)
247-
: cnf_solvert(message_handler), solver(new T)
248+
: cnf_solvert(message_handler), solver(util_make_unique<T>())
248249
{
249250
}
250251

251-
template<>
252-
satcheck_glucose_baset<Glucose::Solver>::~satcheck_glucose_baset()
253-
{
254-
delete solver;
255-
}
256-
257-
template<>
258-
satcheck_glucose_baset<Glucose::SimpSolver>::~satcheck_glucose_baset()
259-
{
260-
delete solver;
261-
}
252+
template <typename T>
253+
satcheck_glucose_baset<T>::~satcheck_glucose_baset() = default;
262254

263255
template<typename T>
264256
bool satcheck_glucose_baset<T>::is_in_conflict(literalt a) const

src/solvers/sat/satcheck_glucose.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <solvers/hardness_collector.h>
1616

17+
#include <memory>
18+
1719
// Select one: basic solver or with simplification.
1820
// Note that the solver with simplifier isn't really robust
1921
// when used incrementally, as variables may disappear
@@ -30,6 +32,8 @@ class satcheck_glucose_baset : public cnf_solvert, public hardness_collectort
3032
{
3133
public:
3234
explicit satcheck_glucose_baset(message_handlert &message_handler);
35+
/// A default destructor defined in the `.cpp` is used to ensure the
36+
/// unique_ptr to the solver is correctly destroyed.
3337
~satcheck_glucose_baset() override;
3438

3539
tvt l_get(literalt a) const override;
@@ -70,7 +74,7 @@ class satcheck_glucose_baset : public cnf_solvert, public hardness_collectort
7074
protected:
7175
resultt do_prop_solve() override;
7276

73-
T *solver;
77+
std::unique_ptr<T> solver;
7478

7579
void add_variables();
7680
bvt assumptions;

0 commit comments

Comments
 (0)