-
Notifications
You must be signed in to change notification settings - Fork 274
Replace owning raw pointers with unique_ptr #1029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
513b705
Replace owning raw pointers with unique_ptr
reuk 3b56b1b
Revert virtual/override changes
reuk 1a6249c
Apply @thk123's fixes
reuk 30d8fb5
Fix includes
reuk 9688d11
Remove "final" from freer struct to reduce unique_ptr size
reuk 59169be
Rename ptr -> language
reuk f1ae9fe
Implement @tautschnig's fixes
reuk 92e02b5
Fix residual memory leak from narrow_argv
reuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,14 @@ Author: Daniel Kroening, [email protected] | |
#ifndef CPROVER_ANALYSES_AI_H | ||
#define CPROVER_ANALYSES_AI_H | ||
|
||
#include <map> | ||
#include <iosfwd> | ||
#include <map> | ||
#include <memory> | ||
|
||
#include <util/json.h> | ||
#include <util/xml.h> | ||
#include <util/expr.h> | ||
#include <util/make_unique.h> | ||
|
||
#include <goto-programs/goto_model.h> | ||
|
||
|
@@ -334,7 +336,7 @@ class ai_baset | |
const namespacet &ns)=0; | ||
virtual statet &get_state(locationt l)=0; | ||
virtual const statet &find_state(locationt l) const=0; | ||
virtual statet* make_temporary_state(const statet &s)=0; | ||
virtual std::unique_ptr<statet> make_temporary_state(const statet &s)=0; | ||
}; | ||
|
||
// domainT is expected to be derived from ai_domain_baseT | ||
|
@@ -400,9 +402,9 @@ class ait:public ai_baset | |
static_cast<const domainT &>(src), from, to); | ||
} | ||
|
||
statet *make_temporary_state(const statet &s) override | ||
std::unique_ptr<statet> make_temporary_state(const statet &s) override | ||
{ | ||
return new domainT(static_cast<const domainT &>(s)); | ||
return util_make_unique<domainT>(static_cast<const domainT &>(s)); | ||
} | ||
|
||
void fixedpoint( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,9 @@ Date: April 2010 | |
\*******************************************************************/ | ||
|
||
|
||
#include <limits> | ||
#include <algorithm> | ||
#include <limits> | ||
#include <memory> | ||
|
||
#include <util/std_code.h> | ||
#include <util/std_expr.h> | ||
|
@@ -19,6 +20,7 @@ Date: April 2010 | |
#include <util/endianness_map.h> | ||
#include <util/arith_tools.h> | ||
#include <util/simplify_expr.h> | ||
#include <util/make_unique.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need |
||
|
||
#include <goto-programs/goto_functions.h> | ||
|
||
|
@@ -50,12 +52,12 @@ rw_range_sett::~rw_range_sett() | |
for(rw_range_sett::objectst::iterator it=r_range_set.begin(); | ||
it!=r_range_set.end(); | ||
++it) | ||
delete it->second; | ||
it->second=nullptr; | ||
|
||
for(rw_range_sett::objectst::iterator it=w_range_set.begin(); | ||
it!=w_range_set.end(); | ||
++it) | ||
delete it->second; | ||
it->second=nullptr; | ||
} | ||
|
||
void rw_range_sett::output(std::ostream &out) const | ||
|
@@ -462,15 +464,18 @@ void rw_range_sett::add( | |
const range_spect &range_start, | ||
const range_spect &range_end) | ||
{ | ||
objectst::iterator entry=(mode==get_modet::LHS_W ? w_range_set : r_range_set). | ||
insert( | ||
std::pair<const irep_idt&, range_domain_baset*>(identifier, 0)).first; | ||
|
||
if(entry->second==0) | ||
entry->second=new range_domaint(); | ||
|
||
static_cast<range_domaint*>(entry->second)->push_back( | ||
std::make_pair(range_start, range_end)); | ||
objectst::iterator entry= | ||
(mode==get_modet::LHS_W?w_range_set:r_range_set) | ||
.insert( | ||
std::pair<const irep_idt &, std::unique_ptr<range_domain_baset>>( | ||
identifier, nullptr)) | ||
.first; | ||
|
||
if(entry->second==nullptr) | ||
entry->second=util_make_unique<range_domaint>(); | ||
|
||
static_cast<range_domaint&>(*entry->second).push_back( | ||
{range_start, range_end}); | ||
} | ||
|
||
void rw_range_sett::get_objects_rec( | ||
|
@@ -662,16 +667,18 @@ void rw_guarded_range_set_value_sett::add( | |
const range_spect &range_start, | ||
const range_spect &range_end) | ||
{ | ||
objectst::iterator entry=(mode==get_modet::LHS_W ? w_range_set : r_range_set). | ||
insert( | ||
std::pair<const irep_idt&, range_domain_baset*>(identifier, 0)).first; | ||
|
||
if(entry->second==0) | ||
entry->second=new guarded_range_domaint(); | ||
|
||
static_cast<guarded_range_domaint*>(entry->second)->insert( | ||
std::make_pair(range_start, | ||
std::make_pair(range_end, guard.as_expr()))); | ||
objectst::iterator entry= | ||
(mode==get_modet::LHS_W?w_range_set:r_range_set) | ||
.insert( | ||
std::pair<const irep_idt &, std::unique_ptr<range_domain_baset>>( | ||
identifier, nullptr)) | ||
.first; | ||
|
||
if(entry->second==nullptr) | ||
entry->second=util_make_unique<guarded_range_domaint>(); | ||
|
||
static_cast<guarded_range_domaint&>(*entry->second).insert( | ||
{range_start, {range_end, guard.as_expr()}}); | ||
} | ||
|
||
void goto_rw(goto_programt::const_targett target, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,11 @@ Author: Daniel Kroening, [email protected] | |
#ifndef CPROVER_ANALYSES_LOCAL_MAY_ALIAS_H | ||
#define CPROVER_ANALYSES_LOCAL_MAY_ALIAS_H | ||
|
||
#include <stack> | ||
#include <memory> | ||
#include <stack> | ||
|
||
#include <util/union_find.h> | ||
#include <util/make_unique.h> | ||
|
||
#include "locals.h" | ||
#include "dirty.h" | ||
|
@@ -117,8 +118,7 @@ class local_may_alias_factoryt | |
goto_functionst::function_mapt::const_iterator f_it2= | ||
goto_functions->function_map.find(fkt); | ||
assert(f_it2!=goto_functions->function_map.end()); | ||
return *(fkt_map[fkt]=std::unique_ptr<local_may_aliast>( | ||
new local_may_aliast(f_it2->second))); | ||
return *(fkt_map[fkt]=util_make_unique<local_may_aliast>(f_it2->second)); | ||
} | ||
|
||
local_may_aliast &operator()(goto_programt::const_targett t) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,14 +240,7 @@ class reaching_definitions_analysist: | |
{ | ||
public: | ||
// constructor | ||
explicit reaching_definitions_analysist(const namespacet &_ns): | ||
concurrency_aware_ait<rd_range_domaint>(), | ||
ns(_ns), | ||
value_sets(0), | ||
is_threaded(0), | ||
is_dirty(0) | ||
{ | ||
} | ||
explicit reaching_definitions_analysist(const namespacet &_ns); | ||
|
||
virtual ~reaching_definitions_analysist(); | ||
|
||
|
@@ -286,9 +279,9 @@ class reaching_definitions_analysist: | |
|
||
protected: | ||
const namespacet &ns; | ||
value_setst * value_sets; | ||
is_threadedt * is_threaded; | ||
dirtyt * is_dirty; | ||
std::unique_ptr<value_setst> value_sets; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a |
||
std::unique_ptr<is_threadedt> is_threaded; | ||
std::unique_ptr<dirtyt> is_dirty; | ||
}; | ||
|
||
#endif // CPROVER_ANALYSES_REACHING_DEFINITIONS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,13 @@ Author: Daniel Kroening, [email protected] | |
#error Deprecated, use ai.h instead | ||
#endif | ||
|
||
#include <map> | ||
#include <iosfwd> | ||
#include <map> | ||
#include <memory> | ||
#include <unordered_set> | ||
|
||
#include <util/make_unique.h> | ||
|
||
#include <goto-programs/goto_functions.h> | ||
|
||
// don't use me -- I am just a base class | ||
|
@@ -252,7 +255,7 @@ class static_analysis_baset | |
virtual void generate_state(locationt l)=0; | ||
virtual statet &get_state(locationt l)=0; | ||
virtual const statet &get_state(locationt l) const=0; | ||
virtual statet* make_temporary_state(statet &s)=0; | ||
virtual std::unique_ptr<statet> make_temporary_state(statet &s)=0; | ||
|
||
typedef domain_baset::expr_sett expr_sett; | ||
|
||
|
@@ -331,9 +334,9 @@ class static_analysist:public static_analysis_baset | |
return static_cast<T &>(a).merge(static_cast<const T &>(b), to); | ||
} | ||
|
||
virtual statet *make_temporary_state(statet &s) | ||
virtual std::unique_ptr<statet> make_temporary_state(statet &s) | ||
{ | ||
return new T(static_cast<T &>(s)); | ||
return util_make_unique<T>(static_cast<T &>(s)); | ||
} | ||
|
||
virtual void generate_state(locationt l) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,10 @@ Author: Daniel Kroening, [email protected] | |
|
||
/*! \defgroup gr_ansi_c ANSI-C front-end */ | ||
|
||
#include <memory> | ||
|
||
#include <util/language.h> | ||
#include <util/make_unique.h> | ||
|
||
#include "ansi_c_parse_tree.h" | ||
|
||
|
@@ -64,8 +67,8 @@ class ansi_c_languaget:public languaget | |
exprt &expr, | ||
const namespacet &ns) override; | ||
|
||
languaget *new_language() override | ||
{ return new ansi_c_languaget; } | ||
std::unique_ptr<languaget> new_language() override | ||
{ return util_make_unique<ansi_c_languaget>(); } | ||
|
||
std::string id() const override { return "C"; } | ||
std::string description() const override { return "ANSI-C 99"; } | ||
|
@@ -78,6 +81,6 @@ class ansi_c_languaget:public languaget | |
std::string parse_path; | ||
}; | ||
|
||
languaget *new_ansi_c_language(); | ||
std::unique_ptr<languaget> new_ansi_c_language(); | ||
|
||
#endif // CPROVER_ANSI_C_ANSI_C_LANGUAGE_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need
#include <memory>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
util/make_unique.h
itself includesmemory
. My preference would be to leave it as-is, and then if we change to C++14 we can find-and-replaceutil/make_unique -> memory
andutil_make_unique -> std::make_unique
.