diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2016-06-21 12:46:45 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-06-21 12:46:45 +0200 |
commit | 038069806e4e2a8760fa415a23c28ccd338239f4 (patch) | |
tree | 601890911cabdf1f45730541c8c3544a326c92ba /pyuno | |
parent | cc66f408f99602618be12ce6c47152233291e1db (diff) |
Clean up uses of Any::getValue() in pyuno
Change-Id: I35c4ac0b84e439982f87420aa7587c99ee367920
Diffstat (limited to 'pyuno')
-rw-r--r-- | pyuno/Library_pythonloader.mk | 1 | ||||
-rw-r--r-- | pyuno/source/loader/pyuno_loader.cxx | 6 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_adapter.cxx | 4 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_runtime.cxx | 10 | ||||
-rw-r--r-- | 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 <pyuno.hxx> +#include <o3tl/any.hxx> + #include <osl/process.h> #include <osl/file.hxx> #include <osl/thread.h> @@ -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<css::uno::Exception const *>(a.getValue())->Message ); + if( auto e = o3tl::tryAccess<css::uno::Exception>(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 <o3tl/any.hxx> + #include <rtl/ustrbuf.hxx> #include <rtl/strbuf.hxx> @@ -87,7 +89,7 @@ void raiseInvocationTargetExceptionWhenNeeded( const Runtime &runtime ) PyErr_Fetch(reinterpret_cast<PyObject **>(&excType), reinterpret_cast<PyObject**>(&excValue), reinterpret_cast<PyObject**>(&excTraceback)); Any unoExc( runtime.extractUnoException( excType, excValue, excTraceback ) ); throw InvocationTargetException( - static_cast<css::uno::Exception const *>(unoExc.getValue())->Message, + o3tl::doAccess<css::uno::Exception>(unoExc)->Message, Reference<XInterface>(), 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 <o3tl/any.hxx> #include <osl/diagnose.h> #include <osl/thread.h> #include <osl/module.h> @@ -378,7 +379,7 @@ PyRef Runtime::any2PyObject (const Any &a ) const } case typelib_TypeClass_CHAR: { - sal_Unicode c = *static_cast<sal_Unicode const *>(a.getValue()); + sal_Unicode c = *o3tl::forceAccess<sal_Unicode>(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<css::uno::Exception>(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<OUString const *>(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 <o3tl/any.hxx> + #include <rtl/ustrbuf.hxx> #include <rtl/strbuf.hxx> @@ -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<sal_Int32 const *>(enumValue.getValue()) ) + css::uno::TypeClass tc = *o3tl::doAccess<css::uno::TypeClass>(enumValue); + if( static_cast<css::uno::TypeClass>(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<sal_Int32 const *>(enumValue.getValue()) ) ); + buf.appendAscii( typeClassToString( tc ) ); throw RuntimeException( buf.makeStringAndClear() ); } return desc.get()->pWeakRef; |