pyuno/source/loader/pyuno_loader.cxx |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

New commits:
commit 8a695046cfcc8f9ec835b208b0d56ca821a3ff84
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Wed Jan 17 14:21:26 2024 +0100
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Wed Jan 17 19:02:49 2024 +0100

    tdf#158375 Hack to make sure process service factory is set
    
    (TODO: A more clean fix would pass XComponentContext into the configuration
    wrapper.)
    
    Change-Id: I1936a4517877f30cc7a825ce1c94923b350f7173
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162198
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>

diff --git a/pyuno/source/loader/pyuno_loader.cxx 
b/pyuno/source/loader/pyuno_loader.cxx
index afdb016aa764..b02ad302fa80 100644
--- a/pyuno/source/loader/pyuno_loader.cxx
+++ b/pyuno/source/loader/pyuno_loader.cxx
@@ -34,8 +34,11 @@
 
 #include <cppuhelper/factory.hxx>
 
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/uno/DeploymentException.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
 
+#include <comphelper/processfactory.hxx>
 #include <officecfg/Office/Common.hxx>
 
 // apparently PATH_MAX is not standard and not defined by MSVC
@@ -244,6 +247,17 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
 pyuno_Loader_get_implementation(
     css::uno::XComponentContext* ctx , css::uno::Sequence<css::uno::Any> 
const&)
 {
+    //HACK: Reading the configuration via officecfg::... below internally 
needs the
+    // comphelper::getProcessServiceFactory(), which might not be set if this 
code is e.g. executed
+    // in a uno.bin process when installing a LibreOffice extension written in 
Python, so make sure
+    // the process service factory is set:
+    try {
+        comphelper::getProcessServiceFactory();
+    } catch (css::uno::DeploymentException const &) {
+        comphelper::setProcessServiceFactory(
+            css::uno::Reference<css::lang::XMultiServiceFactory>(
+                ctx->getServiceManager(), css::uno::UNO_QUERY_THROW));
+    }
     if 
(officecfg::Office::Common::Security::Scripting::DisablePythonRuntime::get())
         return nullptr;
 

Reply via email to