Skip to content

Commit

Permalink
upgrade fmtlib to 11.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Rao Meng committed Feb 13, 2025
1 parent 500e49f commit 308b231
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if(MSVC)
else()
add_compile_options(-Wall -O3 -std=c++17)
#add_compile_options(-Wall -Ofast -std=c++2a -DNDEBUG -march=skylake -flto -fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables -DFMTLOG_NO_CHECK_LEVEL=1)
#SET(CMAKE_AR "gcc-ar")
#SET(CMAKE_RANLIB "gcc-ranlib")
link_libraries(pthread)
endif()

Expand Down
2 changes: 1 addition & 1 deletion fmt
Submodule fmt updated 184 files
6 changes: 3 additions & 3 deletions fmtlog-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ class fmtlogDetailT

template<size_t I, typename T>
inline void setArg(const T& arg) {
args[reorderIdx[I]] = fmt::detail::make_arg<fmtlog::Context>(arg);
args[reorderIdx[I]] = arg;
}

template<size_t I, typename T>
inline void setArgVal(const T& arg) {
fmt::detail::value<fmtlog::Context>& value_ = *(fmt::detail::value<fmtlog::Context>*)&args[reorderIdx[I]];
value_ = fmt::detail::arg_mapper<fmtlog::Context>().map(arg);
value_ = arg;
}

void flushLogFile() {
Expand Down Expand Up @@ -547,7 +547,7 @@ void fmtlogT<_>::setLogFile(const char* filename, bool truncate) {
FILE* newFp = fopen(filename, truncate ? "w" : "a");
if (!newFp) {
std::string err = fmt::format("Unable to open file: {}: {}", filename, strerror(errno));
fmt::detail::throw_format_error(err.c_str());
fmt::report_error(err.c_str());
}
setbuf(newFp, nullptr);
d.fpos = ftell(newFp);
Expand Down
25 changes: 12 additions & 13 deletions fmtlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,20 +406,19 @@ class fmtlogT
{ using type = Arg; };

#if FMT_USE_NONTYPE_TEMPLATE_ARGS
template<typename Arg, size_t N, fmt::detail_exported::fixed_string<char, N> Str>
struct unNamedType<fmt::detail::statically_named_arg<Arg, char, N, Str>>
template<typename Arg, size_t N, fmt::detail::fixed_string<char, N> Str>
struct unNamedType<fmt::detail::static_named_arg<Arg, char, N, Str>>
{ using type = Arg; };
#endif

template<typename Arg>
static inline constexpr bool isCstring() {
return fmt::detail::mapped_type_constant<Arg, Context>::value ==
fmt::detail::type::cstring_type;
return fmt::detail::mapped_type_constant<Arg, char>::value == fmt::detail::type::cstring_type;
}

template<typename Arg>
static inline constexpr bool isString() {
return fmt::detail::mapped_type_constant<Arg, Context>::value == fmt::detail::type::string_type;
return fmt::detail::mapped_type_constant<Arg, char>::value == fmt::detail::type::string_type;
}

template<typename Arg>
Expand Down Expand Up @@ -529,10 +528,10 @@ class fmtlogT
fmt::string_view v(in, size);
if constexpr (ValueOnly) {
fmt::detail::value<Context>& value_ = *(fmt::detail::value<Context>*)(args + Idx);
value_ = fmt::detail::arg_mapper<Context>().map(v);
value_ = v;
}
else {
args[Idx] = fmt::detail::make_arg<Context>(v);
args[Idx] = v;
}
return decodeArgs<ValueOnly, Idx + 1, DestructIdx, Args...>(in + size + 1, args,
destruct_args);
Expand All @@ -541,18 +540,18 @@ class fmtlogT
if constexpr (ValueOnly) {
fmt::detail::value<Context>& value_ = *(fmt::detail::value<Context>*)(args + Idx);
if constexpr (UnrefPtr<ArgType>::value) {
value_ = fmt::detail::arg_mapper<Context>().map(**(ArgType*)in);
value_ = **(ArgType*)in;
}
else {
value_ = fmt::detail::arg_mapper<Context>().map(*(ArgType*)in);
value_ = *(ArgType*)in;
}
}
else {
if constexpr (UnrefPtr<ArgType>::value) {
args[Idx] = fmt::detail::make_arg<Context>(**(ArgType*)in);
args[Idx] = **(ArgType*)in;
}
else {
args[Idx] = fmt::detail::make_arg<Context>(*(ArgType*)in);
args[Idx] = *(ArgType*)in;
}
}

Expand Down Expand Up @@ -636,7 +635,7 @@ class fmtlogT
out += copy_size;
begin = p;
c = *p++;
if (!c) fmt::detail::throw_format_error("invalid format string");
if (!c) fmt::report_error("invalid format string");
if (fmt::detail::is_name_start(c)) {
while ((fmt::detail::is_name_start(c = *p) || ('0' <= c && c <= '9'))) {
++p;
Expand All @@ -649,7 +648,7 @@ class fmtlogT
break;
}
}
if (id < 0) fmt::detail::throw_format_error("invalid format string");
if (id < 0) fmt::report_error("invalid format string");
if constexpr (Reorder) {
reorderIdx[id] = arg_idx++;
}
Expand Down
5 changes: 2 additions & 3 deletions test/enc_dec_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ template<>
struct fmt::formatter<MovableType> : formatter<int>
{
// parse is inherited from formatter<string_view>.
template<typename FormatContext>
auto format(const MovableType& val, FormatContext& ctx) {
// template<typename FormatContext>
auto format(const MovableType& val, format_context& ctx) const {
return formatter<int>::format(val.val[0].v, ctx);
}
};

template<typename S, typename... Args>
void test(const S& format, Args&&... args) {
fmt::detail::check_format_string<Args...>(format);
auto sv = fmt::string_view(format);
size_t formatted_size = fmt::formatted_size(fmt::runtime(sv), std::forward<Args>(args)...);
string ans = fmt::format(fmt::runtime(sv), std::forward<Args>(args)...);
Expand Down

0 comments on commit 308b231

Please sign in to comment.