Replace owning raw pointers with unique_ptr#1029
Replace owning raw pointers with unique_ptr#1029reuk wants to merge 8 commits intodiffblue:test-gen-supportfrom
Conversation
a159f00 to
42a2bf5
Compare
|
thk123
left a comment
There was a problem hiding this comment.
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
| #include <util/json.h> | ||
| #include <util/xml.h> | ||
| #include <util/expr.h> | ||
| #include <util/make_unique.h> |
There was a problem hiding this comment.
Don't we need #include <memory>
There was a problem hiding this comment.
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.
| #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.
Don't we need #include <memory>
src/analyses/goto_rw.h
Outdated
| { | ||
| 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.
While you're modifying the line, can this become INVARIANT or possibly one of the others?
There was a problem hiding this comment.
I'm not against this, but wonder whether it should really be part of this PR.
There was a problem hiding this comment.
@reuk Yup you're right - it is already a big change
src/analyses/goto_rw.h
Outdated
| { | ||
| 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.
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.
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.
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.
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
| } | ||
|
|
||
| languaget *language=get_language_from_filename(filename); | ||
| auto language=get_language_from_filename(filename); |
There was a problem hiding this comment.
Type not on RHS so don't think this should be auto
| auto language=get_language_from_filename(filename); | ||
|
|
||
| if(language==NULL) | ||
| if(language==nullptr) |
There was a problem hiding this comment.
if(!language) to be consistent with earlier changes
src/langapi/language_util.cpp
Outdated
| auto ptr=get_language_from_mode(symbol->mode); | ||
|
|
||
| if(ptr==NULL) | ||
| if(ptr==nullptr) |
src/langapi/language_util.cpp
Outdated
| 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.
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? |
| struct freert | ||
| { | ||
| template <typename T> | ||
| void operator()(T &&t) const |
There was a problem hiding this comment.
You can still have final on member function.
There was a problem hiding this comment.
It's not a virtual method, therefore putting final on it causes a compiler error.
There was a problem hiding this comment.
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
| } | ||
|
|
||
| languaget *ptr=get_language_from_filename(filename); | ||
| std::unique_ptr<languaget> ptr=get_language_from_filename(filename); |
There was a problem hiding this comment.
I'd prefer calling it language instead of ptr
src/util/unicode.cpp
Outdated
| 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.
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.