tdf#173114 pyuno: Don’t require XInvocation2
If an object implements XInvocation then the Invocation service will directly return the object instead of creating its own invocation wrapper. In that case the object isn’t guaranteed to also implement XInvocation2. Previously, this was making pyuno just throw an exception whenever it encounters one of these objects. The only case where XInvocation2 is actually used is the implementation of the __dir__ method. I don’t think this method is used very often so it’s probably OK to just make it return an empty list if XInvocation2 isn’t supported. That way we can just store a reference to XInvocation instead of XInvocation2. This change makes it possible to use objects that implement XInvocation from Python, for example ooo.vba.excel.Application. Change-Id: I822c4ffa760f52d6488b9c1009435d059fc19fdd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/209086 Tested-by: Jenkins Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
This commit is contained in:
@@ -58,6 +58,7 @@ using com::sun::star::lang::XSingleServiceFactory;
|
||||
using com::sun::star::lang::XServiceInfo;
|
||||
using com::sun::star::lang::XTypeProvider;
|
||||
using com::sun::star::lang::XUnoTunnel;
|
||||
using com::sun::star::script::XInvocation;
|
||||
using com::sun::star::script::XInvocation2;
|
||||
using com::sun::star::container::XEnumeration;
|
||||
using com::sun::star::container::XEnumerationAccess;
|
||||
@@ -468,7 +469,10 @@ PyObject* PyUNO_dir (PyObject* self)
|
||||
|
||||
try
|
||||
{
|
||||
oo_member_list = me->members->xInvocation->getMemberNames ();
|
||||
if (Reference<XInvocation2> xInvocation2(me->members->xInvocation, UNO_QUERY);
|
||||
xInvocation2.is())
|
||||
{
|
||||
oo_member_list = xInvocation2->getMemberNames ();
|
||||
member_list = PyList_New (oo_member_list.getLength ());
|
||||
for (int i = 0; i < oo_member_list.getLength (); i++)
|
||||
{
|
||||
@@ -476,6 +480,7 @@ PyObject* PyUNO_dir (PyObject* self)
|
||||
PyList_SetItem (member_list, i, ustring2PyString(oo_member_list[i]).getAcquired() );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( const RuntimeException &e )
|
||||
{
|
||||
raisePyExceptionWithAny( Any(e) );
|
||||
@@ -1722,7 +1727,7 @@ PyRef PyUNO_new (
|
||||
const Any &targetInterface,
|
||||
const Reference<XSingleServiceFactory> &ssf )
|
||||
{
|
||||
Reference<XInvocation2> xInvocation;
|
||||
Reference<XInvocation> xInvocation;
|
||||
|
||||
{
|
||||
PyThreadDetach antiguard;
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
#include <osl/diagnose.h>
|
||||
|
||||
#include <com/sun/star/script/CannotConvertException.hpp>
|
||||
#include <com/sun/star/script/XInvocation2.hpp>
|
||||
#include <com/sun/star/script/XInvocation.hpp>
|
||||
|
||||
using com::sun::star::uno::Sequence;
|
||||
using com::sun::star::uno::Reference;
|
||||
using com::sun::star::uno::Any;
|
||||
using com::sun::star::uno::RuntimeException;
|
||||
using com::sun::star::script::XInvocation2;
|
||||
using com::sun::star::script::XInvocation;
|
||||
|
||||
namespace pyuno
|
||||
{
|
||||
@@ -35,7 +35,7 @@ namespace {
|
||||
|
||||
struct PyUNO_callable_Internals
|
||||
{
|
||||
Reference<XInvocation2> xInvocation;
|
||||
Reference<XInvocation> xInvocation;
|
||||
OUString methodName;
|
||||
};
|
||||
|
||||
@@ -254,7 +254,7 @@ static PyTypeObject PyUNO_callable_Type =
|
||||
};
|
||||
|
||||
PyRef PyUNO_callable_new (
|
||||
const Reference<XInvocation2> &my_inv,
|
||||
const Reference<XInvocation> &my_inv,
|
||||
const OUString & methodName )
|
||||
{
|
||||
PyUNO_callable* self;
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace com::sun::star::lang { class XSingleServiceFactory; }
|
||||
namespace com::sun::star::reflection { class XIdlReflection; }
|
||||
namespace com::sun::star::reflection { class XServiceConstructorDescription; }
|
||||
namespace com::sun::star::reflection { class XServiceTypeDescription2; }
|
||||
namespace com::sun::star::script { class XInvocation2; }
|
||||
namespace com::sun::star::script { class XInvocation; }
|
||||
namespace com::sun::star::script { class XInvocationAdapterFactory2; }
|
||||
namespace com::sun::star::script { class XTypeConverter; }
|
||||
|
||||
@@ -130,7 +130,7 @@ PyRef PyUNOStruct_new (
|
||||
|
||||
struct PyUNOInternals
|
||||
{
|
||||
css::uno::Reference <css::script::XInvocation2> xInvocation;
|
||||
css::uno::Reference <css::script::XInvocation> xInvocation;
|
||||
css::uno::Any wrappedObject;
|
||||
};
|
||||
|
||||
@@ -178,7 +178,7 @@ OUString pyString2ustring( PyObject *str );
|
||||
void raiseInvocationTargetExceptionWhenNeeded( const Runtime &runtime );
|
||||
|
||||
PyRef PyUNO_callable_new (
|
||||
const css::uno::Reference<css::script::XInvocation2> &xInv,
|
||||
const css::uno::Reference<css::script::XInvocation> &xInv,
|
||||
const OUString &methodName );
|
||||
|
||||
PyRef PyUNO_service_constructor_new(
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
#include <com/sun/star/registry/InvalidRegistryException.hpp>
|
||||
#include <com/sun/star/script/CannotConvertException.hpp>
|
||||
#include <com/sun/star/uno/XComponentContext.hpp>
|
||||
#include <com/sun/star/script/XInvocation2.hpp>
|
||||
#include <com/sun/star/script/XInvocation.hpp>
|
||||
#include <com/sun/star/reflection/XIdlReflection.hpp>
|
||||
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
|
||||
|
||||
@@ -63,7 +63,7 @@ using com::sun::star::uno::TypeDescription;
|
||||
using com::sun::star::uno::XComponentContext;
|
||||
using com::sun::star::container::NoSuchElementException;
|
||||
using com::sun::star::reflection::XIdlClass;
|
||||
using com::sun::star::script::XInvocation2;
|
||||
using com::sun::star::script::XInvocation;
|
||||
|
||||
using namespace pyuno;
|
||||
|
||||
@@ -139,7 +139,7 @@ public:
|
||||
|
||||
/// @throws RuntimeException
|
||||
void fillStruct(
|
||||
const Reference< XInvocation2 > &inv,
|
||||
const Reference< XInvocation > &inv,
|
||||
typelib_CompoundTypeDescription *pCompType,
|
||||
PyObject *initializer,
|
||||
PyObject *kwinitializer,
|
||||
@@ -486,7 +486,7 @@ static PyObject *createUnoStructHelper(
|
||||
PyRef returnCandidate( PyUNOStruct_new( IdlStruct, c->xInvocation ) );
|
||||
PyUNO *me = reinterpret_cast<PyUNO*>( returnCandidate.get() );
|
||||
TypeDescription desc( typeName );
|
||||
OSL_ASSERT( desc.is() ); // could already instantiate an XInvocation2 !
|
||||
OSL_ASSERT( desc.is() ); // could already instantiate an XInvocation !
|
||||
|
||||
typelib_CompoundTypeDescription *pCompType =
|
||||
reinterpret_cast<typelib_CompoundTypeDescription *>(desc.get());
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
|
||||
#include <com/sun/star/script/Converter.hpp>
|
||||
#include <com/sun/star/script/InvocationAdapterFactory.hpp>
|
||||
#include <com/sun/star/script/XInvocation2.hpp>
|
||||
#include <com/sun/star/script/XInvocation.hpp>
|
||||
#include <com/sun/star/reflection/theCoreReflection.hpp>
|
||||
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
||||
#include <comphelper/sequence.hxx>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <com/sun/star/beans/UnknownPropertyException.hpp>
|
||||
#include <com/sun/star/beans/XMaterialHolder.hpp>
|
||||
#include <com/sun/star/script/CannotConvertException.hpp>
|
||||
#include <com/sun/star/script/XInvocation2.hpp>
|
||||
#include <com/sun/star/script/XInvocation.hpp>
|
||||
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
||||
|
||||
#include "pyuno_impl.hxx"
|
||||
@@ -35,7 +35,7 @@ using com::sun::star::uno::TypeClass;
|
||||
using com::sun::star::uno::RuntimeException;
|
||||
using com::sun::star::uno::Exception;
|
||||
using com::sun::star::lang::XSingleServiceFactory;
|
||||
using com::sun::star::script::XInvocation2;
|
||||
using com::sun::star::script::XInvocation;
|
||||
using com::sun::star::beans::XMaterialHolder;
|
||||
|
||||
namespace pyuno
|
||||
@@ -369,7 +369,7 @@ PyRef PyUNOStruct_new (
|
||||
const Any &targetInterface,
|
||||
const Reference<XSingleServiceFactory> &ssf )
|
||||
{
|
||||
Reference<XInvocation2> xInvocation;
|
||||
Reference<XInvocation> xInvocation;
|
||||
|
||||
{
|
||||
PyThreadDetach antiguard;
|
||||
|
||||
Reference in New Issue
Block a user