From 1944e3ddc0b2247de3138d2a441cd6999e21fd9a Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Thu, 5 Oct 2017 06:19:56 +0300 Subject: Rename and move SAL_U/W to o3tl::toU/W Previosly (since commit 9ac98e6e3488e434bf4864ecfb13a121784f640b) it was expected to gradually remove SAL_U/W usage in Windows code by replacing with reinterpret_cast or changing to some bettertypes. But as it's useful to make use of fact that LibreOffice and Windows use compatible representation of strings, this commit puts these functions to a better-suited o3tl, and recommends that the functions be consistently used throughout Windows-specific code to reflect the compatibility and keep the casts safe. Change-Id: I2f7c65606d0e2d0c01a00f08812bb4ab7659c5f6 Reviewed-on: https://gerrit.libreoffice.org/43150 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- extensions/source/config/ldap/ldapaccess.cxx | 19 +++++---- extensions/source/ole/oleobjw.cxx | 48 +++++++++++----------- extensions/source/ole/servprov.cxx | 3 +- extensions/source/ole/unoconversionutilities.hxx | 27 ++++++------ extensions/source/ole/unoobjw.cxx | 15 +++---- extensions/source/ole/unotypewrapper.cxx | 4 +- .../source/update/check/updatecheckconfig.cxx | 5 ++- 7 files changed, 63 insertions(+), 58 deletions(-) (limited to 'extensions') diff --git a/extensions/source/config/ldap/ldapaccess.cxx b/extensions/source/config/ldap/ldapaccess.cxx index 8dcd911e7034..1f6667ce4851 100644 --- a/extensions/source/config/ldap/ldapaccess.cxx +++ b/extensions/source/config/ldap/ldapaccess.cxx @@ -23,6 +23,7 @@ #include #include #include +#include namespace extensions { namespace config { namespace ldap { @@ -131,8 +132,8 @@ void LdapConnection::connectSimple() // Do the bind #ifdef _WIN32 LdapErrCode retCode = ldap_simple_bind_sW(mConnection, - const_cast(SAL_W(mLdapDefinition.mAnonUser.getStr())), - const_cast(SAL_W(mLdapDefinition.mAnonCredentials.getStr())) ); + const_cast(o3tl::toW(mLdapDefinition.mAnonUser.getStr())), + const_cast(o3tl::toW(mLdapDefinition.mAnonCredentials.getStr())) ); #else LdapErrCode retCode = ldap_simple_bind_s(mConnection, OUStringToOString( mLdapDefinition.mAnonUser, RTL_TEXTENCODING_UTF8 ).getStr(), @@ -153,7 +154,7 @@ void LdapConnection::initConnection() if (mLdapDefinition.mPort == 0) mLdapDefinition.mPort = LDAP_PORT; #ifdef _WIN32 - mConnection = ldap_initW(const_cast(SAL_W(mLdapDefinition.mServer.getStr())), + mConnection = ldap_initW(const_cast(o3tl::toW(mLdapDefinition.mServer.getStr())), mLdapDefinition.mPort) ; #else mConnection = ldap_init(OUStringToOString( mLdapDefinition.mServer, RTL_TEXTENCODING_UTF8 ).getStr(), @@ -178,7 +179,7 @@ void LdapConnection::initConnection() LdapMessageHolder result; #ifdef _WIN32 LdapErrCode retCode = ldap_search_sW(mConnection, - const_cast(SAL_W(aUserDn.getStr())), + const_cast(o3tl::toW(aUserDn.getStr())), LDAP_SCOPE_BASE, const_cast( L"(objectclass=*)" ), nullptr, @@ -201,8 +202,8 @@ void LdapConnection::initConnection() while (attr) { PWCHAR * values = ldap_get_valuesW(mConnection, result.msg, attr); if (values) { - const OUString aAttr( SAL_U( attr ) ); - const OUString aValues( SAL_U( *values ) ); + const OUString aAttr( o3tl::toU( attr ) ); + const OUString aValues( o3tl::toU( *values ) ); data->emplace( aAttr, aValues ); ldap_value_freeW(values); } @@ -243,9 +244,9 @@ void LdapConnection::initConnection() #ifdef _WIN32 PWCHAR attributes [2] = { const_cast( L"1.1" ), nullptr }; LdapErrCode retCode = ldap_search_sW(mConnection, - const_cast(SAL_W(mLdapDefinition.mBaseDN.getStr())), + const_cast(o3tl::toW(mLdapDefinition.mBaseDN.getStr())), LDAP_SCOPE_SUBTREE, - const_cast(SAL_W(filter.makeStringAndClear().getStr())), attributes, 0, &result.msg) ; + const_cast(o3tl::toW(filter.makeStringAndClear().getStr())), attributes, 0, &result.msg) ; #else sal_Char * attributes [2] = { const_cast(LDAP_NO_ATTRS), nullptr }; LdapErrCode retCode = ldap_search_s(mConnection, @@ -262,7 +263,7 @@ void LdapConnection::initConnection() #ifdef _WIN32 PWCHAR charsDn = ldap_get_dnW(mConnection, entry) ; - userDn = OUString( SAL_U( charsDn ) ); + userDn = OUString( o3tl::toU( charsDn ) ); ldap_memfreeW(charsDn) ; #else sal_Char *charsDn = ldap_get_dn(mConnection, entry) ; diff --git a/extensions/source/ole/oleobjw.cxx b/extensions/source/ole/oleobjw.cxx index 3caab88a4765..c856992fbc96 100644 --- a/extensions/source/ole/oleobjw.cxx +++ b/extensions/source/ole/oleobjw.cxx @@ -18,12 +18,12 @@ */ #include "ole2uno.hxx" -#include "rtl/ustrbuf.hxx" +#include +#include - -#include "osl/diagnose.h" -#include "osl/doublecheckedlocking.h" -#include "osl/thread.h" +#include +#include +#include #include #include @@ -32,8 +32,8 @@ #include #include -#include "com/sun/star/bridge/oleautomation/NamedArgument.hpp" -#include "com/sun/star/bridge/oleautomation/PropertyPutArgument.hpp" +#include +#include #include #include @@ -459,7 +459,7 @@ Any SAL_CALL IUnknownWrapper_Impl::getValue( const OUString& aPropertyName ) if ( SUCCEEDED( pInfo->GetDocumentation( -1, &sName, nullptr, nullptr, nullptr ) ) ) { - OUString sTmp( SAL_U(LPCOLESTR(sName))); + OUString sTmp( o3tl::toU(LPCOLESTR(sName))); if ( sTmp.startsWith("_") ) sTmp = sTmp.copy(1); // do we own the memory for pTypeLib, msdn doc is vague @@ -470,7 +470,7 @@ Any SAL_CALL IUnknownWrapper_Impl::getValue( const OUString& aPropertyName ) { if ( SUCCEEDED( pTypeLib->GetDocumentation( -1, &sName, nullptr, nullptr, nullptr ) ) ) { - OUString sLibName( SAL_U(LPCOLESTR(sName))); + OUString sLibName( o3tl::toU(LPCOLESTR(sName))); m_sTypeName = sLibName.concat( "." ).concat( sTmp ); } @@ -538,13 +538,13 @@ Any SAL_CALL IUnknownWrapper_Impl::getValue( const OUString& aPropertyName ) case DISP_E_BADPARAMCOUNT: case DISP_E_BADVARTYPE: case DISP_E_EXCEPTION: - throw RuntimeException(OUString(SAL_U(excepinfo.bstrDescription))); + throw RuntimeException(OUString(o3tl::toU(excepinfo.bstrDescription))); break; case DISP_E_MEMBERNOTFOUND: - throw UnknownPropertyException(OUString(SAL_U(excepinfo.bstrDescription))); + throw UnknownPropertyException(OUString(o3tl::toU(excepinfo.bstrDescription))); break; default: - throw RuntimeException(OUString(SAL_U(excepinfo.bstrDescription))); + throw RuntimeException(OUString(o3tl::toU(excepinfo.bstrDescription))); break; } } @@ -1184,7 +1184,7 @@ void SAL_CALL IUnknownWrapper_Impl::initialize( const Sequence< Any >& aArgument CComBSTR defaultMemberName; if ( SUCCEEDED( pType->GetDocumentation(0, &defaultMemberName, nullptr, nullptr, nullptr ) ) ) { - OUString usName(SAL_U(LPCOLESTR(defaultMemberName))); + OUString usName(o3tl::toU(LPCOLESTR(defaultMemberName))); FuncDesc aDescGet(pType); FuncDesc aDescPut(pType); VarDesc aVarDesc(pType); @@ -1280,7 +1280,7 @@ uno::Any SAL_CALL IUnknownWrapper_Impl::directInvoke( const OUString& aName, con std::unique_ptr saNames(new OLECHAR*[nSizeAr]); OLECHAR ** pNames = saNames.get(); - pNames[0] = const_cast(SAL_W(aName.getStr())); + pNames[0] = const_cast(o3tl::toW(aName.getStr())); int cNamedArg = 0; for ( size_t nInd = 0; nInd < dispparams.cArgs; nInd++ ) @@ -1292,7 +1292,7 @@ uno::Any SAL_CALL IUnknownWrapper_Impl::directInvoke( const OUString& aName, con //We put the parameter names in reverse order into the array, //so we can use the DISPID array for DISPPARAMS::rgdispidNamedArgs //The first name in the array is the method name - pNames[nSizeAr - 1 - cNamedArg++] = const_cast(SAL_W(arg.Name.getStr())); + pNames[nSizeAr - 1 - cNamedArg++] = const_cast(o3tl::toW(arg.Name.getStr())); } } @@ -1419,7 +1419,7 @@ uno::Any SAL_CALL IUnknownWrapper_Impl::directInvoke( const OUString& aName, con break; case DISP_E_EXCEPTION: message = "[automation bridge]: "; - message += OUString(SAL_U(excepinfo.bstrDescription), + message += OUString(o3tl::toU(excepinfo.bstrDescription), ::SysStringLen(excepinfo.bstrDescription)); throw InvocationTargetException(message, Reference(), Any()); break; @@ -1719,7 +1719,7 @@ Any IUnknownWrapper_Impl::invokeWithDispIdComTlb(FuncDesc& aFuncDesc, std::unique_ptr saNames(new OLECHAR*[nSizeAr]); OLECHAR ** arNames = saNames.get(); - arNames[0] = const_cast(SAL_W(sFuncName.getStr())); + arNames[0] = const_cast(o3tl::toW(sFuncName.getStr())); int cNamedArg = 0; for (size_t iParams = 0; iParams < dispparams.cArgs; iParams ++) @@ -1731,7 +1731,7 @@ Any IUnknownWrapper_Impl::invokeWithDispIdComTlb(FuncDesc& aFuncDesc, //We put the parameter names in reverse order into the array, //so we can use the DISPID array for DISPPARAMS::rgdispidNamedArgs //The first name in the array is the method name - arNames[nSizeAr - 1 - cNamedArg++] = const_cast(SAL_W(arg.Name.getStr())); + arNames[nSizeAr - 1 - cNamedArg++] = const_cast(o3tl::toW(arg.Name.getStr())); } } @@ -2045,7 +2045,7 @@ Any IUnknownWrapper_Impl::invokeWithDispIdComTlb(FuncDesc& aFuncDesc, break; case DISP_E_EXCEPTION: message = "[automation bridge]: "; - message += OUString(SAL_U(excepinfo.bstrDescription), + message += OUString(o3tl::toU(excepinfo.bstrDescription), ::SysStringLen(excepinfo.bstrDescription)); throw InvocationTargetException(message, Reference(), Any()); @@ -2154,7 +2154,7 @@ void IUnknownWrapper_Impl::getFuncDescForInvoke(const OUString & sFuncName, bool IUnknownWrapper_Impl::getDispid(const OUString& sFuncName, DISPID * id) { OSL_ASSERT(m_spDispatch); - LPOLESTR lpsz = const_cast (SAL_W(sFuncName.getStr())); + LPOLESTR lpsz = const_cast (o3tl::toW(sFuncName.getStr())); HRESULT hr = m_spDispatch->GetIDsOfNames(IID_NULL, &lpsz, 1, LOCALE_USER_DEFAULT, id); return hr == S_OK; } @@ -2181,7 +2181,7 @@ void IUnknownWrapper_Impl::getFuncDesc(const OUString & sFuncName, FUNCDESC ** p //get the associated index and add an entry to the map //with the name sFuncName which differs in the casing of the letters to //the actual name as obtained from ITypeInfo - OUString sRealName(SAL_U(LPCOLESTR(memberName))); + OUString sRealName(o3tl::toU(LPCOLESTR(memberName))); cit itOrg = m_mapComFunc.find(sRealName); OSL_ASSERT(itOrg != m_mapComFunc.end()); // maybe this is a property, if so we need @@ -2246,7 +2246,7 @@ void IUnknownWrapper_Impl::getPropDesc(const OUString & sFuncName, FUNCDESC ** p //As opposed to getFuncDesc, we do not add the value because we would // need to find the get and set description for the property. This would //mean to iterate over all FUNCDESCs again. - p = m_mapComFunc.equal_range(OUString(SAL_U(LPCOLESTR(memberName)))); + p = m_mapComFunc.equal_range(OUString(o3tl::toU(LPCOLESTR(memberName)))); } } } @@ -2387,7 +2387,7 @@ void IUnknownWrapper_Impl::buildComTlbIndex() unsigned int pcNames=0; if( SUCCEEDED(pType->GetNames( funcDesc->memid, & memberName, 1, &pcNames))) { - OUString usName(SAL_U(LPCOLESTR(memberName))); + OUString usName(o3tl::toU(LPCOLESTR(memberName))); m_mapComFunc.emplace(usName, i); } else @@ -2414,7 +2414,7 @@ void IUnknownWrapper_Impl::buildComTlbIndex() { if (varDesc->varkind == VAR_DISPATCH) { - OUString usName(SAL_U(LPCOLESTR(memberName))); + OUString usName(o3tl::toU(LPCOLESTR(memberName))); m_mapComFunc.emplace(usName, i); } } diff --git a/extensions/source/ole/servprov.cxx b/extensions/source/ole/servprov.cxx index f3cacec755a7..4fa08a3a6181 100644 --- a/extensions/source/ole/servprov.cxx +++ b/extensions/source/ole/servprov.cxx @@ -28,6 +28,7 @@ #include #include #include +#include using namespace cppu; using namespace osl; @@ -537,7 +538,7 @@ Reference SAL_CALL OleClient_Impl::createInstance(const OUString& Se o2u_attachCurrentThread(); result = CLSIDFromProgID( - SAL_W(ServiceSpecifier.getStr()), //Pointer to the ProgID + o3tl::toW(ServiceSpecifier.getStr()), //Pointer to the ProgID &classId); //Pointer to the CLSID diff --git a/extensions/source/ole/unoconversionutilities.hxx b/extensions/source/ole/unoconversionutilities.hxx index 5b5612c42a1b..98f1885367d2 100644 --- a/extensions/source/ole/unoconversionutilities.hxx +++ b/extensions/source/ole/unoconversionutilities.hxx @@ -20,16 +20,17 @@ #define INCLUDED_EXTENSIONS_SOURCE_OLE_UNOCONVERSIONUTILITIES_HXX #include -#include "com/sun/star/script/XInvocationAdapterFactory.hpp" -#include "com/sun/star/script/XInvocationAdapterFactory2.hpp" -#include "com/sun/star/script/XTypeConverter.hpp" -#include "com/sun/star/script/FailReason.hpp" -#include "com/sun/star/bridge/oleautomation/Date.hpp" -#include "com/sun/star/bridge/oleautomation/Currency.hpp" -#include "com/sun/star/bridge/oleautomation/SCode.hpp" -#include "com/sun/star/bridge/oleautomation/Decimal.hpp" -#include "typelib/typedescription.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include #include "ole2uno.hxx" #include @@ -812,7 +813,7 @@ void UnoConversionUtilities::anyToVariant(VARIANT* pVariant, const Any& rAny) if (rAny >>= value) { pVariant->vt = VT_BSTR; - pVariant->bstrVal = SysAllocString(SAL_W(value.getStr())); + pVariant->bstrVal = SysAllocString(o3tl::toW(value.getStr())); } else { @@ -1507,7 +1508,7 @@ void UnoConversionUtilities::variantToAny( const VARIANT* pVariant, Any& rAny } case VT_BSTR: { - OUString b(SAL_U(var.bstrVal)); + OUString b(o3tl::toU(var.bstrVal)); rAny.setValue( &b, cppu::UnoType::get()); break; } @@ -1528,7 +1529,7 @@ void UnoConversionUtilities::variantToAny( const VARIANT* pVariant, Any& rAny { throw CannotConvertException( "[automation bridge]UnoConversionUtilities::variantToAny \n" - "A UNO type with the name: " + OUString(SAL_U(LPCOLESTR(sName))) + + "A UNO type with the name: " + OUString(o3tl::toU(LPCOLESTR(sName))) + "does not exist!", nullptr, TypeClass_UNKNOWN, FailReason::TYPE_NOT_SUPPORTED,0); } @@ -1992,7 +1993,7 @@ void UnoConversionUtilities::dispatchExObject2Sequence( const VARIANTARG* pva for( sal_Int32 i= 0; i< length; i++) { OUString ousIndex=OUString::number( i); - OLECHAR* sindex = const_cast(SAL_W(ousIndex.getStr())); + OLECHAR* sindex = const_cast(o3tl::toW(ousIndex.getStr())); if( FAILED( hr= pdispEx->GetIDsOfNames(IID_NULL, &sindex , 1, LOCALE_USER_DEFAULT, &dispid))) { diff --git a/extensions/source/ole/unoobjw.cxx b/extensions/source/ole/unoobjw.cxx index cb2634ac6a87..f3355d2acf21 100644 --- a/extensions/source/ole/unoobjw.cxx +++ b/extensions/source/ole/unoobjw.cxx @@ -45,6 +45,7 @@ #include #include #include +#include #include "comifaces.hxx" #include "jscriptclasses.hxx" @@ -84,7 +85,7 @@ static void writeExcepinfo(EXCEPINFO * pInfo, const OUString& message) { pInfo->wCode = UNO_2_OLE_EXCEPTIONCODE; pInfo->bstrSource = SysAllocString(L"[automation bridge] "); - pInfo->bstrDescription = SysAllocString(SAL_W(message.getStr())); + pInfo->bstrDescription = SysAllocString(o3tl::toW(message.getStr())); } } @@ -219,7 +220,7 @@ STDMETHODIMP InterfaceOleWrapper_Impl::GetIDsOfNames(REFIID /*riid*/, if (m_xInvocation.is() && (cNames > 0)) { - OUString name(SAL_U(rgszNames[0])); + OUString name(o3tl::toU(rgszNames[0])); NameToIdMap::iterator iter = m_nameToDispIdMap.find(name); if (iter == m_nameToDispIdMap.end()) @@ -538,7 +539,7 @@ bool getType( const BSTR name, Type & type) { bool ret = false; typelib_TypeDescription * pDesc= nullptr; - OUString str(SAL_U(name)); + OUString str(o3tl::toU(name)); typelib_typedescription_getByName( &pDesc, str.pData ); if( pDesc) { @@ -1023,7 +1024,7 @@ HRESULT InterfaceOleWrapper_Impl::doSetProperty( DISPPARAMS * /*pdispparams*/, V pexcepinfo->wCode = UNO_2_OLE_EXCEPTIONCODE; pexcepinfo->bstrSource = SysAllocString(L"any ONE component"); pexcepinfo->bstrDescription = SysAllocString( - SAL_W(org.getValueType().getTypeName().getStr())); + o3tl::toW(org.getValueType().getTypeName().getStr())); } ret = DISP_E_EXCEPTION; } @@ -1085,7 +1086,7 @@ HRESULT InterfaceOleWrapper_Impl::InvokeGeneral( DISPID dispidMember, unsigned s CComVariant arg; if( pdispparams->cArgs == 1 && SUCCEEDED( arg.ChangeType( VT_BSTR, &pdispparams->rgvarg[0])) ) { - Reference classStruct= xRefl->forName(SAL_U(arg.bstrVal)); + Reference classStruct= xRefl->forName(o3tl::toU(arg.bstrVal)); if( classStruct.is()) { Any anyStruct; @@ -1119,7 +1120,7 @@ HRESULT InterfaceOleWrapper_Impl::InvokeGeneral( DISPID dispidMember, unsigned s if (!getType(arg.bstrVal, type)) { writeExcepinfo(pexcepinfo, "[automation bridge] A UNO type with the name " + - OUString(SAL_U(arg.bstrVal)) + " does not exist!"); + OUString(o3tl::toU(arg.bstrVal)) + " does not exist!"); return DISP_E_EXCEPTION; } @@ -1255,7 +1256,7 @@ STDMETHODIMP UnoObjectWrapperRemoteOpt::GetIDsOfNames ( REFIID /*riid*/, OLECHA if (m_xInvocation.is() && (cNames > 0)) { - OUString name(SAL_U(rgszNames[0])); + OUString name(o3tl::toU(rgszNames[0])); // has this name been determined as "bad" BadNameMap::iterator badIter= m_badNameMap.find( name); if( badIter == m_badNameMap.end() ) diff --git a/extensions/source/ole/unotypewrapper.cxx b/extensions/source/ole/unotypewrapper.cxx index e719e8c66f43..fa12a9636e53 100644 --- a/extensions/source/ole/unotypewrapper.cxx +++ b/extensions/source/ole/unotypewrapper.cxx @@ -20,7 +20,7 @@ #include "unotypewrapper.hxx" #include "rtl/ustring.hxx" #include - +#include bool createUnoTypeWrapper(BSTR sTypeName, VARIANT * pVar) { @@ -47,7 +47,7 @@ bool createUnoTypeWrapper(BSTR sTypeName, VARIANT * pVar) bool createUnoTypeWrapper(const OUString& sTypeName, VARIANT * pVar) { - CComBSTR bstr(SAL_W(sTypeName.getStr())); + CComBSTR bstr(o3tl::toW(sTypeName.getStr())); return createUnoTypeWrapper(bstr, pVar); } diff --git a/extensions/source/update/check/updatecheckconfig.cxx b/extensions/source/update/check/updatecheckconfig.cxx index 81d94c0c1f63..26967b7e55c9 100644 --- a/extensions/source/update/check/updatecheckconfig.cxx +++ b/extensions/source/update/check/updatecheckconfig.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef _WIN32 #ifdef _MSC_VER @@ -169,7 +170,7 @@ OUString UpdateCheckConfig::getDownloadsDirectory() if (SHGetKnownFolderPath(FOLDERID_Downloads, 0, nullptr, &szPath) == S_OK) { - aRet = SAL_U(szPath); + aRet = o3tl::toU(szPath); CoTaskMemFree(szPath); osl::FileBase::getFileURLFromSystemPath( aRet, aRet ); } @@ -197,7 +198,7 @@ OUString UpdateCheckConfig::getAllUsersDirectory() if (TRUE == SHGetSpecialFolderPathW(nullptr, szPath, CSIDL_COMMON_DOCUMENTS, true)) { - aRet = SAL_U(szPath); + aRet = o3tl::toU(szPath); osl::FileBase::getFileURLFromSystemPath( aRet, aRet ); } #else -- cgit