Skip to content

Commit

Permalink
Upgrade to fmt 10.1.0 (#5326)
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul authored Aug 28, 2023
1 parent 8e2a7fd commit 165ebe4
Show file tree
Hide file tree
Showing 27 changed files with 3,382 additions and 3,273 deletions.
10 changes: 6 additions & 4 deletions cscore/src/main/native/cpp/HttpCameraImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect(
auto [mediaType, contentType] = wpi::split(conn->contentType.str(), ';');
mediaType = wpi::trim(mediaType);
if (mediaType != "multipart/x-mixed-replace") {
SWARNING("\"{}\": unrecognized Content-Type \"{}\"", req.host, mediaType);
SWARNING("\"{}\": unrecognized Content-Type \"{}\"", req.host.str(),
mediaType);
std::scoped_lock lock(m_mutex);
m_streamConn = nullptr;
return nullptr;
Expand All @@ -216,7 +217,8 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect(
}

if (boundary.empty()) {
SWARNING("\"{}\": empty multi-part boundary or no Content-Type", req.host);
SWARNING("\"{}\": empty multi-part boundary or no Content-Type",
req.host.str());
std::scoped_lock lock(m_mutex);
m_streamConn = nullptr;
return nullptr;
Expand Down Expand Up @@ -281,8 +283,8 @@ bool HttpCameraImpl::DeviceStreamFrame(wpi::raw_istream& is,
// Check the content type (if present)
if (!contentTypeBuf.str().empty() &&
!wpi::starts_with(contentTypeBuf, "image/jpeg")) {
auto errMsg =
fmt::format("received unknown Content-Type \"{}\"", contentTypeBuf);
auto errMsg = fmt::format("received unknown Content-Type \"{}\"",
contentTypeBuf.str());
SWARNING("{}", errMsg);
PutError(errMsg, wpi::Now());
return false;
Expand Down
6 changes: 3 additions & 3 deletions cscore/src/main/native/cpp/MjpegServerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,12 @@ void MjpegServerImpl::ConnThread::SendHTML(wpi::raw_ostream& os,
fmt::print(os,
"<input id=\"{0}{1}\" type=\"radio\" name=\"{0}\" "
"value=\"{2}\" onclick=\"update('{0}', {1})\"",
name, j, ch_name);
name, j, ch_name.str());
if (j == valE) {
os << " checked";
}
fmt::print(os, " /><label for=\"{}{}\">{}</label>\n", name, j,
ch_name);
ch_name.str());
}
break;
}
Expand Down Expand Up @@ -543,7 +543,7 @@ void MjpegServerImpl::ConnThread::SendJSON(wpi::raw_ostream& os,
for (char ch : *choice) {
ch_name.push_back(std::isprint(ch) ? ch : ' ');
}
fmt::print(os, "\"{}\": \"{}\"", j, ch_name);
fmt::print(os, "\"{}\": \"{}\"", j, ch_name.str());
}
os << "}\n";
}
Expand Down
2 changes: 1 addition & 1 deletion cscore/src/main/native/linux/UsbCameraImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void UsbCameraImpl::CameraThreadMain() {
// If the name is what we expect...
std::string_view name{raw_name.c_str()};
SDEBUG4("got event on '{}' ({}) compare to '{}' ({}) mask {}", name,
name.size(), base, base.size(), event.mask);
name.size(), base.str(), base.size(), event.mask);
if (name == base) {
if ((event.mask & IN_DELETE) != 0) {
wasStreaming = m_streaming;
Expand Down
2 changes: 1 addition & 1 deletion hal/src/main/native/sim/AddressableLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void HAL_WriteAddressableLEDData(HAL_AddressableLEDHandle handle,
status,
fmt::format(
"Data length must be less than or equal to {}. {} was requested",
SimAddressableLEDData[led->index].length, length));
SimAddressableLEDData[led->index].length.Get(), length));
return;
}
SimAddressableLEDData[led->index].SetData(data, length);
Expand Down
3 changes: 2 additions & 1 deletion ntcore/src/main/native/cpp/LocalStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ void LocalStorage::Impl::NetworkAnnounce(TopicData* topic,
}

void LocalStorage::Impl::RemoveNetworkPublisher(TopicData* topic) {
DEBUG4("LS RemoveNetworkPublisher({}, {})", topic->handle, topic->name);
DEBUG4("LS RemoveNetworkPublisher({}, {})", topic->handle.GetHandle(),
topic->name);
// this acts as an unpublish
bool didExist = topic->Exists();
topic->onNetwork = false;
Expand Down
18 changes: 9 additions & 9 deletions roborioteamnumbersetter/src/main/native/cpp/DeploySession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ bool DeploySession::ChangeTeamNumber(const std::string& macAddress,
in_addr addr;
addr.s_addr = ipAddress;
wpi::uv::AddrToName(addr, &ip);
DEBUG("Trying to establish SSH connection to {}.", ip);
DEBUG("Trying to establish SSH connection to {}.", ip.str());
try {
SshSession session{ip.str(), kPort, kUsername, kPassword, m_logger};
session.Open();
DEBUG("SSH connection to {} was successful.", ip);
DEBUG("SSH connection to {} was successful.", ip.str());

SUCCESS("roboRIO Connected!");

Expand All @@ -93,7 +93,7 @@ bool DeploySession::ChangeTeamNumber(const std::string& macAddress,
throw e;
}
} catch (const SshSession::SshException& e) {
DEBUG("SSH connection to {} failed with {}.", ip, e.what());
DEBUG("SSH connection to {} failed with {}.", ip.str(), e.what());
throw e;
}
return 0;
Expand All @@ -117,11 +117,11 @@ bool DeploySession::Reboot(const std::string& macAddress,
in_addr addr;
addr.s_addr = ipAddress;
wpi::uv::AddrToName(addr, &ip);
DEBUG("Trying to establish SSH connection to {}.", ip);
DEBUG("Trying to establish SSH connection to {}.", ip.str());
try {
SshSession session{ip.str(), kPort, kUsername, kPassword, m_logger};
session.Open();
DEBUG("SSH connection to {} was successful.", ip);
DEBUG("SSH connection to {} was successful.", ip.str());

SUCCESS("roboRIO Connected!");

Expand All @@ -132,7 +132,7 @@ bool DeploySession::Reboot(const std::string& macAddress,
throw e;
}
} catch (const SshSession::SshException& e) {
DEBUG("SSH connection to {} failed with {}.", ip, e.what());
DEBUG("SSH connection to {} failed with {}.", ip.str(), e.what());
throw e;
}
return 0;
Expand All @@ -156,11 +156,11 @@ bool DeploySession::Blink(const std::string& macAddress,
in_addr addr;
addr.s_addr = ipAddress;
wpi::uv::AddrToName(addr, &ip);
DEBUG("Trying to establish SSH connection to {}.", ip);
DEBUG("Trying to establish SSH connection to {}.", ip.str());
try {
SshSession session{ip.str(), kPort, kUsername, kPassword, m_logger};
session.Open();
DEBUG("SSH connection to {} was successful.", ip);
DEBUG("SSH connection to {} was successful.", ip.str());

SUCCESS("roboRIO Connected!");

Expand All @@ -175,7 +175,7 @@ bool DeploySession::Blink(const std::string& macAddress,
throw e;
}
} catch (const SshSession::SshException& e) {
DEBUG("SSH connection to {} failed with {}.", ip, e.what());
DEBUG("SSH connection to {} failed with {}.", ip.str(), e.what());
throw e;
}
return 0;
Expand Down
37 changes: 19 additions & 18 deletions upstream_utils/fmt_patches/0001-Don-t-throw-on-write-failure.patch
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Wed, 18 May 2022 10:21:49 -0700
Subject: [PATCH 1/3] Don't throw on write failure
Subject: [PATCH 1/2] Don't throw on write failure

---
include/fmt/format-inl.h | 4 +---
include/fmt/xchar.h | 3 +--
src/os.cc | 3 +--
3 files changed, 3 insertions(+), 7 deletions(-)
src/os.cc | 4 +---
3 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h
index 22b1ec8df0eb14b3f7f21797a19586b50b8423fd..abe4ff13db6287f9c5229df6c4b46beeed020bce 100644
index dac2d437a41ab7b0b4e72895212b5a972ada73a9..af6ba74d618f29c77339e8a82906cccd26a2efa4 100644
--- a/include/fmt/format-inl.h
+++ b/include/fmt/format-inl.h
@@ -79,9 +79,7 @@ FMT_FUNC void report_error(format_func func, int error_code,
@@ -75,9 +75,7 @@ FMT_FUNC void report_error(format_func func, int error_code,
// A wrapper around fwrite that throws on error.
inline void fwrite_fully(const void* ptr, size_t size, size_t count,
FILE* stream) {
Expand All @@ -25,30 +25,31 @@ index 22b1ec8df0eb14b3f7f21797a19586b50b8423fd..abe4ff13db6287f9c5229df6c4b46bee

#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h
index 3b5bc15ca0a1d92d721611ddc70e80f098fb79ae..fc3c67f21c2294b8e73d6ea53f25c877f733082c 100644
index 625ec36922e9bcc44a76b3c40792cb08ede63813..0f79c1720a4c855bb7088381e93af08eae56d66c 100644
--- a/include/fmt/xchar.h
+++ b/include/fmt/xchar.h
@@ -200,8 +200,7 @@ inline void vprint(std::FILE* f, wstring_view fmt, wformat_args args) {
wmemory_buffer buffer;
detail::vformat_to(buffer, fmt, args);
buffer.push_back(L'\0');
- if (std::fputws(buffer.data(), f) == -1)
@@ -220,8 +220,7 @@ inline void vprint(std::FILE* f, wstring_view fmt, wformat_args args) {
auto buf = wmemory_buffer();
detail::vformat_to(buf, fmt, args);
buf.push_back(L'\0');
- if (std::fputws(buf.data(), f) == -1)
- FMT_THROW(system_error(errno, FMT_STRING("cannot write to file")));
+ std::fputws(buffer.data(), f);
+ std::fputws(buf.data(), f);
}

inline void vprint(wstring_view fmt, wformat_args args) {
diff --git a/src/os.cc b/src/os.cc
index f388ead0191b61ae0e5c24692c1f523aae3c9fbb..2c499512b5396830d7f1eb8fb5874586898802dd 100644
index bca410e945e0347d349e06179906a43b38b56a5c..d7ded50f9870a885d1ce1835fecc4f740858127a 100644
--- a/src/os.cc
+++ b/src/os.cc
@@ -277,8 +277,7 @@ std::size_t file::read(void* buffer, std::size_t count) {
std::size_t file::write(const void* buffer, std::size_t count) {
@@ -258,9 +258,7 @@ long long file::size() const {
std::size_t file::read(void* buffer, std::size_t count) {
rwresult result = 0;
FMT_RETRY(result, FMT_POSIX_CALL(write(fd_, buffer, convert_rwcount(count))));
- if (result < 0) FMT_THROW(system_error(errno, "cannot write to file"));
FMT_RETRY(result, FMT_POSIX_CALL(read(fd_, buffer, convert_rwcount(count))));
- if (result < 0)
- FMT_THROW(system_error(errno, FMT_STRING("cannot read from file")));
- return detail::to_unsigned(result);
+ return count;
}

file file::dup(int fd) {
std::size_t file::write(const void* buffer, std::size_t count) {

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Tue, 16 May 2023 13:49:18 -0700
Subject: [PATCH 2/2] Suppress warnings we can't fix

---
include/fmt/format.h | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/include/fmt/format.h b/include/fmt/format.h
index e5bd8b110efe49e12a12b004ea246a4dba671a6f..f11be0d6d58f3d992d7d06adb3d9576f81ecfe11 100644
--- a/include/fmt/format.h
+++ b/include/fmt/format.h
@@ -1324,7 +1324,14 @@ inline auto equal2(const char* lhs, const char* rhs) -> bool {
template <typename Char>
FMT_CONSTEXPR20 FMT_INLINE void copy2(Char* dst, const char* src) {
if (!is_constant_evaluated() && sizeof(Char) == sizeof(char)) {
+#if FMT_GCC_VERSION && FMT_GCC_VERSION >= 1000
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wstringop-overflow"
+#endif
memcpy(dst, src, 2);
+#if FMT_GCC_VERSION && FMT_GCC_VERSION >= 1000
+# pragma GCC diagnostic pop
+#endif
return;
}
*dst++ = static_cast<Char>(*src++);

This file was deleted.

5 changes: 2 additions & 3 deletions upstream_utils/update_fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@


def main():
upstream_root = clone_repo("https://github.com/fmtlib/fmt", "9.1.0")
upstream_root = clone_repo("https://github.com/fmtlib/fmt", "10.1.0")
wpilib_root = get_repo_root()
wpiutil = os.path.join(wpilib_root, "wpiutil")

# Apply patches to upstream Git repo
os.chdir(upstream_root)
for f in [
"0001-Don-t-throw-on-write-failure.patch",
"0002-Suppress-C-20-clang-tidy-warning-false-positive.patch",
"0003-Suppress-warnings-we-can-t-fix.patch",
"0002-Suppress-warnings-we-can-t-fix.patch",
]:
git_am(os.path.join(wpilib_root, "upstream_utils/fmt_patches", f))

Expand Down
2 changes: 1 addition & 1 deletion wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ JNIEXPORT void JNICALL
Java_edu_wpi_first_util_WPIUtilJNI_writeStderr
(JNIEnv* env, jclass, jstring str)
{
fmt::print(stderr, "{}", JStringRef{env, str});
fmt::print(stderr, "{}", JStringRef{env, str}.str());
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Formatting library for C++ - dynamic format arguments
// Formatting library for C++ - dynamic argument lists
//
// Copyright (c) 2012 - present, Victor Zverovich
// All rights reserved.
Expand Down
Loading

0 comments on commit 165ebe4

Please sign in to comment.