diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-12-17 14:17:05 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-12-17 15:47:51 +0100 |
commit | 5e636ec653ce798935ed85aeef96a6fcff893729 (patch) | |
tree | 516b3aa96e9a8967fafa9b47ad384c9629c545d0 | |
parent | 9f2e8017074452888871c9b78d9326cc4f659ac3 (diff) |
Various minor loplugin fixes (macOS ARM64)
Change-Id: I32276e3ceafa1e65671ba395de3f6fa587179d79
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107878
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
4 files changed, 123 insertions, 79 deletions
diff --git a/bridges/source/cpp_uno/gcc3_linux_aarch64/abi.cxx b/bridges/source/cpp_uno/gcc3_linux_aarch64/abi.cxx index 0fce88db6749..8db8c37140e5 100644 --- a/bridges/source/cpp_uno/gcc3_linux_aarch64/abi.cxx +++ b/bridges/source/cpp_uno/gcc3_linux_aarch64/abi.cxx @@ -45,7 +45,7 @@ namespace { OUString toUnoName(char const * name) { - assert(name != 0); + assert(name != nullptr); OUStringBuffer b; bool scoped = *name == 'N'; if (scoped) { @@ -74,7 +74,7 @@ OUString toUnoName(char const * name) { class Rtti { public: - Rtti(): app_(dlopen(0, RTLD_LAZY)) {} + Rtti(): app_(dlopen(nullptr, RTLD_LAZY)) {} ~Rtti() { dlclose(app_); } @@ -107,7 +107,7 @@ std::type_info * Rtti::getRtti(typelib_TypeDescription const & type) { OString sym(b.makeStringAndClear()); std::type_info * rtti = static_cast<std::type_info *>( dlsym(app_, sym.getStr())); - if (rtti == 0) { + if (rtti == nullptr) { char const * rttiName = strdup(sym.getStr() + std::strlen("_ZTI")); if (rttiName == nullptr) { throw std::bad_alloc(); @@ -123,7 +123,7 @@ std::type_info * Rtti::getRtti(typelib_TypeDescription const & type) { typelib_CompoundTypeDescription const & ctd = reinterpret_cast<typelib_CompoundTypeDescription const &>( type); - if (ctd.pBaseTypeDescription == 0) { + if (ctd.pBaseTypeDescription == nullptr) { rtti = new __cxxabiv1::__class_type_info(rttiName); } else { std::type_info * base = getRtti( @@ -201,9 +201,9 @@ extern "C" void _GLIBCXX_CDTOR_CALLABI deleteException(void * exception) { #endif assert(header->exceptionDestructor == &deleteException); OUString unoName(toUnoName(header->exceptionType->name())); - typelib_TypeDescription * td = 0; + typelib_TypeDescription * td = nullptr; typelib_typedescription_getByName(&td, unoName.pData); - assert(td != 0); + assert(td != nullptr); uno_destructData(exception, td, &css::uno::cpp_release); typelib_typedescription_release(td); } @@ -214,7 +214,7 @@ enum StructKind { }; StructKind getStructKind(typelib_CompoundTypeDescription const * type) { - StructKind k = type->pBaseTypeDescription == 0 + StructKind k = type->pBaseTypeDescription == nullptr ? STRUCT_KIND_EMPTY : getStructKind(type->pBaseTypeDescription); for (sal_Int32 i = 0; i != type->nMembers; ++i) { StructKind k2 = StructKind(); @@ -246,7 +246,7 @@ StructKind getStructKind(typelib_CompoundTypeDescription const * type) { break; case typelib_TypeClass_STRUCT: { - typelib_TypeDescription * td = 0; + typelib_TypeDescription * td = nullptr; TYPELIB_DANGER_GET(&td, type->ppTypeRefs[i]); k2 = getStructKind( reinterpret_cast<typelib_CompoundTypeDescription const *>( @@ -289,12 +289,12 @@ namespace abi_aarch64 { void mapException( __cxxabiv1::__cxa_exception * exception, std::type_info const * type, uno_Any * any, uno_Mapping * mapping) { - assert(exception != 0); + assert(exception != nullptr); assert(type != nullptr); OUString unoName(toUnoName(type->name())); - typelib_TypeDescription * td = 0; + typelib_TypeDescription * td = nullptr; typelib_typedescription_getByName(&td, unoName.pData); - if (td == 0) { + if (td == nullptr) { css::uno::RuntimeException e("exception type not found: " + unoName); uno_type_any_constructAndConvert( any, &e, @@ -307,15 +307,15 @@ void mapException( } void raiseException(uno_Any * any, uno_Mapping * mapping) { - typelib_TypeDescription * td = 0; + typelib_TypeDescription * td = nullptr; TYPELIB_DANGER_GET(&td, any->pType); - if (td == 0) { + if (td == nullptr) { throw css::uno::RuntimeException( - "no typedescription for " + OUString(any->pType->pTypeName)); + "no typedescription for " + OUString::unacquired(&any->pType->pTypeName)); } void * exc = __cxxabiv1::__cxa_allocate_exception(td->nSize); uno_copyAndConvertData(exc, any->pData, td, mapping); - uno_any_destruct(any, 0); + uno_any_destruct(any, nullptr); std::type_info * rtti = getRtti(*td); TYPELIB_DANGER_RELEASE(td); __cxxabiv1::__cxa_throw(exc, rtti, deleteException); diff --git a/bridges/source/cpp_uno/gcc3_linux_aarch64/cpp2uno.cxx b/bridges/source/cpp_uno/gcc3_linux_aarch64/cpp2uno.cxx index 830c42eb52f8..77fa3c03bbf4 100644 --- a/bridges/source/cpp_uno/gcc3_linux_aarch64/cpp2uno.cxx +++ b/bridges/source/cpp_uno/gcc3_linux_aarch64/cpp2uno.cxx @@ -41,8 +41,7 @@ #include <vtablefactory.hxx> #include "abi.hxx" - -extern "C" void vtableSlotCall(); +#include "vtablecall.hxx" namespace { @@ -53,16 +52,16 @@ void call( typelib_MethodParameter * parameters, unsigned long * gpr, unsigned long * fpr, unsigned long * stack, void * indirectRet) { - typelib_TypeDescription * rtd = 0; - if (returnType != 0) { + typelib_TypeDescription * rtd = nullptr; + if (returnType != nullptr) { TYPELIB_DANGER_GET(&rtd, returnType); } - abi_aarch64::ReturnKind retKind = rtd == 0 + abi_aarch64::ReturnKind retKind = rtd == nullptr ? abi_aarch64::RETURN_KIND_REG : abi_aarch64::getReturnKind(rtd); - bool retConv = rtd != 0 + bool retConv = rtd != nullptr && bridges::cpp_uno::shared::relatesToInterfaceType(rtd); void * retin = retKind == abi_aarch64::RETURN_KIND_INDIRECT && !retConv - ? indirectRet : rtd == 0 ? 0 : alloca(rtd->nSize); + ? indirectRet : rtd == nullptr ? nullptr : alloca(rtd->nSize); void ** args = static_cast< void ** >(alloca(count * sizeof (void *))); void ** cppArgs = static_cast< void ** >(alloca(count * sizeof (void *))); typelib_TypeDescription ** argtds = static_cast<typelib_TypeDescription **>( @@ -88,7 +87,7 @@ void call( } else { - args[i] = reinterpret_cast<void **>(reinterpret_cast<uintptr_t>(stack + sp) + subsp); + args[i] = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(stack + sp) + subsp); subsp += 1; if (subsp == 8) { @@ -113,7 +112,7 @@ void call( sp++; subsp = 0; } - args[i] = reinterpret_cast<void **>(reinterpret_cast<uintptr_t>(stack + sp) + subsp); + args[i] = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(stack + sp) + subsp); subsp += 2; if (subsp == 8) { @@ -138,7 +137,7 @@ void call( sp++; subsp = 0; } - args[i] = reinterpret_cast<void **>(reinterpret_cast<uintptr_t>(stack + sp) + subsp); + args[i] = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(stack + sp) + subsp); subsp += 4; if (subsp == 8) { @@ -179,7 +178,7 @@ void call( sp++; subsp = 0; } - args[i] = reinterpret_cast<void **>(reinterpret_cast<uintptr_t>(stack + sp) + subsp); + args[i] = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(stack + sp) + subsp); subsp += 4; if (subsp == 8) { @@ -226,7 +225,7 @@ void call( default: assert(false); } - argtds[i] = 0; + argtds[i] = nullptr; } else { #ifdef MACOSX if (subsp > 0) @@ -237,7 +236,7 @@ void call( #endif cppArgs[i] = reinterpret_cast<void *>( ngpr == 8 ? stack[sp++] : gpr[ngpr++]); - typelib_TypeDescription * ptd = 0; + typelib_TypeDescription * ptd = nullptr; TYPELIB_DANGER_GET(&ptd, parameters[i].pTypeRef); if (!parameters[i].bIn) { args[i] = alloca(ptd->nSize); @@ -249,7 +248,7 @@ void call( argtds[i] = ptd; } else { args[i] = cppArgs[i]; - argtds[i] = 0; + argtds[i] = nullptr; TYPELIB_DANGER_RELEASE(ptd); } } @@ -258,22 +257,22 @@ void call( uno_Any * pexc = &exc; proxy->getUnoI()->pDispatcher( proxy->getUnoI(), description.get(), retin, args, &pexc); - if (pexc != 0) { + if (pexc != nullptr) { for (sal_Int32 i = 0; i != count; ++i) { - if (argtds[i] != 0) { + if (argtds[i] != nullptr) { if (parameters[i].bIn) { - uno_destructData(args[i], argtds[i], 0); + uno_destructData(args[i], argtds[i], nullptr); } TYPELIB_DANGER_RELEASE(argtds[i]); } } - if (rtd != 0) { + if (rtd != nullptr) { TYPELIB_DANGER_RELEASE(rtd); } abi_aarch64::raiseException(&exc, proxy->getBridge()->getUno2Cpp()); } for (sal_Int32 i = 0; i != count; ++i) { - if (argtds[i] != 0) { + if (argtds[i] != nullptr) { if (parameters[i].bOut) { uno_destructData( cppArgs[i], argtds[i], @@ -282,14 +281,14 @@ void call( cppArgs[i], args[i], argtds[i], proxy->getBridge()->getUno2Cpp()); } - uno_destructData(args[i], argtds[i], 0); + uno_destructData(args[i], argtds[i], nullptr); TYPELIB_DANGER_RELEASE(argtds[i]); } } - void * retout = 0; // avoid false -Werror=maybe-uninitialized + void * retout = nullptr; // avoid false -Werror=maybe-uninitialized switch (retKind) { case abi_aarch64::RETURN_KIND_REG: - switch (rtd == 0 ? typelib_TypeClass_VOID : rtd->eTypeClass) { + switch (rtd == nullptr ? typelib_TypeClass_VOID : rtd->eTypeClass) { case typelib_TypeClass_VOID: break; case typelib_TypeClass_BOOLEAN: @@ -322,7 +321,7 @@ void call( } break; case abi_aarch64::RETURN_KIND_HFA_FLOAT: - assert(rtd != 0); + assert(rtd != nullptr); switch (rtd->nSize) { case 16: std::memcpy(fpr + 3, static_cast<char *>(retin) + 12, 4); @@ -342,7 +341,7 @@ void call( assert(!retConv); break; case abi_aarch64::RETURN_KIND_HFA_DOUBLE: - assert(rtd != 0); + assert(rtd != nullptr); std::memcpy(fpr, retin, rtd->nSize); assert(!retConv); break; @@ -353,14 +352,16 @@ void call( if (retConv) { uno_copyAndConvertData( retout, retin, rtd, proxy->getBridge()->getUno2Cpp()); - uno_destructData(retin, rtd, 0); + uno_destructData(retin, rtd, nullptr); } - if (rtd != 0) { + if (rtd != nullptr) { TYPELIB_DANGER_RELEASE(rtd); } } -extern "C" void vtableCall( +} + +void vtableCall( sal_Int32 functionIndex, sal_Int32 vtableOffset, unsigned long * gpr, unsigned long * fpr, unsigned long * stack, void * indirectRet) @@ -380,15 +381,15 @@ extern "C" void vtableCall( proxy, desc, reinterpret_cast<typelib_InterfaceAttributeTypeDescription *>( desc.get())->pAttributeTypeRef, - 0, 0, gpr, fpr, stack, indirectRet); + 0, nullptr, gpr, fpr, stack, indirectRet); } else { // Setter: typelib_MethodParameter param = { - 0, + nullptr, reinterpret_cast<typelib_InterfaceAttributeTypeDescription *>( desc.get())->pAttributeTypeRef, true, false }; - call(proxy, desc, 0, 1, ¶m, gpr, fpr, stack, indirectRet); + call(proxy, desc, nullptr, 1, ¶m, gpr, fpr, stack, indirectRet); } break; case typelib_TypeClass_INTERFACE_METHOD: @@ -401,21 +402,21 @@ extern "C" void vtableCall( break; case 0: { - typelib_TypeDescription * td = 0; + typelib_TypeDescription * td = nullptr; TYPELIB_DANGER_GET( &td, (reinterpret_cast<css::uno::Type *>(gpr[1]) ->getTypeLibType())); - if (td != 0 && td->eTypeClass == typelib_TypeClass_INTERFACE) { - css::uno::XInterface * ifc = 0; + if (td != nullptr && td->eTypeClass == typelib_TypeClass_INTERFACE) { + css::uno::XInterface * ifc = nullptr; proxy->getBridge()->getCppEnv()->getRegisteredInterface( proxy->getBridge()->getCppEnv(), reinterpret_cast<void **>(&ifc), proxy->getOid().pData, reinterpret_cast<typelib_InterfaceTypeDescription *>( td)); - if (ifc != 0) { + if (ifc != nullptr) { uno_any_construct( - reinterpret_cast<uno_Any *>(indirectRet), &ifc, td, + static_cast<uno_Any *>(indirectRet), &ifc, td, reinterpret_cast<uno_AcquireFunc>( css::uno::cpp_acquire)); ifc->release(); @@ -443,6 +444,8 @@ extern "C" void vtableCall( } } +namespace { + std::size_t const codeSnippetSize = 8 * 4; unsigned char * generateCodeSnippet( @@ -490,8 +493,8 @@ bridges::cpp_uno::shared::VtableFactory::initializeBlock( typelib_InterfaceTypeDescription *) { Slot * slots = mapBlockToVtable(block); - slots[-2].fn = 0; - slots[-1].fn = 0; + slots[-2].fn = nullptr; + slots[-1].fn = nullptr; return slots + slotCount; } @@ -509,9 +512,9 @@ unsigned char * bridges::cpp_uno::shared::VtableFactory::addLocalFunctions( (*slots) -= functionCount; Slot * s = *slots; for (sal_Int32 i = 0; i != type->nMembers; ++i) { - typelib_TypeDescription * td = 0; + typelib_TypeDescription * td = nullptr; TYPELIB_DANGER_GET(&td, type->ppMembers[i]); - assert(td != 0); + assert(td != nullptr); switch (td->eTypeClass) { case typelib_TypeClass_INTERFACE_ATTRIBUTE: { @@ -551,7 +554,15 @@ void bridges::cpp_uno::shared::VtableFactory::flushCode( RTLD_DEFAULT, "__clear_cache"); (*clear_cache)(begin, end); #else - __builtin___clear_cache((char*)begin, (char*)end); + // GCC clarified with + // <http://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a90b0cdd444f6dde1084a439862cf507f6d3b2ae> + // "extend.texi (__clear_cache): Correct signature" that __builtin___clear_cache takes void* + // parameters, while Clang uses char* ever since + // <https://github.com/llvm/llvm-project/commit/c491a8d4577052bc6b3b4c72a7db6a7cfcbc2ed0> "Add + // support for __builtin___clear_cache in Clang": + __builtin___clear_cache( + reinterpret_cast<char *>(const_cast<unsigned char *>(begin)), + reinterpret_cast<char *>(const_cast<unsigned char *>(end))); #endif } diff --git a/bridges/source/cpp_uno/gcc3_linux_aarch64/uno2cpp.cxx b/bridges/source/cpp_uno/gcc3_linux_aarch64/uno2cpp.cxx index 14e4afa46cc0..57beb6dfa106 100644 --- a/bridges/source/cpp_uno/gcc3_linux_aarch64/uno2cpp.cxx +++ b/bridges/source/cpp_uno/gcc3_linux_aarch64/uno2cpp.cxx @@ -131,7 +131,7 @@ void call( typelib_MethodParameter * parameters, void * returnValue, void ** arguments, uno_Any ** exception) { - typelib_TypeDescription * rtd = 0; + typelib_TypeDescription * rtd = nullptr; TYPELIB_DANGER_GET(&rtd, returnType); abi_aarch64::ReturnKind retKind = abi_aarch64::getReturnKind(rtd); bool retConv = bridges::cpp_uno::shared::relatesToInterfaceType(rtd); @@ -157,15 +157,15 @@ void call( if (!parameters[i].bOut && bridges::cpp_uno::shared::isSimpleType(parameters[i].pTypeRef)) { - cppArgs[i] = 0; + cppArgs[i] = nullptr; switch (parameters[i].pTypeRef->eTypeClass) { case typelib_TypeClass_BOOLEAN: pushArgument( #ifdef MACOSX parameters[i].pTypeRef->eTypeClass, &subsp, #endif - *static_cast<sal_Bool *>(arguments[i]), stack, &sp, gpr, - &ngpr); + static_cast<unsigned long>(*static_cast<sal_Bool *>(arguments[i])), stack, &sp, + gpr, &ngpr); break; case typelib_TypeClass_BYTE: pushArgument( @@ -252,7 +252,7 @@ void call( assert(false); } } else { - typelib_TypeDescription * ptd = 0; + typelib_TypeDescription * ptd = nullptr; TYPELIB_DANGER_GET(&ptd, parameters[i].pTypeRef); if (!parameters[i].bIn) { cppArgs[i] = alloca(ptd->nSize); @@ -277,7 +277,7 @@ void call( reinterpret_cast<unsigned long>(cppArgs[i]), stack, &sp, gpr, &ngpr); } else { - cppArgs[i] = 0; + cppArgs[i] = nullptr; pushArgument( #ifdef MACOSX typelib_TypeClass_HYPER, &subsp, @@ -339,7 +339,7 @@ void call( __cxxabiv1::__cxa_current_exception_type(), *exception, proxy->getBridge()->getCpp2Uno()); for (sal_Int32 i = 0; i != count; ++i) { - if (cppArgs[i] != 0) { + if (cppArgs[i] != nullptr) { uno_destructData( cppArgs[i], ptds[i], reinterpret_cast<uno_ReleaseFunc>(css::uno::cpp_release)); @@ -349,12 +349,12 @@ void call( TYPELIB_DANGER_RELEASE(rtd); return; } - *exception = 0; + *exception = nullptr; for (sal_Int32 i = 0; i != count; ++i) { - if (cppArgs[i] != 0) { + if (cppArgs[i] != nullptr) { if (parameters[i].bOut) { if (parameters[i].bIn) { - uno_destructData(arguments[i], ptds[i], 0); + uno_destructData(arguments[i], ptds[i], nullptr); } uno_copyAndConvertData( arguments[i], cppArgs[i], ptds[i], @@ -442,14 +442,14 @@ void unoInterfaceProxyDispatch( typelib_InterfaceAttributeTypeDescription const *>( pMemberDescr); VtableSlot slot(getVtableSlot(atd)); - if (pReturn != 0) { // getter + if (pReturn != nullptr) { // getter call( - proxy, slot, atd->pAttributeTypeRef, 0, 0, pReturn, pArgs, + proxy, slot, atd->pAttributeTypeRef, 0, nullptr, pReturn, pArgs, ppException); } else { // setter typelib_MethodParameter param = { - 0, atd->pAttributeTypeRef, true, false }; - typelib_TypeDescriptionReference * rtd = 0; + nullptr, atd->pAttributeTypeRef, true, false }; + typelib_TypeDescriptionReference * rtd = nullptr; typelib_typedescriptionreference_new( &rtd, typelib_TypeClass_VOID, OUString("void").pData); slot.index += 1; @@ -468,33 +468,33 @@ void unoInterfaceProxyDispatch( switch (slot.index) { case 1: pUnoI->acquire(pUnoI); - *ppException = 0; + *ppException = nullptr; break; case 2: pUnoI->release(pUnoI); - *ppException = 0; + *ppException = nullptr; break; case 0: { - typelib_TypeDescription * td = 0; + typelib_TypeDescription * td = nullptr; TYPELIB_DANGER_GET( &td, - (reinterpret_cast<css::uno::Type *>(pArgs[0]) + (static_cast<css::uno::Type *>(pArgs[0]) ->getTypeLibType())); - if (td != 0) { - uno_Interface * ifc = 0; + if (td != nullptr) { + uno_Interface * ifc = nullptr; proxy->pBridge->getUnoEnv()->getRegisteredInterface( proxy->pBridge->getUnoEnv(), reinterpret_cast<void **>(&ifc), proxy->oid.pData, reinterpret_cast< typelib_InterfaceTypeDescription *>(td)); - if (ifc != 0) { + if (ifc != nullptr) { uno_any_construct( - reinterpret_cast<uno_Any *>(pReturn), &ifc, td, - 0); + static_cast<uno_Any *>(pReturn), &ifc, td, + nullptr); ifc->release(ifc); TYPELIB_DANGER_RELEASE(td); - *ppException = 0; + *ppException = nullptr; break; } TYPELIB_DANGER_RELEASE(td); diff --git a/bridges/source/cpp_uno/gcc3_linux_aarch64/vtablecall.hxx b/bridges/source/cpp_uno/gcc3_linux_aarch64/vtablecall.hxx new file mode 100644 index 000000000000..6ec92687c4ae --- /dev/null +++ b/bridges/source/cpp_uno/gcc3_linux_aarch64/vtablecall.hxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> + +#include <sal/types.h> + +extern "C" { +void vtableCall(sal_Int32 functionIndex, sal_Int32 vtableOffset, unsigned long* gpr, + unsigned long* fpr, unsigned long* stack, void* indirectRet); + +void vtableSlotCall(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |