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

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Fri Mar 29 12:02:05 UTC 2019


 cppuhelper/source/servicemanager.cxx |  176 +++++++++++++++++------------------
 1 file changed, 86 insertions(+), 90 deletions(-)

New commits:
commit 799aef2bf37ba4e23d3a837be49e354624b7083d
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri Mar 29 09:51:39 2019 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Mar 29 13:01:40 2019 +0100

    preload: cleanup disabled messages and simplify flow.
    
    Change-Id: I249b81afe5ec2fab5e0aaf73a2cde62173fa803e
    Reviewed-on: https://gerrit.libreoffice.org/69912
    Tested-by: Jenkins
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx
index 93a060e21fa4..2118bcb00c88 100644
--- a/cppuhelper/source/servicemanager.cxx
+++ b/cppuhelper/source/servicemanager.cxx
@@ -1790,7 +1790,7 @@ void cppuhelper::ServiceManager::preloadImplementations() {
     std::cerr << "preload:";
     std::vector<OUString> aReported;
     std::vector<OUString> aDisabled;
-    OUStringBuffer aDisabledMsg("Disabled: ");
+    OUStringBuffer aDisabledMsg;
 
     /// Allow external callers & testers to disable certain components
     const char *pDisable = getenv("UNODISABLELIBRARY");
@@ -1809,6 +1809,10 @@ void cppuhelper::ServiceManager::preloadImplementations() {
     // loop all implementations
     for (const auto& rEntry : data_.namedImplementations)
     {
+        if (rEntry.second->info->loader != "com.sun.star.loader.SharedLibrary" ||
+            rEntry.second->status == Data::Implementation::STATUS_LOADED)
+            continue;
+
         try
         {
             const OUString &aLibrary = rEntry.second->info->uri;
@@ -1848,118 +1852,110 @@ void cppuhelper::ServiceManager::preloadImplementations() {
                 static_cast< cppu::OWeakObject * >(this));
         }
 
-        if (rEntry.second->info->loader == "com.sun.star.loader.SharedLibrary" &&
-            rEntry.second->status != Data::Implementation::STATUS_LOADED)
+        // load component library
+        osl::Module aModule(aUri, SAL_LOADMODULE_NOW | SAL_LOADMODULE_GLOBAL);
+
+        if (!aModule.is())
         {
-            // load component library
-            osl::Module aModule(aUri, SAL_LOADMODULE_NOW | SAL_LOADMODULE_GLOBAL);
+            std::cerr << ":failed" << std::endl;
+            std::cerr.flush();
+        }
 
-            if (!aModule.is())
-            {
-                std::cerr << ":failed" << std::endl;
-                std::cerr.flush();
-            }
+        if (aModule.is() &&
+            !rEntry.second->info->environment.isEmpty())
+        {
+            OUString aSymFactory;
+            oslGenericFunction fpFactory;
+            css::uno::Environment aTargetEnv;
+            css::uno::Reference<css::uno::XInterface> xFactory;
 
-            if (aModule.is() &&
-                !rEntry.second->info->environment.isEmpty())
+            if(rEntry.second->info->constructor.isEmpty())
             {
-                OUString aSymFactory;
-                oslGenericFunction fpFactory;
-                css::uno::Environment aTargetEnv;
-                css::uno::Reference<css::uno::XInterface> xFactory;
+                // expand full name component factory symbol
+                if (rEntry.second->info->prefix == "direct")
+                    aSymFactory = rEntry.second->info->name.replace('.', '_') + "_" COMPONENT_GETFACTORY;
+                else if (!rEntry.second->info->prefix.isEmpty())
+                    aSymFactory = rEntry.second->info->prefix + "_" COMPONENT_GETFACTORY;
+                else
+                    aSymFactory = COMPONENT_GETFACTORY;
 
-                if(rEntry.second->info->constructor.isEmpty())
+                // get function symbol component factory
+                fpFactory = aModule.getFunctionSymbol(aSymFactory);
+                if (fpFactory == nullptr)
                 {
-                    // expand full name component factory symbol
-                    if (rEntry.second->info->prefix == "direct")
-                        aSymFactory = rEntry.second->info->name.replace('.', '_') + "_" COMPONENT_GETFACTORY;
-                    else if (!rEntry.second->info->prefix.isEmpty())
-                        aSymFactory = rEntry.second->info->prefix + "_" COMPONENT_GETFACTORY;
-                    else
-                        aSymFactory = COMPONENT_GETFACTORY;
-
-                    // get function symbol component factory
-                    fpFactory = aModule.getFunctionSymbol(aSymFactory);
-                    if (fpFactory == nullptr)
-                    {
-                        throw css::loader::CannotActivateFactoryException(
-                            ("no factory symbol \"" + aSymFactory + "\" in component library :" + aUri),
-                            css::uno::Reference<css::uno::XInterface>());
-                    }
-
-                    aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info->environment, rEntry.second->info->name);
-                    component_getFactoryFunc fpComponentFactory = reinterpret_cast<component_getFactoryFunc>(fpFactory);
-
-                    if (aSourceEnv.get() == aTargetEnv.get())
-                    {
-                        // invoke function component factory
-                        OString aImpl(OUStringToOString(rEntry.second->info->name, RTL_TEXTENCODING_ASCII_US));
-                        xFactory.set(css::uno::Reference<css::uno::XInterface>(static_cast<css::uno::XInterface *>(
-                            (*fpComponentFactory)(aImpl.getStr(), this, nullptr)), SAL_NO_ACQUIRE));
-                    }
+                    throw css::loader::CannotActivateFactoryException(
+                        ("no factory symbol \"" + aSymFactory + "\" in component library :" + aUri),
+                        css::uno::Reference<css::uno::XInterface>());
                 }
-                else
+
+                aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info->environment, rEntry.second->info->name);
+                component_getFactoryFunc fpComponentFactory = reinterpret_cast<component_getFactoryFunc>(fpFactory);
+
+                if (aSourceEnv.get() == aTargetEnv.get())
                 {
-                    // get function symbol component factory
-                    aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info->environment, rEntry.second->info->name);
-                    if (aSourceEnv.get() == aTargetEnv.get())
-                    {
-                        fpFactory = aModule.getFunctionSymbol(rEntry.second->info->constructor);
-                    }
-                    else
-                    {
-                        fpFactory = nullptr;
-                    }
+                    // invoke function component factory
+                    OString aImpl(OUStringToOString(rEntry.second->info->name, RTL_TEXTENCODING_ASCII_US));
+                    xFactory.set(css::uno::Reference<css::uno::XInterface>(static_cast<css::uno::XInterface *>(
+                        (*fpComponentFactory)(aImpl.getStr(), this, nullptr)), SAL_NO_ACQUIRE));
                 }
+            }
+            else
+            {
+                // get function symbol component factory
+                aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info->environment, rEntry.second->info->name);
+                fpFactory = (aSourceEnv.get() == aTargetEnv.get()) ?
+                    aModule.getFunctionSymbol(rEntry.second->info->constructor) : nullptr;
+            }
 
