From 32f24eabb25716e99e8b5bfa548640472cde6917 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 13 Aug 2016 23:16:05 -0400 Subject: [PATCH] Review uses of safenew... ... add comments and assertions, and use make_unique instead where possible --- src/MixerBoard.cpp | 1 + src/Project.cpp | 5 +++-- src/SplashDialog.cpp | 1 + src/TimerRecordDialog.cpp | 1 + src/effects/Effect.cpp | 2 +- src/toolbars/MeterToolBar.cpp | 1 + src/toolbars/ToolBar.cpp | 1 + src/toolbars/ToolBar.h | 1 + src/toolbars/ToolManager.cpp | 6 ++++++ src/widgets/BackedPanel.cpp | 4 ++-- src/widgets/ErrorDialog.cpp | 2 ++ src/widgets/HelpSystem.cpp | 3 +++ src/widgets/LinkingHtmlWindow.cpp | 2 +- 13 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/MixerBoard.cpp b/src/MixerBoard.cpp index aaf9986c5..216ba7a1f 100644 --- a/src/MixerBoard.cpp +++ b/src/MixerBoard.cpp @@ -934,6 +934,7 @@ MixerBoard::MixerBoard(AudacityProject* pProject, this->LoadMusicalInstruments(); // Set up mMusicalInstruments. mProject = pProject; + wxASSERT(pProject); // to justify safenew mScrolledWindow = safenew MixerBoardScrolledWindow( pProject, // AudacityProject* project, diff --git a/src/Project.cpp b/src/Project.cpp index 89c3332ad..208d9862f 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -169,7 +169,8 @@ scroll information. It also has some status flags. #include "../images/AudacityLogoAlpha.xpm" -std::unique_ptr AudacityProject::msClipboard{ safenew TrackList() }; +std::unique_ptr AudacityProject::msClipboard + { std::make_unique() }; double AudacityProject::msClipT0 = 0.0; double AudacityProject::msClipT1 = 0.0; AudacityProject *AudacityProject::msClipProject = NULL; @@ -829,7 +830,7 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id, mSelectionFormat(gPrefs->Read(wxT("/SelectionFormat"), wxT(""))), mFrequencySelectionFormatName(gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT(""))), mBandwidthSelectionFormatName(gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT(""))), - mUndoManager(safenew UndoManager), + mUndoManager(std::make_unique()), mViewInfo(0.0, 1.0, ZoomInfo::GetDefaultZoom()) { // Note that the first field of the status bar is a dummy, and it's width is set diff --git a/src/SplashDialog.cpp b/src/SplashDialog.cpp index 7c75692d0..9efe77d43 100644 --- a/src/SplashDialog.cpp +++ b/src/SplashDialog.cpp @@ -143,6 +143,7 @@ void SplashDialog::Show2( wxWindow * pParent ) if( pSelf == NULL ) { // pParent owns it + wxASSERT(pParent); pSelf = safenew SplashDialog( pParent ); } pSelf->mpHtml->SetPage(HelpText( wxT("welcome") )); diff --git a/src/TimerRecordDialog.cpp b/src/TimerRecordDialog.cpp index ceac1476c..81f91252b 100644 --- a/src/TimerRecordDialog.cpp +++ b/src/TimerRecordDialog.cpp @@ -778,6 +778,7 @@ TimerRecordPathCtrl * TimerRecordDialog::NewPathControl(wxWindow *wParent, const const wxString &sCaption, const wxString &sValue) { TimerRecordPathCtrl * pTextCtrl; + wxASSERT(wParent); // to justify safenew pTextCtrl = safenew TimerRecordPathCtrl(wParent, iID, sValue); pTextCtrl->SetName(sCaption); return pTextCtrl; diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index 39438add7..a476b9f51 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -2125,7 +2125,7 @@ Effect::AddedAnalysisTrack::~AddedAnalysisTrack() auto Effect::AddAnalysisTrack(const wxString &name) -> std::shared_ptr { return std::shared_ptr - { safenew AddedAnalysisTrack{ this, name } }; + { safenew AddedAnalysisTrack{ this, name } }; } Effect::ModifiedAnalysisTrack::ModifiedAnalysisTrack diff --git a/src/toolbars/MeterToolBar.cpp b/src/toolbars/MeterToolBar.cpp index 492fe4ee0..037733ce6 100644 --- a/src/toolbars/MeterToolBar.cpp +++ b/src/toolbars/MeterToolBar.cpp @@ -113,6 +113,7 @@ void MeterToolBar::ReCreateButtons() void MeterToolBar::Populate() { + wxASSERT(mProject); // to justify safenew Add((mSizer = safenew wxGridBagSizer()), 1, wxEXPAND); if( mWhichMeters & kWithRecordMeter ){ diff --git a/src/toolbars/ToolBar.cpp b/src/toolbars/ToolBar.cpp index a01c41ea7..1787260a5 100644 --- a/src/toolbars/ToolBar.cpp +++ b/src/toolbars/ToolBar.cpp @@ -758,6 +758,7 @@ AButton * ToolBar::MakeButton(wxWindow *parent, wxImagePtr down2 (OverlayImage(eDown, eStandardDown, xoff + 1, yoff + 1)); wxImagePtr disable2 (OverlayImage(eUp, eDisabled, xoff, yoff)); + wxASSERT(parent); // to justify safenew AButton * button = safenew AButton(parent, id, placement, size, *up2, *hilite2, *down2, *disable2, processdownevents); diff --git a/src/toolbars/ToolBar.h b/src/toolbars/ToolBar.h index 1c26e74e8..e92ce9ee2 100644 --- a/src/toolbars/ToolBar.h +++ b/src/toolbars/ToolBar.h @@ -181,6 +181,7 @@ class ToolBar /* not final */ : public wxPanelWrapper int border = 0, wxObject *userData = NULL); + // Takes ownership of sizer void Add(wxSizer *sizer, int proportion = 0, int flag = 0, diff --git a/src/toolbars/ToolManager.cpp b/src/toolbars/ToolManager.cpp index f33524160..cd050c643 100644 --- a/src/toolbars/ToolManager.cpp +++ b/src/toolbars/ToolManager.cpp @@ -363,6 +363,7 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent ) mLeft = std::make_unique( 3, &pt[0] ); // Create the indicator frame + // parent is null but FramePtr ensures destruction mIndicator = FramePtr{ safenew wxFrame( NULL, wxID_ANY, wxEmptyString, @@ -410,6 +411,8 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent ) mBotDock = safenew ToolDock( this, mParent, BotDockID ); // Create all of the toolbars + // All have the project as parent window + wxASSERT(parent); mBars[ ToolsBarID ] = ToolBar::Holder{ safenew ToolsToolBar() }; mBars[ TransportBarID ] = ToolBar::Holder{ safenew ControlToolBar() }; mBars[ RecordMeterBarID ] = ToolBar::Holder{ safenew MeterToolBar( parent, RecordMeterBarID ) }; @@ -583,6 +586,7 @@ void ToolManager::Reset() // Maybe construct a NEW floater // this happens if we have just been bounced out of a dock. if( floater == NULL ) { + wxASSERT(mParent); floater = safenew ToolFrame( mParent, this, bar, wxPoint(-1,-1) ); bar->Reparent( floater ); } @@ -761,6 +765,7 @@ void ToolManager::ReadConfig() bar->Create( mTopDock ); // Construct a NEW floater + wxASSERT(mParent); ToolFrame *f = safenew ToolFrame( mParent, this, bar, wxPoint( x, y ) ); // Set the width and height @@ -1327,6 +1332,7 @@ void ToolManager::OnGrabber( GrabberEvent & event ) mDragBar->SetPositioned(); // Construct a NEW floater + wxASSERT(mParent); mDragWindow = safenew ToolFrame( mParent, this, mDragBar, mp ); // Make sure the ferry is visible diff --git a/src/widgets/BackedPanel.cpp b/src/widgets/BackedPanel.cpp index 78148fe76..0f8357ee9 100644 --- a/src/widgets/BackedPanel.cpp +++ b/src/widgets/BackedPanel.cpp @@ -14,7 +14,7 @@ BackedPanel::BackedPanel(wxWindow * parent, wxWindowID id, const wxSize & size, long style) : wxPanelWrapper(parent, id, pos, size, style) -, mBacking{ safenew wxBitmap(1, 1) } +, mBacking{ std::make_unique(1, 1) } { // Preinit the backing DC and bitmap so routines that require it will // not cause a crash if they run before the panel is fully initialized. @@ -52,7 +52,7 @@ void BackedPanel::ResizeBacking() mBackingDC.SelectObject(wxNullBitmap); wxSize sz = GetClientSize(); - mBacking.reset(safenew wxBitmap); + mBacking = std::make_unique(); mBacking->Create(sz.x, sz.y); //, *dc); mBackingDC.SelectObject(*mBacking); } diff --git a/src/widgets/ErrorDialog.cpp b/src/widgets/ErrorDialog.cpp index 0cb633142..d7e3f48e9 100644 --- a/src/widgets/ErrorDialog.cpp +++ b/src/widgets/ErrorDialog.cpp @@ -184,6 +184,7 @@ void ShowModelessErrorDialog(wxWindow *parent, const wxString &helpURL, const bool Close) { + wxASSERT(parent); ErrorDialog *dlog = safenew ErrorDialog(parent, dlogTitle, message, helpURL, Close, false); dlog->CentreOnParent(); dlog->Show(); @@ -199,6 +200,7 @@ void ShowAliasMissingDialog(AudacityProject *parent, const wxString &helpURL, const bool Close) { + wxASSERT(parent); // to justify safenew ErrorDialog *dlog = safenew AliasedFileMissingDialog(parent, dlogTitle, message, helpURL, Close, false); // Don't center because in many cases (effect, export, etc) there will be a progress bar in the center that blocks this. // instead put it just above or on the top of the project. diff --git a/src/widgets/HelpSystem.cpp b/src/widgets/HelpSystem.cpp index 47fbe5b8f..60bfc16d9 100644 --- a/src/widgets/HelpSystem.cpp +++ b/src/widgets/HelpSystem.cpp @@ -100,6 +100,7 @@ void HelpSystem::ShowHtmlText(wxWindow *pParent, { LinkingHtmlWindow *html; + wxASSERT(pParent); // to justify safenew auto pFrame = safenew wxFrame { pParent, wxID_ANY, Title, wxDefaultPosition, wxDefaultSize, #if defined(__WXMAC__) @@ -195,6 +196,7 @@ void HelpSystem::ShowHelpDialog(wxWindow *parent, const wxString &remoteURL, bool bModal) { + wxASSERT(parent); // to justify safenew AudacityProject * pProj = GetActiveProject(); wxString HelpMode = wxT("Local"); @@ -341,6 +343,7 @@ void HelpSystem::ShowHelpDialog(wxWindow *parent, wxLogMessage(wxT("webHelpPage %s, localHelpPage %s"), webHelpPage.c_str(), localHelpPage.c_str()); + wxASSERT(parent); // to justify safenew HelpSystem::ShowHelpDialog( parent, localHelpPage, diff --git a/src/widgets/LinkingHtmlWindow.cpp b/src/widgets/LinkingHtmlWindow.cpp index ab674fb3c..2b8d7a53c 100644 --- a/src/widgets/LinkingHtmlWindow.cpp +++ b/src/widgets/LinkingHtmlWindow.cpp @@ -124,7 +124,7 @@ void LinkingHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) wxFileName( FileNames::HtmlHelpDir(), href.Mid( 10 ) + wxT(".htm") ).GetFullPath(); if( wxFileExists( FileName ) ) { - HelpSystem::ShowHelpDialog(NULL, FileName, wxT("")); + HelpSystem::ShowHelpDialog(this, FileName, wxT("")); return; } else