refactor: replace some C idioms with C++ ones (#5656)

* tidy up legecy practices

* remove undefined std::ignore usage

* avoid extra function stack level in daemon.cc
This commit is contained in:
tearfur
2023-06-23 06:58:16 +08:00
committed by GitHub
parent 699b3d8416
commit 41cfdce6fd
6 changed files with 18 additions and 24 deletions

View File

@@ -3,15 +3,15 @@
// or any future license endorsed by Mnemosyne LLC. // or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder. // License text can be found in the licenses/ folder.
#include <assert.h> #include <cassert>
#include <errno.h> #include <cerrno>
#include <pthread.h> #include <pthread.h>
#ifdef HAVE_SYS_SIGNALFD_H #ifdef HAVE_SYS_SIGNALFD_H
#include <sys/signalfd.h> #include <sys/signalfd.h>
#endif /* signalfd API */ #endif /* signalfd API */
#include <event2/event.h> #include <event2/event.h>
#include <signal.h> #include <csignal>
#include <stdlib.h> /* abort(), daemon(), exit() */ #include <cstdlib> /* abort(), daemon(), exit() */
#include <fcntl.h> /* open() */ #include <fcntl.h> /* open() */
#include <unistd.h> /* fork(), setsid(), chdir(), dup2(), close(), pipe() */ #include <unistd.h> /* fork(), setsid(), chdir(), dup2(), close(), pipe() */

View File

@@ -39,15 +39,9 @@
#else #else
static void sd_notify(int /*status*/, char const* /*str*/) // no-op
{ #define sd_notify(status, str)
// no-op #define sd_notifyf(status, fmt, ...)
}
static void sd_notifyf(int /*status*/, char const* /*fmt*/, ...)
{
// no-op
}
#endif #endif
@@ -695,7 +689,7 @@ int tr_daemon::start([[maybe_unused]] bool foreground)
/* setup event state */ /* setup event state */
ev_base_ = event_base_new(); ev_base_ = event_base_new();
if (ev_base_ == nullptr || setup_signals() == false) if (ev_base_ == nullptr || !setup_signals())
{ {
auto const error_code = errno; auto const error_code = errno;
auto const errmsg = fmt::format( auto const errmsg = fmt::format(

View File

@@ -584,8 +584,8 @@ void Application::Impl::on_startup()
css_provider, css_provider,
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
std::ignore = FilterBar(); FilterBar();
std::ignore = PathButton(); PathButton();
tr_session* session = nullptr; tr_session* session = nullptr;

View File

@@ -82,8 +82,8 @@ enum tr_encryption_mode
TR_ENCRYPTION_REQUIRED TR_ENCRYPTION_REQUIRED
}; };
#define TR_RATIO_NA -1 #define TR_RATIO_NA (-1)
#define TR_RATIO_INF -2 #define TR_RATIO_INF (-2)
// --- Startup & Shutdown // --- Startup & Shutdown

View File

@@ -66,10 +66,10 @@ void tr_locale_set_global(char const* locale_name) noexcept
{ {
try try
{ {
std::ignore = std::locale::global(std::locale{ locale_name }); std::locale::global(std::locale{ locale_name });
std::ignore = std::cout.imbue(std::locale{}); std::cout.imbue(std::locale{});
std::ignore = std::cerr.imbue(std::locale{}); std::cerr.imbue(std::locale{});
} }
catch (std::exception const&) catch (std::exception const&)
{ {
@@ -274,7 +274,7 @@ double tr_getRatio(uint64_t numerator, uint64_t denominator)
{ {
if (denominator > 0) if (denominator > 0)
{ {
return numerator / (double)denominator; return numerator / static_cast<double>(denominator);
} }
if (numerator > 0) if (numerator > 0)
@@ -717,7 +717,7 @@ char* formatter_get_size_str(formatter_units const& u, char* buf, uint64_t bytes
unit = &u[3]; unit = &u[3];
} }
double const value = double(bytes) / unit->value; double const value = static_cast<double>(bytes) / unit->value;
auto const* const units = std::data(unit->name); auto const* const units = std::data(unit->name);
auto precision = int{}; auto precision = int{};

View File

@@ -39,7 +39,7 @@ protected:
{ {
if (old_locale_) if (old_locale_)
{ {
std::ignore = std::locale::global(*old_locale_); std::locale::global(*old_locale_);
} }
} }