vcl/source/window/builder.cxx |   48 +++++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 19 deletions(-)

New commits:
commit 3a9bb39c7b667e59e1a063feff415845726209ea
Author: Mike Kaganski <mike.kagan...@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.me...@collabora.com>
    Tested-by: Michael Meeks <michael.me...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/52453

diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 35991601bc64..a5b8764cd740 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -1129,26 +1129,30 @@ void VclBuilder::cleanupWidgetOwnScrolling(vcl::Window 
*pScrollParent, vcl::Wind
 
 #ifndef DISABLE_DYNLOADING
 extern "C" { static void SAL_CALL 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[] = {
@@ -1171,6 +1175,7 @@ void VclBuilder::preload()
         else
             delete pModule;
     }
+#endif // ENABLE_MERGELIBS
 #endif // DISABLE_DYNLOADING
 }
 
@@ -1656,13 +1661,12 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window 
*pParent, const OString &
     }
     else
     {
-#ifndef SAL_DLLPREFIX
-#define SAL_DLLPREFIX ""
-#endif
         sal_Int32 nDelim = name.indexOf('-');
         if (nDelim != -1)
         {
             OUString sFunction(OStringToOUString(OString("make") + 
name.copy(nDelim+1), RTL_TEXTENCODING_UTF8));
+
+            customMakeWidget pFunction = nullptr;
 #ifndef DISABLE_DYNLOADING
             OUStringBuffer sModuleBuf;
             sModuleBuf.append(SAL_DLLPREFIX);
@@ -1673,21 +1677,27 @@ 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");
+                    (void) ok;
+                    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)
             {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to