include/vcl/weld.hxx | 5 ++++- sc/source/ui/miscdlgs/solvrdlg.cxx | 2 +- vcl/source/app/salvtables.cxx | 7 +++++-- vcl/unx/gtk3/gtk3gtkinst.cxx | 11 +++++++---- 4 files changed, 17 insertions(+), 8 deletions(-)
New commits: commit b358bb95c04772a6ff00d7fcbb6fbef9d3dca13c Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Fri May 24 14:40:56 2019 +0200 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Fri May 24 16:09:56 2019 +0200 cannot create a shared_ptr from an existing object so pass in the shared_ptr we already have (and enforce that we pass in the right one) Change-Id: Ic481b5ec17c34ed9cba50586dedb6184505dee24 Reviewed-on: https://gerrit.libreoffice.org/72908 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 71214ada80cf..af7271037a3b 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -403,7 +403,10 @@ private: public: virtual int run() = 0; // Run async without a controller - virtual bool runAsync(const std::function<void(sal_Int32)>& func) = 0; + // @param self - must point to this, to enforce that the dialog was created/held by a shared_ptr + virtual bool runAsync(std::shared_ptr<Dialog> const& rxSelf, + const std::function<void(sal_Int32)>& func) + = 0; virtual void response(int response) = 0; virtual void add_button(const OUString& rText, int response, const OString& rHelpId = OString()) = 0; diff --git a/sc/source/ui/miscdlgs/solvrdlg.cxx b/sc/source/ui/miscdlgs/solvrdlg.cxx index 551e781cbf8a..25a36c30941d 100644 --- a/sc/source/ui/miscdlgs/solvrdlg.cxx +++ b/sc/source/ui/miscdlgs/solvrdlg.cxx @@ -38,7 +38,7 @@ namespace std::shared_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent, VclMessageType::Warning, VclButtonsType::Ok, rString)); - xBox->runAsync(func); + xBox->runAsync(xBox, func); } } diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 5c75d2f369a2..e68e3818dcbc 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -1199,10 +1199,13 @@ public: return m_xDialog->StartExecuteAsync(aCtx); } - virtual bool runAsync(const std::function<void(sal_Int32)> &rEndDialogFn) override + virtual bool runAsync(std::shared_ptr<Dialog> const & rxSelf, const std::function<void(sal_Int32)> &rEndDialogFn) override { + assert( rxSelf.get() == this ); VclAbstractDialog::AsyncContext aCtx; - aCtx.mxOwnerSelf.reset(this); + // In order to store a shared_ptr to ourself, we have to have been constructed by make_shared, + // which is that rxSelf enforces. + aCtx.mxOwnerSelf = rxSelf; aCtx.maEndDialogFn = rEndDialogFn; return m_xDialog->StartExecuteAsync(aCtx); } diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 39581793b406..263577731bdc 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -3004,7 +3004,7 @@ private: DialogRunner m_aDialogRun; std::shared_ptr<weld::DialogController> m_xDialogController; // Used to keep ourself alive during a runAsync(when doing runAsync without a DialogController) - std::shared_ptr<GtkInstanceDialog> m_xRunAsyncSelf; + std::shared_ptr<weld::Dialog> m_xRunAsyncSelf; std::function<void(sal_Int32)> m_aFunc; gulong m_nCloseSignalId; gulong m_nResponseSignalId; @@ -3088,11 +3088,14 @@ public: return true; } - virtual bool runAsync(const std::function<void(sal_Int32)>& func) override + virtual bool runAsync(std::shared_ptr<Dialog> const & rxSelf, const std::function<void(sal_Int32)>& func) override { + assert( rxSelf.get() == this ); assert(!m_nResponseSignalId); - m_xRunAsyncSelf.reset(this); + // In order to store a shared_ptr to ourself, we have to have been constructed by make_shared, + // which is that rxSelf enforces. + m_xRunAsyncSelf = rxSelf; m_aFunc = func; show(); @@ -4630,7 +4633,7 @@ void GtkInstanceDialog::asyncresponse(gint ret) m_aFunc(GtkToVcl(ret)); m_aFunc = nullptr; // move the self pointer, otherwise it might be de-allocated by time we try to reset it - std::shared_ptr<GtkInstanceDialog> me = std::move(m_xRunAsyncSelf); + std::shared_ptr<weld::Dialog> me = std::move(m_xRunAsyncSelf); m_xDialogController.reset(); me.reset(); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits