From 97302647bacdb8e04b20a484bd6bc136cad2843d Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 11 Aug 2026 12:12:35 +0200 Subject: [PATCH] =?UTF-8?q?tdf#173114=20pyuno:=20Don=E2=80=99t=20require?= =?UTF-8?q?=20XInvocation2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- pyuno/source/module/pyuno.cxx | 17 +++++++++++------ pyuno/source/module/pyuno_callable.cxx | 8 ++++---- pyuno/source/module/pyuno_impl.hxx | 6 +++--- pyuno/source/module/pyuno_module.cxx | 8 ++++---- pyuno/source/module/pyuno_runtime.cxx | 2 +- pyuno/source/module/pyuno_struct.cxx | 6 +++--- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/pyuno/source/module/pyuno.cxx b/pyuno/source/module/pyuno.cxx index 8c081522233d..6cfc876a701c 100644 --- a/pyuno/source/module/pyuno.cxx +++ b/pyuno/source/module/pyuno.cxx @@ -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,12 +469,16 @@ PyObject* PyUNO_dir (PyObject* self) try { - oo_member_list = me->members->xInvocation->getMemberNames (); - member_list = PyList_New (oo_member_list.getLength ()); - for (int i = 0; i < oo_member_list.getLength (); i++) + if (Reference xInvocation2(me->members->xInvocation, UNO_QUERY); + xInvocation2.is()) { - // setitem steals a reference - PyList_SetItem (member_list, i, ustring2PyString(oo_member_list[i]).getAcquired() ); + oo_member_list = xInvocation2->getMemberNames (); + member_list = PyList_New (oo_member_list.getLength ()); + for (int i = 0; i < oo_member_list.getLength (); i++) + { + // setitem steals a reference + PyList_SetItem (member_list, i, ustring2PyString(oo_member_list[i]).getAcquired() ); + } } } catch( const RuntimeException &e ) @@ -1722,7 +1727,7 @@ PyRef PyUNO_new ( const Any &targetInterface, const Reference &ssf ) { - Reference xInvocation; + Reference xInvocation; { PyThreadDetach antiguard; diff --git a/pyuno/source/module/pyuno_callable.cxx b/pyuno/source/module/pyuno_callable.cxx index 2c802aa70ef8..62f1c89bc111 100644 --- a/pyuno/source/module/pyuno_callable.cxx +++ b/pyuno/source/module/pyuno_callable.cxx @@ -21,13 +21,13 @@ #include #include -#include +#include 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 xInvocation; + Reference xInvocation; OUString methodName; }; @@ -254,7 +254,7 @@ static PyTypeObject PyUNO_callable_Type = }; PyRef PyUNO_callable_new ( - const Reference &my_inv, + const Reference &my_inv, const OUString & methodName ) { PyUNO_callable* self; diff --git a/pyuno/source/module/pyuno_impl.hxx b/pyuno/source/module/pyuno_impl.hxx index c281155e7477..d75631711428 100644 --- a/pyuno/source/module/pyuno_impl.hxx +++ b/pyuno/source/module/pyuno_impl.hxx @@ -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 xInvocation; + css::uno::Reference 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 &xInv, + const css::uno::Reference &xInv, const OUString &methodName ); PyRef PyUNO_service_constructor_new( diff --git a/pyuno/source/module/pyuno_module.cxx b/pyuno/source/module/pyuno_module.cxx index b1eb13ec659c..99c05ce6c4e5 100644 --- a/pyuno/source/module/pyuno_module.cxx +++ b/pyuno/source/module/pyuno_module.cxx @@ -48,7 +48,7 @@ #include #include #include -#include +#include #include #include @@ -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( 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(desc.get()); diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx index 8f570009add0..2b86490228ac 100644 --- a/pyuno/source/module/pyuno_runtime.cxx +++ b/pyuno/source/module/pyuno_runtime.cxx @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/pyuno/source/module/pyuno_struct.cxx b/pyuno/source/module/pyuno_struct.cxx index 3b8b14ab2017..d2aa0457f93d 100644 --- a/pyuno/source/module/pyuno_struct.cxx +++ b/pyuno/source/module/pyuno_struct.cxx @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #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 &ssf ) { - Reference xInvocation; + Reference xInvocation; { PyThreadDetach antiguard;