-                css::uno::Reference<css::lang::XSingleComponentFactory> xSCFactory;
-                css::uno::Reference<css::lang::XSingleServiceFactory> xSSFactory;
+            css::uno::Reference<css::lang::XSingleComponentFactory> xSCFactory;
+            css::uno::Reference<css::lang::XSingleServiceFactory> xSSFactory;
 
-                // query interface XSingleComponentFactory or XSingleServiceFactory
-                if (xFactory.is())
+            // query interface XSingleComponentFactory or XSingleServiceFactory
+            if (xFactory.is())
+            {
+                xSCFactory.set(xFactory, css::uno::UNO_QUERY);
+                if (!xSCFactory.is())
                 {
-                    xSCFactory.set(xFactory, css::uno::UNO_QUERY);
-                    if (!xSCFactory.is())
-                    {
-                        xSSFactory.set(xFactory, css::uno::UNO_QUERY);
-                        if (!xSSFactory.is())
-                        {
-                            throw css::uno::DeploymentException(
-                                ("Implementation " + rEntry.second->info->name
-                                  + " does not provide a constructor or factory"),
-                                static_cast< cppu::OWeakObject * >(this));
-                        }
-                    }
+                    xSSFactory.set(xFactory, css::uno::UNO_QUERY);
+                    if (!xSSFactory.is())
+                        throw css::uno::DeploymentException(
+                            ("Implementation " + rEntry.second->info->name
+                             + " does not provide a constructor or factory"),
+                            static_cast< cppu::OWeakObject * >(this));
                 }
+            }
 
-                if (!rEntry.second->info->constructor.isEmpty() && fpFactory)
-                    rEntry.second->constructor = WrapperConstructorFn(reinterpret_cast<ImplementationConstructorFn *>(fpFactory));
+            if (!rEntry.second->info->constructor.isEmpty() && fpFactory)
+                rEntry.second->constructor = WrapperConstructorFn(reinterpret_cast<ImplementationConstructorFn *>(fpFactory));
 
-                rEntry.second->factory1 = xSCFactory;
-                rEntry.second->factory2 = xSSFactory;
-                rEntry.second->status = Data::Implementation::STATUS_LOADED;
+            rEntry.second->factory1 = xSCFactory;
+            rEntry.second->factory2 = xSSFactory;
+            rEntry.second->status = Data::Implementation::STATUS_LOADED;
 
-            }
+        }
 
-            // Some libraries use other (non-UNO) libraries requiring preinit
-            oslGenericFunction fpPreload = aModule.getFunctionSymbol( "lok_preload_hook" );
-            if (fpPreload)
+        // Some libraries use other (non-UNO) libraries requiring preinit
+        oslGenericFunction fpPreload = aModule.getFunctionSymbol( "lok_preload_hook" );
+        if (fpPreload)
+        {
+            static std::vector<oslGenericFunction> aPreloaded;
+            if (std::find(aPreloaded.begin(), aPreloaded.end(), fpPreload) == aPreloaded.end())
             {
-                static std::vector<oslGenericFunction> aPreloaded;
-                if (std::find(aPreloaded.begin(), aPreloaded.end(), fpPreload) == aPreloaded.end())
-                {
-                    aPreloaded.push_back(fpPreload);
-                    fpPreload();
-                }
+                aPreloaded.push_back(fpPreload);
+                fpPreload();
             }
-
-            // leak aModule
-            aModule.release();
         }
+
+        // leak aModule
+        aModule.release();
     }
     std::cerr << std::endl;
 
-    std::cerr << aDisabledMsg.makeStringAndClear() << "\n";
+    if (aDisabledMsg.getLength() > 0)
+    {
+        OUString aMsg = aDisabledMsg.makeStringAndClear();
+        std::cerr << "Disabled: " << aMsg << "\n";
+    }
     std::cerr.flush();
 
     // Various rather important uno mappings.


More information about the Libreoffice-commits mailing list