Skip to content

Conversation

@reuk
Copy link
Contributor

@reuk reuk commented Jun 17, 2017

The same as #835 but targeting test-gen-support.

@reuk reuk force-pushed the no-raw-ptrs-tgs branch 5 times, most recently from a159f00 to 42a2bf5 Compare June 18, 2017 09:10
@reuk reuk force-pushed the no-raw-ptrs-tgs branch from 42a2bf5 to 513b705 Compare June 18, 2017 14:00
@smowton
Copy link
Contributor

smowton commented Jun 19, 2017

  1. Suggest whoever comes to merge this should instead merge in the corresponding master commit and then apply residual changes in the merge, such that the commit graph resembles the true situation and merge decisions are more likely to be taken automatically in the future

  2. Suggest unrelated virtual -> override changes be done in a different PR / commit

  3. I don't understand the purpose of std::forward in freert, could you explain?

Copy link
Contributor

@thk123 thk123 left a 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

#include <util/json.h>
#include <util/xml.h>
#include <util/expr.h>
#include <util/make_unique.h>
Copy link
Contributor

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>

Copy link
Contributor Author

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.

#include <util/endianness_map.h>
#include <util/arith_tools.h>
#include <util/simplify_expr.h>
#include <util/make_unique.h>
Copy link
Contributor

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>

{
assert(dynamic_cast<range_domaint*>(it->second)!=0);
return *static_cast<range_domaint*>(it->second);
assert(dynamic_cast<range_domaint*>(it->second.get()));
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

{
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);
Copy link
Contributor

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;
Copy link
Contributor

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>


// We offer the option to disable the SAT preprocessor
if(options.get_bool_option("sat-preprocessor"))
auto prop=[this]() -> std::unique_ptr<propt>
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

languaget *language=get_language_from_filename(filename);
auto language=get_language_from_filename(filename);
Copy link
Contributor

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

auto language=get_language_from_filename(filename);

if(language==NULL)
if(language==nullptr)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted :)

auto ptr=get_language_from_mode(symbol->mode);

if(ptr==NULL)
if(ptr==nullptr)
Copy link
Contributor

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

return get_default_language();

languaget *ptr=get_language_from_mode(symbol->mode);
auto ptr=get_language_from_mode(symbol->mode);
Copy link
Contributor

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

@reuk
Copy link
Contributor Author

reuk commented Jun 19, 2017

@smowton:

  1. Good idea, but that PR has been open two months and no-one is doing anything about it. This stuff is important, so the plan was to merge it into test-gen-support, which is normally quicker.
  2. Good point, removed from this PR.
  3. For wrappers like this which don't implement any semantic changes, I like to use forward so that the interface for the wrapper exactly matches the interface of the wrapped function.

@reuk reuk force-pushed the no-raw-ptrs-tgs branch from caee053 to 1a6249c Compare June 19, 2017 10:56
@smowton
Copy link
Contributor

smowton commented Jun 19, 2017

Let's try to aggrevate for the master PR tomorrow in the interest of less merge chaff downstream

@reuk
Copy link
Contributor Author

reuk commented Jun 19, 2017

Updated to include <memory> as requested.

@reuk
Copy link
Contributor Author

reuk commented Jun 20, 2017

Should I apply the changes from this PR to the original one?

struct freert
{
template <typename T>
void operator()(T &&t) const
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@thk123
Copy link
Contributor

thk123 commented Jun 20, 2017

@reuk I suppose so (sorry for not reviewing the original one - that would have been more helpful)

@reuk reuk mentioned this pull request Jun 20, 2017
}

languaget *ptr=get_language_from_filename(filename);
std::unique_ptr<languaget> ptr=get_language_from_filename(filename);
Copy link
Member

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

std::vector<const char *> argv_narrow(argc+1);
argv_narrow[argc]=0;

for(int i=0; i<argc; i++)
Copy link
Contributor

@janmroczkowski janmroczkowski Jun 21, 2017

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.

@reuk reuk force-pushed the no-raw-ptrs-tgs branch from 80f7b89 to 92e02b5 Compare June 21, 2017 13:06
@peterschrammel
Copy link
Member

peterschrammel commented Jun 25, 2017

Let's get #835 merged into master first.

@reuk reuk closed this Jul 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants