mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
[wpiutil] Upgrade to fmt 10.2.1, add wpi::print (#6161)
We now use a wrapper (wpi::print) to catch exceptions since we can't patch std::print() to not throw when we ultimately migrate to it. fmtlib and std format/print throw the same exceptions and always have. We previously patched fmt::print() to not throw a write failure exception, but we can't do that for std::print(); wpi::print() is the migration plan.
This commit is contained in:
@@ -9,12 +9,12 @@
|
||||
|
||||
#include "wpi/raw_ostream.h"
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
namespace wpi {
|
||||
|
||||
inline void vprint(wpi::raw_ostream& os, string_view format_str,
|
||||
inline void vprint(wpi::raw_ostream& os, fmt::string_view format_str,
|
||||
fmt::format_args args) {
|
||||
memory_buffer buffer;
|
||||
detail::vformat_to(buffer, format_str, args);
|
||||
fmt::memory_buffer buffer;
|
||||
fmt::detail::vformat_to(buffer, format_str, args);
|
||||
os.write(buffer.data(), buffer.size());
|
||||
}
|
||||
|
||||
@@ -26,6 +26,6 @@ void print(wpi::raw_ostream& os, const S& format_str, Args&&... args) {
|
||||
vprint(os, format_str, fmt::make_format_args(args...));
|
||||
}
|
||||
|
||||
FMT_END_NAMESPACE
|
||||
} // namespace wpi
|
||||
|
||||
#endif // WPIUTIL_WPI_FMT_RAW_OSTREAM_H_
|
||||
|
||||
@@ -15,14 +15,13 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include "wpi/ConvertUTF.h"
|
||||
#include "wpi/SafeThread.h"
|
||||
#include "wpi/SmallString.h"
|
||||
#include "wpi/SmallVector.h"
|
||||
#include "wpi/StringExtras.h"
|
||||
#include "wpi/mutex.h"
|
||||
#include "wpi/print.h"
|
||||
#include "wpi/raw_ostream.h"
|
||||
|
||||
/** Java Native Interface (JNI) utility functions */
|
||||
@@ -160,7 +159,7 @@ class JStringRef {
|
||||
env->ReleaseStringCritical(str, chars);
|
||||
}
|
||||
} else {
|
||||
fmt::print(stderr, "JStringRef was passed a null pointer at\n",
|
||||
wpi::print(stderr, "JStringRef was passed a null pointer at\n",
|
||||
GetJavaStackTrace(env));
|
||||
}
|
||||
// Ensure str is null-terminated.
|
||||
@@ -283,7 +282,7 @@ class JSpanBase {
|
||||
m_elements{static_cast<std::remove_cv_t<T>*>(
|
||||
bb ? env->GetDirectBufferAddress(bb) : nullptr)} {
|
||||
if (!bb) {
|
||||
fmt::print(stderr, "JSpan was passed a null pointer at\n",
|
||||
wpi::print(stderr, "JSpan was passed a null pointer at\n",
|
||||
GetJavaStackTrace(env));
|
||||
}
|
||||
}
|
||||
@@ -302,7 +301,7 @@ class JSpanBase {
|
||||
m_elements = ArrHelper::GetArrayElements(env, jarr);
|
||||
}
|
||||
} else {
|
||||
fmt::print(stderr, "JSpan was passed a null pointer at\n",
|
||||
wpi::print(stderr, "JSpan was passed a null pointer at\n",
|
||||
GetJavaStackTrace(env));
|
||||
}
|
||||
}
|
||||
|
||||
58
wpiutil/src/main/native/include/wpi/print.h
Normal file
58
wpiutil/src/main/native/include/wpi/print.h
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <system_error>
|
||||
#include <utility>
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
namespace wpi {
|
||||
|
||||
/**
|
||||
* Wrapper around fmt::print() that squelches write failure exceptions.
|
||||
*/
|
||||
template <typename... T>
|
||||
inline void print(fmt::format_string<T...> fmt, T&&... args) {
|
||||
try {
|
||||
fmt::print(fmt, std::forward<T>(args)...);
|
||||
} catch (const std::system_error&) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around fmt::print() that squelches write failure exceptions.
|
||||
*/
|
||||
template <typename... T>
|
||||
inline void print(std::FILE* f, fmt::format_string<T...> fmt, T&&... args) {
|
||||
try {
|
||||
fmt::print(f, fmt, std::forward<T>(args)...);
|
||||
} catch (const std::system_error&) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around fmt::println() that squelches write failure exceptions.
|
||||
*/
|
||||
template <typename... T>
|
||||
inline void println(fmt::format_string<T...> fmt, T&&... args) {
|
||||
try {
|
||||
fmt::println(fmt, std::forward<T>(args)...);
|
||||
} catch (const std::system_error&) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around fmt::println() that squelches write failure exceptions.
|
||||
*/
|
||||
template <typename... T>
|
||||
inline void println(std::FILE* f, fmt::format_string<T...> fmt, T&&... args) {
|
||||
try {
|
||||
fmt::println(f, fmt, std::forward<T>(args)...);
|
||||
} catch (const std::system_error&) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace wpi
|
||||
Reference in New Issue
Block a user