From 038069806e4e2a8760fa415a23c28ccd338239f4 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 21 Jun 2016 12:46:45 +0200 Subject: [PATCH] Clean up uses of Any::getValue() in pyuno Change-Id: I35c4ac0b84e439982f87420aa7587c99ee367920 --- pyuno/Library_pythonloader.mk | 1 + pyuno/source/loader/pyuno_loader.cxx | 6 ++++-- pyuno/source/module/pyuno_adapter.cxx | 4 +++- pyuno/source/module/pyuno_runtime.cxx | 10 ++++------ pyuno/source/module/pyuno_type.cxx | 7 +++++-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/pyuno/Library_pythonloader.mk b/pyuno/Library_pythonloader.mk index f35905726222..adc622ee57b2 100644 --- a/pyuno/Library_pythonloader.mk +++ b/pyuno/Library_pythonloader.mk @@ -29,6 +29,7 @@ $(eval $(call gb_Library_use_libraries,pythonloader,\ )) $(eval $(call gb_Library_use_externals,pythonloader,\ + boost_headers \ python \ )) diff --git a/pyuno/source/loader/pyuno_loader.cxx b/pyuno/source/loader/pyuno_loader.cxx index ef16cfb1872e..af835411d115 100644 --- a/pyuno/source/loader/pyuno_loader.cxx +++ b/pyuno/source/loader/pyuno_loader.cxx @@ -22,6 +22,8 @@ #include +#include + #include #include #include @@ -71,8 +73,8 @@ static void raiseRuntimeExceptionWhenNeeded() throw ( RuntimeException ) css::uno::Any a = runtime.extractUnoException( excType, excValue, excTraceback ); OUStringBuffer buf; buf.append( "python-loader:" ); - if( a.hasValue() ) - buf.append( static_cast(a.getValue())->Message ); + if( auto e = o3tl::tryAccess(a) ) + buf.append( e->Message ); throw RuntimeException( buf.makeStringAndClear() ); } } diff --git a/pyuno/source/module/pyuno_adapter.cxx b/pyuno/source/module/pyuno_adapter.cxx index 77abd7d3e4b8..cf60272a917e 100644 --- a/pyuno/source/module/pyuno_adapter.cxx +++ b/pyuno/source/module/pyuno_adapter.cxx @@ -18,6 +18,8 @@ */ #include "pyuno_impl.hxx" +#include + #include #include @@ -87,7 +89,7 @@ void raiseInvocationTargetExceptionWhenNeeded( const Runtime &runtime ) PyErr_Fetch(reinterpret_cast(&excType), reinterpret_cast(&excValue), reinterpret_cast(&excTraceback)); Any unoExc( runtime.extractUnoException( excType, excValue, excTraceback ) ); throw InvocationTargetException( - static_cast(unoExc.getValue())->Message, + o3tl::doAccess(unoExc)->Message, Reference(), unoExc ); } } diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx index 7d7cfebc15c2..1cc944780871 100644 --- a/pyuno/source/module/pyuno_runtime.cxx +++ b/pyuno/source/module/pyuno_runtime.cxx @@ -22,6 +22,7 @@ #include "pyuno_impl.hxx" +#include #include #include #include @@ -378,7 +379,7 @@ PyRef Runtime::any2PyObject (const Any &a ) const } case typelib_TypeClass_CHAR: { - sal_Unicode c = *static_cast(a.getValue()); + sal_Unicode c = *o3tl::forceAccess(a); return PyRef( PyUNO_char_new( c , *this ), SAL_NO_ACQUIRE ); } case typelib_TypeClass_BOOLEAN: @@ -491,15 +492,12 @@ PyRef Runtime::any2PyObject (const Any &a ) const throw RuntimeException( buf.makeStringAndClear() ); } - if( css::uno::TypeClass_EXCEPTION == a.getValueTypeClass() ) + if( auto e = o3tl::tryAccess(a) ) { // add the message in a standard python way ! PyRef args( PyTuple_New( 1 ), SAL_NO_ACQUIRE, NOT_NULL ); - // assuming that the Message is always the first member, wuuuu - void const *pData = a.getValue(); - OUString message = *static_cast(pData); - PyRef pymsg = ustring2PyString( message ); + PyRef pymsg = ustring2PyString( e->Message ); PyTuple_SetItem( args.get(), 0 , pymsg.getAcquired() ); // the exception base functions want to have an "args" tuple, // which contains the message diff --git a/pyuno/source/module/pyuno_type.cxx b/pyuno/source/module/pyuno_type.cxx index c2472e478029..b522b8d93aff 100644 --- a/pyuno/source/module/pyuno_type.cxx +++ b/pyuno/source/module/pyuno_type.cxx @@ -18,6 +18,8 @@ */ #include "pyuno_impl.hxx" +#include + #include #include @@ -220,13 +222,14 @@ Type PyType2Type( PyObject * o ) throw(RuntimeException ) buf.append( "type " ).append(name).append( " is unknown" ); throw RuntimeException( buf.makeStringAndClear() ); } - if( desc.get()->eTypeClass != (typelib_TypeClass) *static_cast(enumValue.getValue()) ) + css::uno::TypeClass tc = *o3tl::doAccess(enumValue); + if( static_cast(desc.get()->eTypeClass) != tc ) { OUStringBuffer buf; buf.append( "pyuno.checkType: " ).append(name).append( " is a " ); buf.appendAscii( typeClassToString( (TypeClass) desc.get()->eTypeClass) ); buf.append( ", but type got construct with typeclass " ); - buf.appendAscii( typeClassToString( (TypeClass) *static_cast(enumValue.getValue()) ) ); + buf.appendAscii( typeClassToString( tc ) ); throw RuntimeException( buf.makeStringAndClear() ); } return desc.get()->pWeakRef;