-
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
Conversation
a159f00
to
42a2bf5
Compare
|
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.
I'm neither well versed enough in C++ memory types or the code in question to approve but I've spotted some inconsistencies in the changes so I've pointed them out
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected] | |||
#include <util/json.h> | |||
#include <util/xml.h> | |||
#include <util/expr.h> | |||
#include <util/make_unique.h> |
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 includes memory
. My preference would be to leave it as-is, and then if we change to C++14 we can find-and-replace util/make_unique -> memory
and util_make_unique -> std::make_unique
.
@@ -19,6 +19,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 comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need #include <memory>
src/analyses/goto_rw.h
Outdated
@@ -108,8 +109,8 @@ class rw_range_sett | |||
|
|||
const range_domaint &get_ranges(objectst::const_iterator it) const | |||
{ | |||
assert(dynamic_cast<range_domaint*>(it->second)!=0); | |||
return *static_cast<range_domaint*>(it->second); | |||
assert(dynamic_cast<range_domaint*>(it->second.get())); |
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.
While you're modifying the line, can this become INVARIANT
or possibly one of the others?
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.
I'm not against this, but wonder whether it should really be part of this PR.
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.
@reuk Yup you're right - it is already a big change
src/analyses/goto_rw.h
Outdated
@@ -277,8 +278,8 @@ class rw_guarded_range_set_value_sett:public rw_range_set_value_sett | |||
|
|||
const guarded_range_domaint &get_ranges(objectst::const_iterator it) const | |||
{ | |||
assert(dynamic_cast<guarded_range_domaint*>(it->second)!=0); | |||
return *static_cast<guarded_range_domaint*>(it->second); | |||
assert(dynamic_cast<guarded_range_domaint*>(it->second.get())!=nullptr); |
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.
While you're modifying the line, can this become INVARIANT or possibly one of the others?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a #include <memory>
src/cbmc/cbmc_solvers.cpp
Outdated
|
||
// We offer the option to disable the SAT preprocessor | ||
if(options.get_bool_option("sat-preprocessor")) | ||
auto prop=[this]() -> std::unique_ptr<propt> |
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.
Why is this a lambda?
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.
So that prop
can be directly initialised to its correct state rather than two-stage constructed-then-initialised. I think this is cleaner than
std::unique_ptr<propt> prop;
// We offer the option to disable the SAT preprocessor
if(options.get_bool_option("sat-preprocessor"))
{
no_beautification();
prop=util_make_unique<satcheckt>();
}
else
prop=util_make_unique<satcheck_no_simplifiert>();
...although there's not much in it, so if you'd prefer it like that then I'll change it.
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 have a strong preference - do have a strong preference that you drop the auto
if you do it this way, I assumed on first reading that prop
was a lambda
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.
Done
@@ -247,9 +247,9 @@ bool clobber_parse_optionst::get_goto_program( | |||
return true; | |||
} | |||
|
|||
languaget *language=get_language_from_filename(filename); | |||
auto language=get_language_from_filename(filename); |
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.
Type not on RHS so don't think this should be auto
|
||
if(language==NULL) | ||
if(language==nullptr) |
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.
if(!language)
to be consistent with earlier changes
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.
Well spotted :)
src/langapi/language_util.cpp
Outdated
|
||
if(ptr==NULL) | ||
if(ptr==nullptr) |
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.
if(!ptr)
to be consistent
src/langapi/language_util.cpp
Outdated
@@ -28,9 +28,9 @@ static languaget* get_language( | |||
symbol->mode=="") | |||
return get_default_language(); | |||
|
|||
languaget *ptr=get_language_from_mode(symbol->mode); | |||
auto ptr=get_language_from_mode(symbol->mode); |
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.
Type not on RHS so don't think this should be auto
|
Let's try to aggrevate for the master PR tomorrow in the interest of less merge chaff downstream |
Updated to include |
Should I apply the changes from this PR to the original one? |
src/util/freer.h
Outdated
@@ -12,7 +12,7 @@ Author: Reuben Thomas, [email protected] | |||
#include <cstdlib> | |||
#include <utility> | |||
|
|||
struct freert final | |||
struct freert | |||
{ | |||
template <typename T> | |||
void operator()(T &&t) const |
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.
You can still have final on member function.
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.
It's not a virtual method, therefore putting final on it causes a compiler error.
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.
Fine with me, I was not really a fan of putting final in there in the first place.
@reuk I suppose so (sorry for not reviewing the original one - that would have been more helpful) |
src/cbmc/cbmc_parse_options.cpp
Outdated
@@ -750,19 +750,17 @@ void cbmc_parse_optionst::preprocessing() | |||
return; | |||
} | |||
|
|||
languaget *ptr=get_language_from_filename(filename); | |||
std::unique_ptr<languaget> ptr=get_language_from_filename(filename); |
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.
I'd prefer calling it language
instead of ptr
src/util/unicode.cpp
Outdated
|
||
// the following never gets deleted | ||
const char **argv_narrow=new const char *[argc+1]; | ||
std::vector<const char *> argv_narrow(argc+1); | ||
argv_narrow[argc]=0; | ||
|
||
for(int i=0; i<argc; i++) |
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.
While the above fixes array leak, it still leaks elements.
Maybe change from char* to std::string or unique pointer would help.
Let's get #835 merged into master first. |
The same as #835 but targeting test-gen-support.