Skip to content

Commit

Permalink
fix: wrap runtime format strings with fmt::runtime
Browse files Browse the repository at this point in the history
fmt::format_string ctor is consteval with C++20
See fmtlib/fmt#2438

Signed-off-by: Dzmitry Neviadomski <[email protected]>
  • Loading branch information
nevack committed May 7, 2024
1 parent 3244dcd commit 301ba75
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions libtransmission/announcer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -890,10 +890,10 @@ void on_announce_error(tr_tier* tier, char const* err, tr_announce_event e)
tr_logAddWarnTier(
tier,
fmt::format(
tr_ngettext(
fmt::runtime(tr_ngettext(
"Announce error: {error} (Retrying in {count} second) ({url})",
"Announce error: {error} (Retrying in {count} seconds) ({url})",
interval),
interval)),
fmt::arg("error", err),
fmt::arg("count", interval),
fmt::arg("url", announce_url)));
Expand Down
6 changes: 4 additions & 2 deletions libtransmission/blocklist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ void save(std::string_view filename, address_range_t const* ranges, size_t n_ran
else
{
tr_logAddInfo(fmt::format(
tr_ngettext("Blocklist '{path}' has {count} entry", "Blocklist '{path}' has {count} entries", n_ranges),
fmt::runtime(
tr_ngettext("Blocklist '{path}' has {count} entry", "Blocklist '{path}' has {count} entries", n_ranges)),
fmt::arg("path", tr_sys_path_basename(filename)),
fmt::arg("count", n_ranges)));
}
Expand Down Expand Up @@ -400,7 +401,8 @@ void Blocklists::Blocklist::ensureLoaded() const
}

tr_logAddInfo(fmt::format(
tr_ngettext("Blocklist '{path}' has {count} entry", "Blocklist '{path}' has {count} entries", std::size(rules_)),
fmt::runtime(
tr_ngettext("Blocklist '{path}' has {count} entry", "Blocklist '{path}' has {count} entries", std::size(rules_))),
fmt::arg("path", tr_sys_path_basename(bin_file_)),
fmt::arg("count", std::size(rules_))));
}
Expand Down
9 changes: 5 additions & 4 deletions libtransmission/net.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,10 @@ tr_socket_t tr_netBindTCPImpl(tr_address const& addr, tr_port port, bool suppres
if (!suppress_msgs)
{
tr_logAddError(fmt::format(
err == EADDRINUSE ?
_("Couldn't bind port {port} on {address}: {error} ({error_code}) -- Is another copy of Transmission already running?") :
_("Couldn't bind port {port} on {address}: {error} ({error_code})"),
fmt::runtime(
err == EADDRINUSE ?
_("Couldn't bind port {port} on {address}: {error} ({error_code}) -- Is another copy of Transmission already running?") :
_("Couldn't bind port {port} on {address}: {error} ({error_code})")),
fmt::arg("address", addr.display_name()),
fmt::arg("port", port.host()),
fmt::arg("error", tr_net_strerror(err)),
Expand Down Expand Up @@ -707,7 +708,7 @@ int tr_address::compare(tr_address const& that) const noexcept // <=>

std::string tr_socket_address::display_name(tr_address const& address, tr_port port) noexcept
{
return fmt::format(address.is_ipv6() ? "[{:s}]:{:d}" : "{:s}:{:d}", address.display_name(), port.host());
return fmt::format(fmt::runtime(address.is_ipv6() ? "[{:s}]:{:d}" : "{:s}:{:d}"), address.display_name(), port.host());
}

bool tr_socket_address::is_valid_for_peers(tr_peer_from from) const noexcept
Expand Down
2 changes: 1 addition & 1 deletion libtransmission/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ void session_load_torrents(tr_session* session, tr_ctor* ctor, std::promise<size
if (n_torrents != 0U)
{
tr_logAddInfo(fmt::format(
tr_ngettext("Loaded {count} torrent", "Loaded {count} torrents", n_torrents),
fmt::runtime(tr_ngettext("Loaded {count} torrent", "Loaded {count} torrents", n_torrents)),
fmt::arg("count", n_torrents)));
}

Expand Down
7 changes: 4 additions & 3 deletions utils/create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,16 @@ int tr_main(int argc, char* argv[])
}

fmt::print(
tr_ngettext("{file_count:L} file, {total_size}\n", "{file_count:L} files, {total_size}\n", builder.file_count()),
fmt::runtime(
tr_ngettext("{file_count:L} file, {total_size}\n", "{file_count:L} files, {total_size}\n", builder.file_count())),
fmt::arg("file_count", builder.file_count()),
fmt::arg("total_size", Storage{ builder.total_size(), Storage::Units::Bytes }.to_string()));

fmt::print(
tr_ngettext(
fmt::runtime(tr_ngettext(
"{piece_count:L} piece, {piece_size}\n",
"{piece_count:L} pieces, {piece_size} each\n",
builder.piece_count()),
builder.piece_count())),
fmt::arg("piece_count", builder.piece_count()),
fmt::arg("piece_size", Memory{ builder.piece_size(), Memory::Units::Bytes }.to_string()));

Expand Down
2 changes: 1 addition & 1 deletion utils/remote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ void printDetails(tr_variant* top)
{
if (tr_variantGetStrView(tr_variantListChild(l, child_idx), &sv))
{
fmt::print(child_idx == 0 ? "{:s}" : ", {:s}", sv);
fmt::print(fmt::runtime(child_idx == 0 ? "{:s}" : ", {:s}"), sv);
}
}

Expand Down

0 comments on commit 301ba75

Please sign in to comment.