[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - compilerplugins/clang vcl/source

Jan Holesovsky kendy at collabora.com
Thu Jan 18 07:27:57 UTC 2018


 compilerplugins/clang/badstatics.cxx |    1 
 vcl/source/window/window.cxx         |   37 +++++++++++++++++++++++++----------
 2 files changed, 28 insertions(+), 10 deletions(-)

New commits:
commit bfbed0f9c4ab52e770ef8b37e6a6328991cd0c6b
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Nov 29 14:19:54 2017 +0100

    lokdialog: Make the badstatic loplugin happy.
    
    Change-Id: Ic19bbd2a3533e4e600d8856e55c4e8d06f0ad752
    Reviewed-on: https://gerrit.libreoffice.org/45500
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    (cherry picked from commit 8ce967ad157d83ad567c5f8c750f4225dd974219)
    Reviewed-on: https://gerrit.libreoffice.org/48088
    Reviewed-by: pranavk <pranavk at collabora.co.uk>
    Tested-by: pranavk <pranavk at collabora.co.uk>

diff --git a/compilerplugins/clang/badstatics.cxx b/compilerplugins/clang/badstatics.cxx
index e551d6be5c5b..5f2d15e9e20d 100644
--- a/compilerplugins/clang/badstatics.cxx
+++ b/compilerplugins/clang/badstatics.cxx
@@ -200,6 +200,7 @@ public:
                 || name == "m_aUncommitedRegistrations" // sw/source/uibase/dbui/dbmgr.cxx
                 || (loplugin::DeclCheck(pVarDecl).Var("aAllListeners")
                     .Class("ScAddInListener").GlobalNamespace()) // not owning
+                || name == "s_pLOKWindowsMap" // LOK only, guarded by assert, and LOK never tries to perform a VCL cleanup
                ) // these variables appear unproblematic
             {
                 return true;
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 430dbe3ac2cf..f0ab681f421f 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -85,12 +85,6 @@ using namespace ::com::sun::star::datatransfer::dnd;
 
 namespace vcl {
 
-/// Counter to be able to have unique id's for each window.
-static vcl::LOKWindowId sLastLOKWindowId = 1;
-
-/// Map to remember the LOKWindowId <-> Window binding.
-static std::map<vcl::LOKWindowId, VclPtr<vcl::Window>> sLOKWindows;
-
 Window::Window( WindowType nType ) :
     mpWindowImpl(new WindowImpl( nType ))
 {
@@ -3200,24 +3194,47 @@ void Window::SetComponentInterface( Reference< css::awt::XWindowPeer > const & x
         pWrapper->SetWindowInterface( this, xIFace );
 }
 
+typedef std::map<vcl::LOKWindowId, VclPtr<vcl::Window>> LOKWindowsMap;
+
+namespace {
+
+LOKWindowsMap& GetLOKWindowsMap()
+{
+    // never use this in the desktop case
+    assert(comphelper::LibreOfficeKit::isActive());
+
+    // Map to remember the LOKWindowId <-> Window binding.
+    static std::unique_ptr<LOKWindowsMap> s_pLOKWindowsMap;
+
+    if (!s_pLOKWindowsMap)
+        s_pLOKWindowsMap.reset(new LOKWindowsMap);
+
+    return *s_pLOKWindowsMap.get();
+}
+
+}
+
 void Window::SetLOKNotifier(const vcl::ILibreOfficeKitNotifier* pNotifier)
 {
     // don't allow setting this twice
     assert(mpWindowImpl->mpLOKNotifier == nullptr);
     assert(pNotifier);
 
+    // Counter to be able to have unique id's for each window.
+    static vcl::LOKWindowId sLastLOKWindowId = 1;
+
     // assign the LOK window id
     assert(mpWindowImpl->mnLOKWindowId == 0);
     mpWindowImpl->mnLOKWindowId = sLastLOKWindowId++;
-    sLOKWindows.insert(std::map<vcl::LOKWindowId, VclPtr<vcl::Window>>::value_type(mpWindowImpl->mnLOKWindowId, this));
+    GetLOKWindowsMap().insert(std::map<vcl::LOKWindowId, VclPtr<vcl::Window>>::value_type(mpWindowImpl->mnLOKWindowId, this));
 
     mpWindowImpl->mpLOKNotifier = pNotifier;
 }
 
 VclPtr<Window> Window::FindLOKWindow(vcl::LOKWindowId nWindowId)
 {
-    const auto it = sLOKWindows.find(nWindowId);
-    if (it != sLOKWindows.end())
+    const auto it = GetLOKWindowsMap().find(nWindowId);
+    if (it != GetLOKWindowsMap().end())
         return it->second;
 
     return VclPtr<Window>();
@@ -3227,7 +3244,7 @@ void Window::ReleaseLOKNotifier()
 {
     // unregister the LOK window binding
     if (mpWindowImpl->mnLOKWindowId > 0)
-        sLOKWindows.erase(mpWindowImpl->mnLOKWindowId);
+        GetLOKWindowsMap().erase(mpWindowImpl->mnLOKWindowId);
 
     mpWindowImpl->mpLOKNotifier = nullptr;
     mpWindowImpl->mnLOKWindowId = 0;


More information about the Libreoffice-commits mailing list