-
Notifications
You must be signed in to change notification settings - Fork 14
Fix memory leak, and many lint warning. #602
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
base: main
Are you sure you want to change the base?
Conversation
6e3c7d5 to
e790495
Compare
angela28chen
left a comment
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.
Thanks for making this effort to make Dive ui code use "new" in a more intentioned way
src/dive/ui/forward.h
Outdated
|
|
||
| // Forward declarations for UI. | ||
|
|
||
| class OverlayHelper; |
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.
this seems repeated (line 74)
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.
Eh, I probably selected the wrong range when running sort+deduplicate in the editor.
| return ptr; // NOLINT | ||
| } | ||
|
|
||
| // Create a new Qt object. |
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 like the examples section for how to create new layouts using LayoutHelper. Can we have a similar brief example section for QtNew and QtNewUnowned?
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.
They are just new with static_assert.
Will add a bit more document.
| #include "ui/overlay.h" | ||
| #include "ui/settings.h" | ||
|
|
||
| using DiveLint::QtNew; |
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.
Is there any downside to avoiding "using" and just calling the full DiveLint::QtNew() when using this or is it just wordy? I slightly prefer the wordy version since I think it makes it clearer that QtNew() isn't something defined by Qt despite the prefix
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.
Though I guess it might be confusing to see the word "Lint" in there. Could it not just be Dive::QtNew() or DiveQt::QtNew or something?
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.
Those are annotations, and more specifically lint annotations. They don't do anything other than doing additional lint checks.
Also regarding to using alias https://google.github.io/styleguide/cppguide.html#Aliases
Had a bit offline chat earlier with @footballhead , instead of disable lint check for pointer ownership, it seems sensible to explicitly annotate allocations. |
src/dive/lint/gsl.h
Outdated
| namespace gsl | ||
| { | ||
|
|
||
| template<class T, std::enable_if_t<std::is_pointer_v<T>, bool> = true> // |
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 the trailing //?
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.
We probably wan to remove clang-format rule AlwaysBreakTemplateDeclarations: MultiLine
| - "-cppcoreguidelines-avoid-non-const-global-variables" # ABSL_FLAG | ||
| - "-cppcoreguidelines-use-enum-class" | ||
| - "-readability-redundant-access-specifiers" # qt | ||
| - "-cppcoreguidelines-pro-bounds-avoid-unchecked-container-access" # https://abseil.io/tips/224 |
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.
+1 love adding the justification in the comment
| using DiveLint::QtNew; | ||
| using DiveLint::QtNewUnowned; |
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.
nit, likely not an issue here since the using isn't inside the namespace but (in general) prefer to fully qualify https://abseil.io/tips/119
| using DiveLint::QtNew; | |
| using DiveLint::QtNewUnowned; | |
| using ::DiveLint::QtNew; | |
| using ::DiveLint::QtNewUnowned; |
(https://abseil.io/tips/119 also recommends putting this in a namespace but I can see that there isn't one here :)
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.
| m_available_metrics(available_metrics) | ||
| { | ||
| qDebug() << "AnalyzeDialog created."; | ||
| InitializeLayout(); |
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.
Is it worth documenting somewhere that this is called from the constructor so should not be made virtual?
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 should be a factory function
auto Create() {
auto dialog = new AnalyzeDialog;
if (!AnalyzeDialog->InitializeLayout()) { delete dialog; return nullptr; }
return dialog;
}however the rest of the code are not capable of handling creation failure at the moment.
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.
Until that happens, document that this is called from the constructor so should not be made virtual?
|
|
||
| // Left Panel Layout | ||
| m_left_panel_layout = new QVBoxLayout(); | ||
| m_left_panel_layout = QtNewUnowned<QVBoxLayout>(); |
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.
Should we look at using the layout helper here as well?
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.
Yes. Although that's a lot of reordering probably fitted for the next PR.
I intentionally did not add AddWidget and AddLayout since they encourage having unparented elements.
a3afd32 to
a73af62
Compare
src/dive/ui/layout_helper.h
Outdated
| // auto* label = layout.New<QLabel>(tr("text")); | ||
| // | ||
| // Add a new item to an existing layout: | ||
| // auto* label = NewWidgetLayout{layout}.New<QLabel>(tr("text")); |
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.
nit: since NewWidgetLayout is a funtion call, should the {} be () instead?
| // auto* label = NewWidgetLayout{layout}.New<QLabel>(tr("text")); | |
| // auto* label = NewWidgetLayout(layout).New<QLabel>(tr("text")); |
| m_available_metrics(available_metrics) | ||
| { | ||
| qDebug() << "AnalyzeDialog created."; | ||
| InitializeLayout(); |
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.
Until that happens, document that this is called from the constructor so should not be made virtual?
6b4fffe to
c4ca939
Compare
4920263 to
ffcb8a7
Compare
- Created a tiny Guidelines Support Library - Add some helper function to make sure we do qt ownership correctly.
Fix two memory leak, and many lint warning.