wsd: reduce directives for unused variable supression

We use [[maybe_unused]] to reduce explicit supression
especially under compile-time directives.

Change-Id: Ic5f3f3227a80efe52097cb35520d05b9cdaacb42
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
pull/8503/head
Ashod Nakashian 2024-03-06 06:14:07 -05:00 committed by Ashod Nakashian
parent 4a3e10e4a9
commit d57baeb906
12 changed files with 45 additions and 93 deletions

View File

@ -15,14 +15,8 @@
#include <common/TraceEvent.hpp>
void TraceEvent::emitOneRecordingIfEnabled(const std::string &recording)
{
(void) recording;
}
void TraceEvent::emitOneRecordingIfEnabled([[maybe_unused]] const std::string& recording) {}
void TraceEvent::emitOneRecording(const std::string &recording)
{
(void) recording;
}
void TraceEvent::emitOneRecording([[maybe_unused]] const std::string& recording) {}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -72,18 +72,14 @@ namespace RenderTiles
return nextId;
}
bool doRender(std::shared_ptr<lok::Document> document,
DeltaGenerator &deltaGen,
TileCombined &tileCombined,
ThreadPool &pngPool,
const std::function<void (unsigned char *data,
int offsetX, int offsetY,
size_t pixmapWidth, size_t pixmapHeight,
int pixelWidth, int pixelHeight,
LibreOfficeKitTileMode mode)>& blendWatermark,
const std::function<void (const char *buffer, size_t length)>& outputMessage,
unsigned mobileAppDocId,
int canonicalViewId, bool dumpTiles)
bool doRender(
std::shared_ptr<lok::Document> document, DeltaGenerator& deltaGen,
TileCombined& tileCombined, ThreadPool& pngPool,
const std::function<void(unsigned char* data, int offsetX, int offsetY, size_t pixmapWidth,
size_t pixmapHeight, int pixelWidth, int pixelHeight,
LibreOfficeKitTileMode mode)>& blendWatermark,
const std::function<void(const char* buffer, size_t length)>& outputMessage,
[[maybe_unused]] unsigned mobileAppDocId, int canonicalViewId, bool dumpTiles)
{
const auto& tiles = tileCombined.getTiles();
@ -145,8 +141,6 @@ namespace RenderTiles
<< renderArea.getWidth() << ", " << renderArea.getHeight() << ") "
<< " took " << elapsedUs << " (" << area / elapsedUs.count() << " MP/s).");
(void) mobileAppDocId;
const auto mode = static_cast<LibreOfficeKitTileMode>(document->getTileMode());
const size_t pixmapSize = 4 * pixmapWidth * pixmapHeight;

View File

