summaryrefslogtreecommitdiff
path: root/basic/source/classes/sbunoobj.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'basic/source/classes/sbunoobj.cxx')
-rw-r--r--basic/source/classes/sbunoobj.cxx173
1 files changed, 76 insertions, 97 deletions
diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx
index 9e1d31fb4ac1..5fea3f14179f 100644
--- a/basic/source/classes/sbunoobj.cxx
+++ b/basic/source/classes/sbunoobj.cxx
@@ -20,14 +20,15 @@
#include <sal/config.h>
#include <o3tl/any.hxx>
-#include <osl/mutex.hxx>
+#include <o3tl/safeint.hxx>
+#include <utility>
#include <vcl/svapp.hxx>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <svl/hint.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/exc_hlp.hxx>
-#include <comphelper/interfacecontainer2.hxx>
+#include <comphelper/interfacecontainer4.hxx>
#include <comphelper/extract.hxx>
#include <comphelper/processfactory.hxx>
#include <cppuhelper/weakref.hxx>
@@ -99,9 +100,9 @@ using namespace cppu;
// Identifiers for creating the strings for dbg_Properties
-constexpr OUStringLiteral ID_DBG_SUPPORTEDINTERFACES = u"Dbg_SupportedInterfaces";
-constexpr OUStringLiteral ID_DBG_PROPERTIES = u"Dbg_Properties";
-constexpr OUStringLiteral ID_DBG_METHODS = u"Dbg_Methods";
+constexpr OUString ID_DBG_SUPPORTEDINTERFACES = u"Dbg_SupportedInterfaces"_ustr;
+constexpr OUString ID_DBG_PROPERTIES = u"Dbg_Properties"_ustr;
+constexpr OUString ID_DBG_METHODS = u"Dbg_Methods"_ustr;
char const aSeqLevelStr[] = "[]";
@@ -968,6 +969,12 @@ static Type getUnoTypeForSbxValue( const SbxValue* pVal )
// No object, convert basic type
else
{
+ if (eBaseType == SbxBYTE && pVal->GetByte() > 127)
+ {
+ // Basic Byte type is unsigned; cppu::UnoType<sal_uInt8> corresponds to UNO boolean,
+ // so values 128-255 are only representable starting with UNO short types
+ eBaseType = SbxUSHORT;
+ }
aRetType = getUnoTypeForSbxBaseType( eBaseType );
}
return aRetType;
@@ -1048,19 +1055,10 @@ static Any sbxToUnoValueImpl( const SbxValue* pVar, bool bBlockConversionToSmall
aType = ::cppu::UnoType<sal_Int16>::get();
break;
}
- case TypeClass_UNSIGNED_SHORT:
- {
- sal_uInt16 n = pVar->GetUShort();
- if( n <= 255 )
- aType = cppu::UnoType<sal_uInt8>::get();
- break;
- }
case TypeClass_UNSIGNED_LONG:
{
sal_uInt32 n = pVar->GetLong();
- if( n <= 255 )
- aType = cppu::UnoType<sal_uInt8>::get();
- else if( n <= SbxMAXUINT )
+ if( n <= SbxMAXUINT )
aType = cppu::UnoType<cppu::UnoUnsignedShortType>::get();
break;
}
@@ -1534,7 +1532,7 @@ static Any invokeAutomationMethod( const OUString& Name, Sequence< Any > const &
for( sal_uInt32 j = 0 ; j < nLen ; j++ )
{
sal_Int16 iTarget = pIndices[ j ];
- if( iTarget >= static_cast<sal_Int16>(nParamCount) )
+ if( o3tl::make_unsigned(iTarget) >= nParamCount )
break;
unoToSbxValue(pParams->Get(j + 1), pNewValues[j]);
}
@@ -1607,9 +1605,7 @@ static OUString getDbgObjectName(SbUnoObject& rUnoObj)
{
aRet.append( "\n" );
}
- aRet.append( "\"" );
- aRet.append( aName );
- aRet.append( "\":" );
+ aRet.append( "\"" + aName + "\":" );
return aRet.makeStringAndClear();
}
@@ -1741,16 +1737,16 @@ static OUString Impl_GetSupportedInterfaces(SbUnoObject& rUnoObj)
auto x = o3tl::tryAccess<Reference<XInterface>>(aToInspectObj);
if( !x )
{
- aRet.append( ID_DBG_SUPPORTEDINTERFACES );
- aRet.append( " not available.\n(TypeClass is not TypeClass_INTERFACE)\n" );
+ aRet.append( ID_DBG_SUPPORTEDINTERFACES
+ + " not available.\n(TypeClass is not TypeClass_INTERFACE)\n" );
}
else
{
Reference< XTypeProvider > xTypeProvider( *x, UNO_QUERY );
- aRet.append( "Supported interfaces by object " );
- aRet.append(getDbgObjectName(rUnoObj));
- aRet.append( "\n" );
+ aRet.append( "Supported interfaces by object "
+ + getDbgObjectName(rUnoObj)
+ + "\n" );
if( xTypeProvider.is() )
{
// get the interfaces of the implementation
@@ -1771,9 +1767,9 @@ static OUString Impl_GetSupportedInterfaces(SbUnoObject& rUnoObj)
typelib_TypeDescription * pTD = nullptr;
rType.getDescription( &pTD );
- aRet.append( "*** ERROR: No IdlClass for type \"" );
- aRet.append( pTD->pTypeName );
- aRet.append( "\"\n*** Please check type library\n" );
+ aRet.append( OUString::Concat("*** ERROR: No IdlClass for type \"")
+ + OUString::unacquired(&pTD->pTypeName)
+ + "\"\n*** Please check type library\n" );
}
}
}
@@ -1829,9 +1825,7 @@ static OUString Dbg_SbxDataType2String( SbxDataType eType )
// Debugging help method to display the properties of a SbUnoObjects
static OUString Impl_DumpProperties(SbUnoObject& rUnoObj)
{
- OUStringBuffer aRet;
- aRet.append("Properties of object ");
- aRet.append(getDbgObjectName(rUnoObj));
+ OUStringBuffer aRet("Properties of object " + getDbgObjectName(rUnoObj));
// analyse the Uno-Infos to recognise the arrays
Reference< XIntrospectionAccess > xAccess = rUnoObj.getIntrospectionAccess();
@@ -1889,8 +1883,7 @@ static OUString Impl_DumpProperties(SbUnoObject& rUnoObj)
aPropStr.append( Dbg_SbxDataType2String( eType ) );
if( bMaybeVoid )
aPropStr.append( "/void" );
- aPropStr.append( " " );
- aPropStr.append( pVar->GetName() );
+ aPropStr.append( " " + pVar->GetName() );
if( i == nPropCount - 1 )
aPropStr.append( "\n" );
@@ -1906,9 +1899,7 @@ static OUString Impl_DumpProperties(SbUnoObject& rUnoObj)
// Debugging help method to display the methods of an SbUnoObjects
static OUString Impl_DumpMethods(SbUnoObject& rUnoObj)
{
- OUStringBuffer aRet;
- aRet.append("Methods of object ");
- aRet.append(getDbgObjectName(rUnoObj));
+ OUStringBuffer aRet("Methods of object " + getDbgObjectName(rUnoObj));
// XIntrospectionAccess, so that the types of the parameter could be outputted
Reference< XIntrospectionAccess > xAccess = rUnoObj.getIntrospectionAccess();
@@ -1955,10 +1946,8 @@ static OUString Impl_DumpMethods(SbUnoObject& rUnoObj)
eType = SbxDataType( SbxOBJECT | SbxARRAY );
}
// output the name and the type
- aRet.append( Dbg_SbxDataType2String( eType ) );
- aRet.append( " " );
- aRet.append ( pVar->GetName() );
- aRet.append( " ( " );
+ aRet.append( Dbg_SbxDataType2String( eType )
+ + " " + pVar->GetName() + " ( " );
// the get-method mustn't have a parameter
Sequence< Reference< XIdlClass > > aParamsSeq = rxMethod->getParameterTypes();
@@ -2052,7 +2041,7 @@ void SbUnoObject::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
{
if ( pProp->isUnoStruct() )
{
- SbUnoStructRefObject* pSbUnoObject = new SbUnoStructRefObject( pProp->GetName(), aMember );
+ SbUnoStructRefObject* pSbUnoObject = new SbUnoStructRefObject( pProp->GetName(), std::move(aMember) );
SbxObjectRef xWrapper = static_cast<SbxObject*>(pSbUnoObject);
pVar->PutObject( xWrapper.get() );
}
@@ -2312,12 +2301,9 @@ SbUnoObject::SbUnoObject( const OUString& aName_, const Any& aUnoObj_ )
return;
}
- Reference< XTypeProvider > xTypeProvider;
// Did the object have an invocation itself?
mxInvocation.set( x, UNO_QUERY );
- xTypeProvider.set( x, UNO_QUERY );
-
if( mxInvocation.is() )
{
@@ -2325,6 +2311,7 @@ SbUnoObject::SbUnoObject( const OUString& aName_, const Any& aUnoObj_ )
mxExactNameInvocation.set( mxInvocation, UNO_QUERY );
// The remainder refers only to the introspection
+ Reference< XTypeProvider > xTypeProvider( x, UNO_QUERY );
if( !xTypeProvider.is() )
{
bNeedIntrospection = false;
@@ -2437,11 +2424,11 @@ void SbUnoObject::doIntrospection()
// Start of a list of all SbUnoMethod-Instances
-static SbUnoMethod* pFirst = nullptr;
+static SbUnoMethod* s_pFirst = nullptr;
void clearUnoMethodsForBasic( StarBASIC const * pBasic )
{
- SbUnoMethod* pMeth = pFirst;
+ SbUnoMethod* pMeth = s_pFirst;
while( pMeth )
{
SbxObject* pObject = pMeth->GetParent();
@@ -2456,8 +2443,8 @@ void clearUnoMethodsForBasic( StarBASIC const * pBasic )
// set the new StarBASIC as the parent of the module
// pObject->SetParent( NULL );
- if( pMeth == pFirst )
- pFirst = pMeth->pNext;
+ if( pMeth == s_pFirst )
+ s_pFirst = pMeth->pNext;
else if( pMeth->pPrev )
pMeth->pPrev->pNext = pMeth->pNext;
if( pMeth->pNext )
@@ -2470,7 +2457,7 @@ void clearUnoMethodsForBasic( StarBASIC const * pBasic )
pObject->SbxValue::Clear();
// start from the beginning after object clearing, the cycle will end since the method is removed each time
- pMeth = pFirst;
+ pMeth = s_pFirst;
}
else
pMeth = pMeth->pNext;
@@ -2482,7 +2469,7 @@ void clearUnoMethodsForBasic( StarBASIC const * pBasic )
void clearUnoMethods()
{
- SbUnoMethod* pMeth = pFirst;
+ SbUnoMethod* pMeth = s_pFirst;
while( pMeth )
{
pMeth->SbxValue::Clear();
@@ -2505,9 +2492,9 @@ SbUnoMethod::SbUnoMethod
pParamInfoSeq = nullptr;
// enregister the method in a list
- pNext = pFirst;
+ pNext = s_pFirst;
pPrev = nullptr;
- pFirst = this;
+ s_pFirst = this;
if( pNext )
pNext->pPrev = this;
}
@@ -2516,8 +2503,8 @@ SbUnoMethod::~SbUnoMethod()
{
pParamInfoSeq.reset();
- if( this == pFirst )
- pFirst = pNext;
+ if( this == s_pFirst )
+ s_pFirst = pNext;
else if( pPrev )
pPrev->pNext = pNext;
if( pNext )
@@ -2566,13 +2553,13 @@ SbUnoProperty::SbUnoProperty
const OUString& aName_,
SbxDataType eSbxType,
SbxDataType eRealSbxType,
- const Property& aUnoProp_,
+ Property aUnoProp_,
sal_Int32 nId_,
bool bInvocation,
bool bUnoStruct
)
: SbxProperty( aName_, eSbxType )
- , aUnoProp( aUnoProp_ )
+ , aUnoProp(std::move( aUnoProp_ ))
, nId( nId_ )
, mbInvocation( bInvocation )
, mRealType( eRealSbxType )
@@ -2756,15 +2743,15 @@ void SbUnoObject::implCreateDbgProperties()
Property aProp;
// Id == -1: display the implemented interfaces corresponding the ClassProvider
- auto xVarRef = tools::make_ref<SbUnoProperty>( OUString(ID_DBG_SUPPORTEDINTERFACES), SbxSTRING, SbxSTRING, aProp, -1, false, false );
+ auto xVarRef = tools::make_ref<SbUnoProperty>( ID_DBG_SUPPORTEDINTERFACES, SbxSTRING, SbxSTRING, aProp, -1, false, false );
QuickInsert( xVarRef.get() );
// Id == -2: output the properties
- xVarRef = tools::make_ref<SbUnoProperty>( OUString(ID_DBG_PROPERTIES), SbxSTRING, SbxSTRING, aProp, -2, false, false );
+ xVarRef = tools::make_ref<SbUnoProperty>( ID_DBG_PROPERTIES, SbxSTRING, SbxSTRING, aProp, -2, false, false );
QuickInsert( xVarRef.get() );
// Id == -3: output the Methods
- xVarRef = tools::make_ref<SbUnoProperty>( OUString(ID_DBG_METHODS), SbxSTRING, SbxSTRING, aProp, -3, false, false );
+ xVarRef = tools::make_ref<SbUnoProperty>( ID_DBG_METHODS, SbxSTRING, SbxSTRING, aProp, -3, false, false );
QuickInsert( xVarRef.get() );
}
@@ -3272,14 +3259,14 @@ void VBAConstantHelper::init()
}
bool
-VBAConstantHelper::isVBAConstantType( const OUString& rName )
+VBAConstantHelper::isVBAConstantType( std::u16string_view rName )
{
init();
bool bConstant = false;
for (auto const& elem : aConstCache)
{
- if( rName.equalsIgnoreAsciiCase(elem) )
+ if( o3tl::equalsIgnoreAsciiCase(rName, elem) )
{
bConstant = true;
break;
@@ -3784,7 +3771,7 @@ public:
SbxObjectRef xSbxObj;
OUString aPrefixName;
- explicit BasicAllListener_Impl( const OUString& aPrefixName );
+ explicit BasicAllListener_Impl( OUString aPrefixName );
// Methods of XAllListener
virtual void SAL_CALL firing(const AllEventObject& Event) override;
@@ -3796,8 +3783,8 @@ public:
}
-BasicAllListener_Impl::BasicAllListener_Impl(const OUString& aPrefixName_)
- : aPrefixName( aPrefixName_ )
+BasicAllListener_Impl::BasicAllListener_Impl(OUString aPrefixName_)
+ : aPrefixName(std::move( aPrefixName_ ))
{
}
@@ -3882,7 +3869,7 @@ class InvocationToAllListenerMapper : public WeakImplHelper< XInvocation >
{
public:
InvocationToAllListenerMapper( const Reference< XIdlClass >& ListenerType,
- const Reference< XAllListener >& AllListener, const Any& Helper );
+ const Reference< XAllListener >& AllListener, Any Helper );
// XInvocation
virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection() override;
@@ -3923,10 +3910,10 @@ static Reference< XInterface > createAllListenerAdapter
// InvocationToAllListenerMapper
InvocationToAllListenerMapper::InvocationToAllListenerMapper
- ( const Reference< XIdlClass >& ListenerType, const Reference< XAllListener >& AllListener, const Any& Helper )
+ ( const Reference< XIdlClass >& ListenerType, const Reference< XAllListener >& AllListener, Any Helper )
: m_xAllListener( AllListener )
, m_xListenerType( ListenerType )
- , m_Helper( Helper )
+ , m_Helper(std::move( Helper ))
{
}
@@ -3973,7 +3960,7 @@ Any SAL_CALL InvocationToAllListenerMapper::invoke(const OUString& FunctionName,
}
AllEventObject aAllEvent;
- aAllEvent.Source = static_cast<OWeakObject*>(this);
+ aAllEvent.Source = getXWeak();
aAllEvent.Helper = m_Helper;
aAllEvent.ListenerType = Type(m_xListenerType->getTypeClass(), m_xListenerType->getName() );
aAllEvent.MethodName = FunctionName;
@@ -4126,9 +4113,8 @@ void RTL_Impl_CreateUnoValue( SbxArray& rPar )
bool bSuccess = implGetTypeByName( aValTypeName, aType );
if( bSuccess )
{
- Any aTypeAny( aType );
SbxVariableRef refVar = rPar.Get(0);
- SbxObjectRef xUnoAnyObject = new SbUnoAnyObject( aTypeAny );
+ SbxObjectRef xUnoAnyObject = new SbUnoAnyObject(Any(aType));
refVar->PutObject( xUnoAnyObject.get() );
}
return;
@@ -4166,12 +4152,12 @@ namespace {
class ModuleInvocationProxy : public WeakImplHelper< XInvocation, XComponent >
{
- ::osl::Mutex m_aMutex;
+ std::mutex m_aMutex;
OUString m_aPrefix;
SbxObjectRef m_xScopeObj;
bool m_bProxyIsClassModuleObject;
- ::comphelper::OInterfaceContainerHelper2 m_aListeners;
+ ::comphelper::OInterfaceContainerHelper4<XEventListener> m_aListeners;
public:
ModuleInvocationProxy( std::u16string_view aPrefix, SbxObjectRef const & xScopeObj );
@@ -4199,7 +4185,6 @@ public:
ModuleInvocationProxy::ModuleInvocationProxy( std::u16string_view aPrefix, SbxObjectRef const & xScopeObj )
: m_aPrefix( OUString::Concat(aPrefix) + "_" )
, m_xScopeObj( xScopeObj )
- , m_aListeners( m_aMutex )
{
m_bProxyIsClassModuleObject = xScopeObj.is() && dynamic_cast<const SbClassModuleObject*>( xScopeObj.get() ) != nullptr;
}
@@ -4300,17 +4285,13 @@ Any SAL_CALL ModuleInvocationProxy::invoke( const OUString& rFunction,
OUString aFunctionName = m_aPrefix
+ rFunction;
- bool bSetRescheduleBack = false;
- bool bOldReschedule = true;
+ bool bOldReschedule = false;
SbiInstance* pInst = GetSbData()->pInst;
if( pInst && pInst->IsCompatibility() )
{
bOldReschedule = pInst->IsReschedule();
if ( bOldReschedule )
- {
pInst->EnableReschedule( false );
- bSetRescheduleBack = true;
- }
}
SbxVariable* p = xScopeObj->Find( aFunctionName, SbxClassType::Method );
@@ -4345,7 +4326,7 @@ Any SAL_CALL ModuleInvocationProxy::invoke( const OUString& rFunction,
aRet = sbxToUnoValue( xValue.get() );
pMeth->SetParameters( nullptr );
- if( bSetRescheduleBack )
+ if (bOldReschedule)
pInst->EnableReschedule( bOldReschedule );
// TODO: OutParameter?
@@ -4355,22 +4336,24 @@ Any SAL_CALL ModuleInvocationProxy::invoke( const OUString& rFunction,
void SAL_CALL ModuleInvocationProxy::dispose()
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::unique_lock aGuard( m_aMutex );
EventObject aEvent( static_cast<XComponent*>(this) );
- m_aListeners.disposeAndClear( aEvent );
+ m_aListeners.disposeAndClear( aGuard, aEvent );
m_xScopeObj = nullptr;
}
void SAL_CALL ModuleInvocationProxy::addEventListener( const Reference< XEventListener >& xListener )
{
- m_aListeners.addInterface( xListener );
+ std::unique_lock aGuard( m_aMutex );
+ m_aListeners.addInterface( aGuard, xListener );
}
void SAL_CALL ModuleInvocationProxy::removeEventListener( const Reference< XEventListener >& xListener )
{
- m_aListeners.removeInterface( xListener );
+ std::unique_lock aGuard( m_aMutex );
+ m_aListeners.removeInterface( aGuard, xListener );
}
@@ -4631,7 +4614,7 @@ TypeClass StructRefInfo::getTypeClass() const
return maType.getTypeClass();
}
-SbUnoStructRefObject::SbUnoStructRefObject( const OUString& aName_, const StructRefInfo& rMemberInfo ) : SbxObject( aName_ ), maMemberInfo( rMemberInfo ), mbMemberCacheInit( false )
+SbUnoStructRefObject::SbUnoStructRefObject( const OUString& aName_, StructRefInfo aMemberInfo ) : SbxObject( aName_ ), maMemberInfo(std::move( aMemberInfo )), mbMemberCacheInit( false )
{
SetClassName( maMemberInfo.getTypeName() );
}
@@ -4679,7 +4662,8 @@ SbxVariable* SbUnoStructRefObject::Find( const OUString& rName, SbxClassType t )
Property aProp;
aProp.Name = rName;
aProp.Type = css::uno::Type( it->second->getTypeClass(), it->second->getTypeName() );
- SbUnoProperty* pProp = new SbUnoProperty( rName, eSbxType, eRealSbxType, aProp, 0, false, ( aProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT) );
+ const bool bIsStruct = aProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT;
+ SbUnoProperty* pProp = new SbUnoProperty( rName, eSbxType, eRealSbxType, std::move(aProp), 0, false, bIsStruct );
SbxVariableRef xVarRef = pProp;
QuickInsert( xVarRef.get() );
pRes = xVarRef.get();
@@ -4717,7 +4701,7 @@ void SbUnoStructRefObject::implCreateDbgProperties()
QuickInsert( xVarRef.get() );
// Id == -3: output the Methods
- xVarRef = new SbUnoProperty( ID_DBG_METHODS, SbxSTRING, SbxSTRING, aProp, -3, false, false );
+ xVarRef = new SbUnoProperty( ID_DBG_METHODS, SbxSTRING, SbxSTRING, std::move(aProp), -3, false, false );
QuickInsert( xVarRef.get() );
}
@@ -4739,7 +4723,8 @@ void SbUnoStructRefObject::implCreateAll()
Property aProp;
aProp.Name = rName;
aProp.Type = css::uno::Type( field.second->getTypeClass(), field.second->getTypeName() );
- SbUnoProperty* pProp = new SbUnoProperty( rName, eSbxType, eRealSbxType, aProp, 0, false, ( aProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT) );
+ const bool bIsStruct = aProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT;
+ SbUnoProperty* pProp = new SbUnoProperty( rName, eSbxType, eRealSbxType, std::move(aProp), 0, false, bIsStruct );
SbxVariableRef xVarRef = pProp;
QuickInsert( xVarRef.get() );
}
@@ -4756,9 +4741,7 @@ Any SbUnoStructRefObject::getUnoAny()
OUString SbUnoStructRefObject::Impl_DumpProperties()
{
- OUStringBuffer aRet;
- aRet.append("Properties of object ");
- aRet.append( getDbgObjectName() );
+ OUStringBuffer aRet("Properties of object " + getDbgObjectName() );
sal_uInt32 nPropCount = pProps->Count();
sal_uInt32 nPropsPerLine = 1 + nPropCount / 30;
@@ -4791,10 +4774,8 @@ OUString SbUnoStructRefObject::Impl_DumpProperties()
}
}
}
- aPropStr.append( Dbg_SbxDataType2String( eType ) );
-
- aPropStr.append( " " );
- aPropStr.append( pVar->GetName() );
+ aPropStr.append( Dbg_SbxDataType2String( eType )
+ + " " + pVar->GetName() );
if( i == nPropCount - 1 )
{
@@ -4915,9 +4896,7 @@ OUString SbUnoStructRefObject::getDbgObjectName() const
{
aRet.append( "\n" );
}
- aRet.append( "\"" );
- aRet.append( aName );
- aRet.append( "\":" );
+ aRet.append( "\"" + aName + "\":" );
return aRet.makeStringAndClear();
}