Kaydet (Commit) 03806980 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Clean up uses of Any::getValue() in pyuno

Change-Id: I35c4ac0b84e439982f87420aa7587c99ee367920
üst cc66f408
...@@ -29,6 +29,7 @@ $(eval $(call gb_Library_use_libraries,pythonloader,\ ...@@ -29,6 +29,7 @@ $(eval $(call gb_Library_use_libraries,pythonloader,\
)) ))
$(eval $(call gb_Library_use_externals,pythonloader,\ $(eval $(call gb_Library_use_externals,pythonloader,\
boost_headers \
python \ python \
)) ))
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include <pyuno.hxx> #include <pyuno.hxx>
#include <o3tl/any.hxx>
#include <osl/process.h> #include <osl/process.h>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <osl/thread.h> #include <osl/thread.h>
...@@ -71,8 +73,8 @@ static void raiseRuntimeExceptionWhenNeeded() throw ( RuntimeException ) ...@@ -71,8 +73,8 @@ static void raiseRuntimeExceptionWhenNeeded() throw ( RuntimeException )
css::uno::Any a = runtime.extractUnoException( excType, excValue, excTraceback ); css::uno::Any a = runtime.extractUnoException( excType, excValue, excTraceback );
OUStringBuffer buf; OUStringBuffer buf;
buf.append( "python-loader:" ); buf.append( "python-loader:" );
if( a.hasValue() ) if( auto e = o3tl::tryAccess<css::uno::Exception>(a) )
buf.append( static_cast<css::uno::Exception const *>(a.getValue())->Message ); buf.append( e->Message );
throw RuntimeException( buf.makeStringAndClear() ); throw RuntimeException( buf.makeStringAndClear() );
} }
} }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
*/ */
#include "pyuno_impl.hxx" #include "pyuno_impl.hxx"
#include <o3tl/any.hxx>
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
...@@ -87,7 +89,7 @@ void raiseInvocationTargetExceptionWhenNeeded( const Runtime &runtime ) ...@@ -87,7 +89,7 @@ void raiseInvocationTargetExceptionWhenNeeded( const Runtime &runtime )
PyErr_Fetch(reinterpret_cast<PyObject **>(&excType), reinterpret_cast<PyObject**>(&excValue), reinterpret_cast<PyObject**>(&excTraceback)); PyErr_Fetch(reinterpret_cast<PyObject **>(&excType), reinterpret_cast<PyObject**>(&excValue), reinterpret_cast<PyObject**>(&excTraceback));
Any unoExc( runtime.extractUnoException( excType, excValue, excTraceback ) ); Any unoExc( runtime.extractUnoException( excType, excValue, excTraceback ) );
throw InvocationTargetException( throw InvocationTargetException(
static_cast<css::uno::Exception const *>(unoExc.getValue())->Message, o3tl::doAccess<css::uno::Exception>(unoExc)->Message,
Reference<XInterface>(), unoExc ); Reference<XInterface>(), unoExc );
} }
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "pyuno_impl.hxx" #include "pyuno_impl.hxx"
#include <o3tl/any.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <osl/thread.h> #include <osl/thread.h>
#include <osl/module.h> #include <osl/module.h>
...@@ -378,7 +379,7 @@ PyRef Runtime::any2PyObject (const Any &a ) const ...@@ -378,7 +379,7 @@ PyRef Runtime::any2PyObject (const Any &a ) const
} }
case typelib_TypeClass_CHAR: 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 ); return PyRef( PyUNO_char_new( c , *this ), SAL_NO_ACQUIRE );
} }
case typelib_TypeClass_BOOLEAN: case typelib_TypeClass_BOOLEAN:
...@@ -491,15 +492,12 @@ PyRef Runtime::any2PyObject (const Any &a ) const ...@@ -491,15 +492,12 @@ PyRef Runtime::any2PyObject (const Any &a ) const
throw RuntimeException( buf.makeStringAndClear() ); 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 ! // add the message in a standard python way !
PyRef args( PyTuple_New( 1 ), SAL_NO_ACQUIRE, NOT_NULL ); PyRef args( PyTuple_New( 1 ), SAL_NO_ACQUIRE, NOT_NULL );
// assuming that the Message is always the first member, wuuuu PyRef pymsg = ustring2PyString( e->Message );
void const *pData = a.getValue();
OUString message = *static_cast<OUString const *>(pData);
PyRef pymsg = ustring2PyString( message );
PyTuple_SetItem( args.get(), 0 , pymsg.getAcquired() ); PyTuple_SetItem( args.get(), 0 , pymsg.getAcquired() );
// the exception base functions want to have an "args" tuple, // the exception base functions want to have an "args" tuple,
// which contains the message // which contains the message
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
*/ */
#include "pyuno_impl.hxx" #include "pyuno_impl.hxx"
#include <o3tl/any.hxx>
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
...@@ -220,13 +222,14 @@ Type PyType2Type( PyObject * o ) throw(RuntimeException ) ...@@ -220,13 +222,14 @@ Type PyType2Type( PyObject * o ) throw(RuntimeException )
buf.append( "type " ).append(name).append( " is unknown" ); buf.append( "type " ).append(name).append( " is unknown" );
throw RuntimeException( buf.makeStringAndClear() ); 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; OUStringBuffer buf;
buf.append( "pyuno.checkType: " ).append(name).append( " is a " ); buf.append( "pyuno.checkType: " ).append(name).append( " is a " );
buf.appendAscii( typeClassToString( (TypeClass) desc.get()->eTypeClass) ); buf.appendAscii( typeClassToString( (TypeClass) desc.get()->eTypeClass) );
buf.append( ", but type got construct with typeclass " ); 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() ); throw RuntimeException( buf.makeStringAndClear() );
} }
return desc.get()->pWeakRef; return desc.get()->pWeakRef;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment