pyuno: create instances with uno constructors

See tdf#74608 for motivation.

Change-Id: I4bdc09b4ba5c2f7ecc4fc8184f2d8230896aef01
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98716
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2020-07-14 10:36:40 +02:00
parent cef5a2d780
commit 15b100506a
2 changed files with 9 additions and 37 deletions

View file

@ -18,8 +18,9 @@
-->
<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
prefix="pythonloader" xmlns="http://openoffice.org/2010/uno-components">
<implementation name="org.openoffice.comp.pyuno.Loader">
xmlns="http://openoffice.org/2010/uno-components">
<implementation name="org.openoffice.comp.pyuno.Loader"
constructor="pyuno_Loader_get_implementation">
<service name="com.sun.star.loader.Python"/>
</implementation>
</component>

View file

@ -106,16 +106,6 @@ static PyRef getObjectFromLoaderModule( const char * func )
return object;
}
static OUString getImplementationName()
{
return "org.openoffice.comp.pyuno.Loader";
}
static Sequence< OUString > getSupportedServiceNames()
{
return { "com.sun.star.loader.Python" };
}
static void setPythonHome ( const OUString & pythonHome )
{
OUString systemPythonHome;
@ -242,7 +232,9 @@ PythonInit() {
}
static Reference<XInterface> CreateInstance(const Reference<XComponentContext> & ctx)
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
pyuno_Loader_get_implementation(
css::uno::XComponentContext* ctx , css::uno::Sequence<css::uno::Any> const&)
{
// tdf#114815 thread-safe static to init python only once
static PythonInit s_Init;
@ -262,7 +254,7 @@ static Reference<XInterface> CreateInstance(const Reference<XComponentContext> &
Runtime runtime;
PyRef pyCtx = runtime.any2PyObject(
css::uno::makeAny( ctx ) );
css::uno::makeAny( css::uno::Reference(ctx) ) );
PyRef clazz = getObjectFromLoaderModule( "Loader" );
PyRef args ( PyTuple_New( 1 ), SAL_NO_ACQUIRE, NOT_NULL );
@ -270,29 +262,8 @@ static Reference<XInterface> CreateInstance(const Reference<XComponentContext> &
PyRef pyInstance( PyObject_CallObject( clazz.get() , args.get() ), SAL_NO_ACQUIRE );
runtime.pyObject2Any( pyInstance ) >>= ret;
}
return ret;
}
}
const struct cppu::ImplementationEntry g_entries[] =
{
{
pyuno_loader::CreateInstance, pyuno_loader::getImplementationName,
pyuno_loader::getSupportedServiceNames, cppu::createSingleComponentFactory,
nullptr , 0
},
{ nullptr, nullptr, nullptr, nullptr, nullptr, 0 }
};
extern "C"
{
SAL_DLLPUBLIC_EXPORT void * pythonloader_component_getFactory(
const char * pImplName, void * pServiceManager, void * pRegistryKey )
{
return cppu::component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries );
ret->acquire();
return ret.get();
}
}