[Libreoffice-commits] core.git: vcl/source

Mike Kaganski mike.kaganski at collabora.com
Thu Apr 5 09:08:12 UTC 2018


 vcl/source/window/builder.cxx |   44 ++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)

New commits:
commit b3ab7292931fe8fb0411b667de31c68988ce3c94
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Thu Apr 5 08:14:23 2018 +0100

    If the function is in mergelib, store mergelib module
    
    Regression from commit 707f787cd991f9c59712cd3020d127d09605c792
    It didn't ensure that we store mergelib when required, thus still
    trying to get function from stubs and failing (with mergelibs
    enabled), leading to SEGFAULT later.
    
    Change-Id: Ib15528795f3d65b1ae5c31be2aa5284ce5ff04cf
    Reviewed-on: https://gerrit.libreoffice.org/52428
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index cc1bff6fc4c9..926549db5302 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -1223,27 +1223,32 @@ void VclBuilder::cleanupWidgetOwnScrolling(vcl::Window *pScrollParent, vcl::Wind
 }
 
 #ifndef DISABLE_DYNLOADING
+
 extern "C" { static void thisModule() {} }
-#endif
 
 // We store these forever, closing modules is non-ideal from a performance
 // perspective, code pages will be freed up by the OS anyway if unused for
 // a while in many cases, and this helps us pre-init.
-typedef std::map<OUString, std::unique_ptr<osl::Module>> ModuleMap;
+typedef std::map<OUString, std::shared_ptr<osl::Module>> ModuleMap;
 static ModuleMap g_aModuleMap;
-static osl::Module g_aMergedLib;
+
+#if ENABLE_MERGELIBS
+static std::shared_ptr<osl::Module> g_pMergedLib = std::make_shared<osl::Module>();
+#endif
 
 #ifndef SAL_DLLPREFIX
 #  define SAL_DLLPREFIX ""
 #endif
 
+#endif
+
 void VclBuilder::preload()
 {
 #ifndef DISABLE_DYNLOADING
 
 #if ENABLE_MERGELIBS
-    g_aMergedLib.loadRelative(&thisModule, SVLIBRARY("merged"));
-#endif
+    g_pMergedLib->loadRelative(&thisModule, SVLIBRARY("merged"));
+#else
 // find -name '*ui*' | xargs grep 'class=".*lo-' |
 //     sed 's/.*class="//' | sed 's/-.*$//' | sort | uniq
     static const char *aWidgetLibs[] = {
@@ -1266,6 +1271,7 @@ void VclBuilder::preload()
         else
             delete pModule;
     }
+#endif // ENABLE_MERGELIBS
 #endif // DISABLE_DYNLOADING
 }
 
@@ -1768,6 +1774,7 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OString &
         {
             OUString sFunction(OStringToOUString(OString("make") + name.copy(nDelim+1), RTL_TEXTENCODING_UTF8));
 
+            customMakeWidget pFunction = nullptr;
 #ifndef DISABLE_DYNLOADING
             OUStringBuffer sModuleBuf;
             sModuleBuf.append(SAL_DLLPREFIX);
@@ -1778,21 +1785,26 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OString &
             ModuleMap::iterator aI = g_aModuleMap.find(sModule);
             if (aI == g_aModuleMap.end())
             {
-                osl::Module* pModule = new osl::Module;
-                bool ok = false;
+                std::shared_ptr<osl::Module> pModule;
 #if ENABLE_MERGELIBS
-                if (!g_aMergedLib.is())
-                    g_aMergedLib.loadRelative(&thisModule, SVLIBRARY("merged"));
-                ok = g_aMergedLib.getFunctionSymbol(sFunction);
+                if (!g_pMergedLib->is())
+                    g_pMergedLib->loadRelative(&thisModule, SVLIBRARY("merged"));
+                if ((pFunction = reinterpret_cast<customMakeWidget>(g_pMergedLib->getFunctionSymbol(sFunction))))
+                    pModule = g_pMergedLib;
 #endif
-                if (!ok)
-                    ok = pModule->loadRelative(&thisModule, sModule);
-                assert(ok && "bad module name in .ui");
-                aI = g_aModuleMap.insert(std::make_pair(sModule, std::unique_ptr<osl::Module>(pModule))).first;
+                if (!pFunction)
+                {
+                    pModule.reset(new osl::Module);
+                    bool ok = pModule->loadRelative(&thisModule, sModule);
+                    assert(ok && "bad module name in .ui");
+                    pFunction = reinterpret_cast<customMakeWidget>(pModule->getFunctionSymbol(sFunction));
+                }
+                g_aModuleMap.insert(std::make_pair(sModule, pModule));
             }
-            customMakeWidget pFunction = reinterpret_cast<customMakeWidget>(aI->second->getFunctionSymbol(sFunction));
+            else
+                pFunction = reinterpret_cast<customMakeWidget>(aI->second->getFunctionSymbol(sFunction));
 #else
-            customMakeWidget pFunction = reinterpret_cast<customMakeWidget>(osl_getFunctionSymbol((oslModule) RTLD_DEFAULT, sFunction.pData));
+            pFunction = reinterpret_cast<customMakeWidget>(osl_getFunctionSymbol((oslModule) RTLD_DEFAULT, sFunction.pData));
 #endif
             if (pFunction)
             {


More information about the Libreoffice-commits mailing list