@ -102,10 +102,8 @@ static void handleSysSignal(int /* signal */,
namespace Seccomp {
bool lockdown(Type type)
bool lockdown([[maybe_unused]] Type type)
{
(void)type; // so far just the kit.
#if DISABLE_SECCOMP == 0
#define ACCEPT_SYSCALL(name) \
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, __NR_##name, 0, 1), \

View File

@ -105,7 +105,7 @@ void requestShutdown()
#endif
#endif // !IOS
void checkDumpGlobalState(GlobalDumpStateFn dumpState)
void checkDumpGlobalState([[maybe_unused]] GlobalDumpStateFn dumpState)
{
#if !MOBILEAPP
assert(dumpState && "Invalid callback for checkDumpGlobalState");
@ -114,12 +114,10 @@ void requestShutdown()
DumpGlobalState = false;
dumpState();
}
#else
(void) dumpState;
#endif
}
void checkForwardSigUsr2(ForwardSigUsr2Fn forwardSigUsr2)
void checkForwardSigUsr2([[maybe_unused]] ForwardSigUsr2Fn forwardSigUsr2)
{
#if !MOBILEAPP
assert(forwardSigUsr2 && "Invalid callback for checkForwardSigUsr2");
@ -128,8 +126,6 @@ void requestShutdown()
ForwardSigUsr2Flag = false;
forwardSigUsr2();
}
#else
(void) forwardSigUsr2;
#endif
}

View File

@ -54,7 +54,8 @@ std::condition_variable TimeoutConditionVariable;
/// Controls whether experimental features/behavior is enabled or not.
bool EnableExperimental = false;
UnitBase** UnitBase::linkAndCreateUnit(UnitType type, const std::string& unitLibPath)
UnitBase** UnitBase::linkAndCreateUnit([[maybe_unused]] UnitType type,
[[maybe_unused]] const std::string& unitLibPath)
{
#if !MOBILEAPP
DlHandle = dlopen(unitLibPath.c_str(), RTLD_GLOBAL|RTLD_NOW);
@ -124,9 +125,6 @@ UnitBase** UnitBase::linkAndCreateUnit(UnitType type, const std::string& unitLib
return new UnitBase* [2] { hooks, nullptr };
LOG_ERR("No wsd unit-tests found in " << unitLibPath);
#else
(void) type;
(void) unitLibPath;
#endif
return nullptr;

View File

@ -227,21 +227,16 @@ namespace Util
#endif
/// Assert that a lock is already taken.
template <typename T>
void assertIsLocked(const T& lock)
template <typename T> void assertIsLocked([[maybe_unused]] const T& lock)
{
#ifdef NDEBUG
(void) lock;
#else
#ifndef NDEBUG
assert(lock.owns_lock());
#endif
}
inline void assertIsLocked(std::mutex& mtx)
inline void assertIsLocked([[maybe_unused]] std::mutex& mtx)
{
#ifdef NDEBUG
(void) mtx;
#else
#ifndef NDEBUG
assert(!mtx.try_lock());
#endif
}

View File

@ -62,10 +62,9 @@ inline int isInContainer()
return 0;
}
inline int hasCorrectUID(const char *appName)
inline int hasCorrectUID([[maybe_unused]] const char* appName)
{
#if ENABLE_DEBUG
(void)appName;
return 1; // insecure but easy to use.
#else
if (hasUID(COOL_USER_ID))

View File

@ -325,24 +325,21 @@ class DeltaGenerator {
DeltaData(const DeltaData&) = delete;
DeltaData& operator=(const DeltaData&) = delete;
DeltaData (TileWireId wid,
unsigned char* pixmap, size_t startX, size_t startY,
int width, int height,
const TileLocation &loc, int bufferWidth, int bufferHeight
) :
_loc(loc),
_inUse(false),
_wid(wid),
DeltaData(TileWireId wid, unsigned char* pixmap, size_t startX, size_t startY, int width,
int height, const TileLocation& loc, int bufferWidth,
[[maybe_unused]] int bufferHeight)
: _loc(loc)
, _inUse(false)
, _wid(wid)
,
// in Pixels
_width(width),
_height(height),
_rows(new DeltaBitmapRow[height])
_width(width)
, _height(height)
, _rows(new DeltaBitmapRow[height])
{
assert (startX + width <= (size_t)bufferWidth);
assert (startY + height <= (size_t)bufferHeight);
(void)bufferHeight;
LOG_TRC("Converting pixel data to delta data of size "
<< (width * height * 4) << " width " << width
<< " height " << height);

View File

@ -222,7 +222,7 @@ namespace
unsigned linkOrCopyFileCount = 0; // Track to help quantify the link-or-copy performance.
constexpr unsigned SlowLinkOrCopyLimitInSecs = 2; // After this many seconds, start spamming the logs.
bool detectSlowStackingFileSystem(const std::string &directory)
bool detectSlowStackingFileSystem([[maybe_unused]] const std::string& directory)
{
#ifdef __linux__
#ifndef OVERLAYFS_SUPER_MAGIC
@ -243,7 +243,6 @@ namespace
return false;
}
#else
(void)directory;
return false;
#endif
}

View File

@ -61,7 +61,7 @@ std::atomic<bool> Socket::InhibitThreadChecks(false);
#define SOCKET_ABSTRACT_UNIX_NAME "0coolwsd-"
int Socket::createSocket(Socket::Type type)
int Socket::createSocket([[maybe_unused]] Socket::Type type)
{
#if !MOBILEAPP
int domain = AF_UNSPEC;
@ -76,7 +76,6 @@ int Socket::createSocket(Socket::Type type)
return socket(domain, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
#else
(void) type;
return fakeSocketSocket();
#endif
}
@ -819,7 +818,7 @@ void SocketPoll::dumpState(std::ostream& os) const
}
/// Returns true on success only.
bool ServerSocket::bind(Type type, int port)
bool ServerSocket::bind([[maybe_unused]] Type type, [[maybe_unused]] int port)
{
#if !MOBILEAPP
// Enable address reuse to avoid stalling after
@ -873,9 +872,6 @@ bool ServerSocket::bind(Type type, int port)
return rc == 0;
#else
(void) type;
(void) port;
return true;
#endif
}

View File

@ -67,7 +67,7 @@ public:
/// isClient: the instance should behave like a client (true) or like a server (false)
/// (from websocket perspective)
/// isMasking: a client should mask (true) or not (false) outgoing frames
WebSocketHandler(bool isClient, bool isMasking)
WebSocketHandler(bool isClient, [[maybe_unused]] bool isMasking)
:
#if !MOBILEAPP
_lastPingSentTime(std::chrono::steady_clock::now() -
@ -84,9 +84,6 @@ public:
, _isClient(isClient)
, _unit(UnitBase::isUnitTesting() ? &UnitBase::get() : nullptr)
{
#if MOBILEAPP
(void) isMasking;
#endif
}
/// Upgrades itself to a websocket directly.
@ -550,8 +547,8 @@ protected:
}
}
int getPollEvents(std::chrono::steady_clock::time_point now,
int64_t & timeoutMaxMicroS) override
int getPollEvents([[maybe_unused]] std::chrono::steady_clock::time_point now,
[[maybe_unused]] int64_t& timeoutMaxMicroS) override
{
#if !MOBILEAPP
if (!_isClient)
@ -561,9 +558,6 @@ protected:
timeoutMaxMicroS
= std::min(timeoutMaxMicroS, (int64_t)(PingFrequencyMicroS - timeSincePingMicroS).count());
}
#else
(void) now;
(void) timeoutMaxMicroS;
#endif
int events = POLLIN;
if (_msgHandler && _msgHandler->hasQueuedMessages())
@ -612,7 +606,7 @@ public:
#endif
/// Do we need to handle a timeout ?
void checkTimeout(std::chrono::steady_clock::time_point now) override
void checkTimeout([[maybe_unused]] std::chrono::steady_clock::time_point now) override
{
#if !MOBILEAPP
if (_isClient)
@ -626,8 +620,6 @@ public:
if (socket)
sendPing(now, socket);
}
#else
(void) now;
#endif
}
@ -759,9 +751,8 @@ protected:
/// Sends a WebSocket frame given the data, length, and flags.
/// Returns the number of bytes written (including frame overhead) on success,
/// 0 for closed/invalid socket, and -1 for other errors.
int sendFrame(const std::shared_ptr<StreamSocket>& socket,
const char* data, const uint64_t len,
unsigned char flags, bool flush = true) const
int sendFrame(const std::shared_ptr<StreamSocket>& socket, const char* data, const uint64_t len,
[[maybe_unused]] unsigned char flags, bool flush = true) const
{
if (!socket || data == nullptr || len == 0)
return -1;
@ -827,8 +818,6 @@ protected:
// Return the number of bytes we wrote to the *buffer*.
const size_t size = out.size() - oldSize;
#else
(void) flags;
// We ignore the flush parameter and always flush in the MOBILEAPP case because there is no
// WebSocket framing, we put the messages as such into the FakeSocket queue.
flush = true;
@ -933,7 +922,8 @@ protected:
/// Upgrade the http(s) connection to a websocket.
template <typename T>
void upgradeToWebSocket(const std::shared_ptr<StreamSocket>& socket, const T& req)
void upgradeToWebSocket(const std::shared_ptr<StreamSocket>& socket,
[[maybe_unused]] const T& req)
{
assert(socket && "Must have a valid socket");
LOG_TRC("Upgrading to WebSocket");
@ -960,8 +950,6 @@ protected:
httpResponse.set("Sec-WebSocket-Accept", computeAccept(wsKey));
LOG_TRC("Sending WS Upgrade response: " << httpResponse.header().toString());
socket->send(httpResponse);
#else
(void) req;
#endif
setWebSocket(socket);
}

View File

@ -495,18 +495,16 @@ class LocalStorage : public StorageBase
{
public:
LocalStorage(const Poco::URI& uri, const std::string& localStorePath,
const std::string& jailPath, bool isTemporaryFile)
const std::string& jailPath, [[maybe_unused]] bool isTemporaryFile)
: StorageBase(uri, localStorePath, jailPath)
#if !MOBILEAPP
, _isTemporaryFile(isTemporaryFile)
#endif
, _isCopy(false)
{
LOG_INF("LocalStorage ctor with localStorePath: [" << localStorePath <<
"], jailPath: [" << jailPath << "], uri: [" << COOLWSD::anonymizeUrl(uri.toString()) << "].");
#if MOBILEAPP
(void) isTemporaryFile;
#endif
LOG_INF("LocalStorage ctor with localStorePath: ["
<< localStorePath << "], jailPath: [" << jailPath << "], uri: ["
<< COOLWSD::anonymizeUrl(uri.toString()) << "].");
}
class LocalFileInfo