diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 0828b56..5d04019 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -29,4 +29,6 @@ file(GLOB HEAD_FILES ${LIBIPC_PROJECT_DIR}/benchmark/*.h) add_executable(${PROJECT_NAME} ${SRC_FILES} ${HEAD_FILES}) -target_link_libraries(${PROJECT_NAME} benchmark_main imp ipc) +target_link_libraries(${PROJECT_NAME} + benchmark_main fmt + imp ipc) diff --git a/include/libconcur/element.h b/include/libconcur/element.h index b45dd28..f53381b 100644 --- a/include/libconcur/element.h +++ b/include/libconcur/element.h @@ -54,7 +54,7 @@ public: LIBIMP_TRY { data_ = std::forward(src); } LIBIMP_CATCH(std::exception const &e) { - log.error("failed: `data = std::forward(src)`. error = {}", e.what()); + log.error("failed: `data = std::forward(src)`. error = ", e.what()); } LIBIMP_CATCH(...) { log.error("failed: `data = std::forward(src)`. error = unknown"); } diff --git a/include/libimp/fmt.h b/include/libimp/fmt.h index c35c68f..6e5dd9d 100644 --- a/include/libimp/fmt.h +++ b/include/libimp/fmt.h @@ -95,7 +95,7 @@ LIBIMP_EXPORT std::string to_string(long double a, span fstr = {}) n LIBIMP_EXPORT std::string to_string(std::nullptr_t) noexcept; template ::value>> -LIBIMP_EXPORT std::string to_string(T *a) noexcept; +LIBIMP_EXPORT std::string to_string(T const volatile *a) noexcept; /// @brief Date and time. LIBIMP_EXPORT std::string to_string(std::tm const &a, span fstr = {}) noexcept; @@ -118,5 +118,11 @@ auto tag_invoke(fmt_to_string_t, T &&arg) noexcept return ::LIBIMP::to_string(std::forward(arg)); } +template +auto tag_invoke(fmt_to_string_t, fmt_ref arg) noexcept + -> decltype(::LIBIMP::to_string(static_cast(arg.param), arg.fstr)) { + return ::LIBIMP::to_string(static_cast(arg.param), arg.fstr); +} + } // namespace detail LIBIMP_NAMESPACE_END_ diff --git a/include/libimp/log.h b/include/libimp/log.h index df9b794..43924ba 100644 --- a/include/libimp/log.h +++ b/include/libimp/log.h @@ -11,8 +11,6 @@ #include #include -#include "fmt/format.h" - #include "libimp/def.h" #include "libimp/detect_plat.h" #include "libimp/export.h" @@ -40,9 +38,7 @@ struct context { LIBIMP_EXPORT std::string to_string(context &&) noexcept; -/** - * @brief Custom defined fmt_to_string method for imp::fmt - */ +/// @brief Custom defined fmt_to_string method for imp::fmt template std::string tag_invoke(decltype(::LIBIMP::fmt_to_string), context &&arg) noexcept { return ::LIBIMP::log::to_string(std::move(arg)); @@ -151,8 +147,8 @@ class grip { char const *func_; level level_limit_; - template - grip &output(log::level l, Fmt &&ft, A &&... args) noexcept { + template + grip &output(log::level l, A &&... args) noexcept { if (!printer_ || (enum_cast(l) < enum_cast(level_limit_))) { return *this; } @@ -160,7 +156,7 @@ class grip { LIBIMP_TRY { ctx = { l, std::chrono::system_clock::now(), func_, - ::fmt::format(std::forward(ft), std::forward(args)...), + fmt(std::forward(args)...), }; } LIBIMP_CATCH(std::exception const &e) { /// @remark [TBD] std::string constructor may throw an exception @@ -178,30 +174,12 @@ public: , func_ (func) , level_limit_(level_limit) {} - template - grip &trace(Fmt &&ft, A &&... args) noexcept { - return output(log::level::trace, std::forward(ft), std::forward(args)...); - } - template - grip &debug(Fmt &&ft, A &&... args) noexcept { - return output(log::level::debug, std::forward(ft), std::forward(args)...); - } - template - grip &info(Fmt &&ft, A &&... args) noexcept { - return output(log::level::info, std::forward(ft), std::forward(args)...); - } - template - grip &warning(Fmt &&ft, A &&... args) noexcept { - return output(log::level::warning, std::forward(ft), std::forward(args)...); - } - template - grip &error(Fmt &&ft, A &&... args) noexcept { - return output(log::level::error, std::forward(ft), std::forward(args)...); - } - template - grip &failed(Fmt &&ft, A &&... args) noexcept { - return output(log::level::failed, std::forward(ft), std::forward(args)...); - } + template grip &trace (A &&...args) noexcept { return output(log::level::trace , std::forward(args)...); } + template grip &debug (A &&...args) noexcept { return output(log::level::debug , std::forward(args)...); } + template grip &info (A &&...args) noexcept { return output(log::level::info , std::forward(args)...); } + template grip &warning(A &&...args) noexcept { return output(log::level::warning, std::forward(args)...); } + template grip &error (A &&...args) noexcept { return output(log::level::error , std::forward(args)...); } + template grip &failed (A &&...args) noexcept { return output(log::level::failed , std::forward(args)...); } }; } // namespace log diff --git a/include/libimp/result.h b/include/libimp/result.h index 6037b30..8603d62 100644 --- a/include/libimp/result.h +++ b/include/libimp/result.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include "fmt/format.h" @@ -14,6 +15,7 @@ #include "libimp/def.h" #include "libimp/detect_plat.h" #include "libimp/export.h" +#include "libimp/fmt.h" LIBIMP_NAMESPACE_BEG_ @@ -70,9 +72,12 @@ struct default_traits::value>> { static T cast_from_code(result_type code) noexcept { return static_cast(code); } + static std::string format(result const &r) noexcept { + return fmt(*r); + } template static auto format(result const &r, Out &&out) noexcept { - return format_to(out, "{}", *r); + return format_to(out, format(r)); } }; @@ -86,12 +91,15 @@ struct default_traits::value>> { static T cast_from_code(result_type code) noexcept { return reinterpret_cast(code); } + static std::string format(result const &r) noexcept { + if LIBIMP_LIKELY(r) { + return fmt(static_cast(*r)); + } + return fmt(static_cast(*r), ", code = ", r.code_value()); + } template static auto format(result const &r, Out &&out) noexcept { - if LIBIMP_LIKELY(r) { - return format_to(out, "{}", static_cast(*r)); - } - return format_to(out, "{}, code = {}", static_cast(*r), r.code_value()); + return format_to(out, format(r)); } }; @@ -157,6 +165,19 @@ public: friend bool operator!=(result const &lhs, result const &rhs) noexcept { return lhs.code_ != rhs.code_; } }; +/// @brief Custom defined fmt_to_string method for imp::fmt +namespace detail { + +inline std::string tag_invoke(decltype(::LIBIMP::fmt_to_string), result_code r) noexcept { + return fmt("[", (r ? "succ" : "fail"), ", value = ", *r, "]"); +} + +template +std::string tag_invoke(decltype(::LIBIMP::fmt_to_string), result r) noexcept { + return fmt("[", (r ? "succ" : "fail"), ", value = ", result::default_traits_t::format(r), "]"); +} + +} // namespace detail LIBIMP_NAMESPACE_END_ template diff --git a/include/libimp/system.h b/include/libimp/system.h index 435d257..ce207c6 100644 --- a/include/libimp/system.h +++ b/include/libimp/system.h @@ -13,6 +13,7 @@ #include "libimp/def.h" #include "libimp/export.h" #include "libimp/result.h" +#include "libimp/fmt.h" LIBIMP_NAMESPACE_BEG_ namespace sys { @@ -63,6 +64,13 @@ enum class info : std::int32_t { }; LIBIMP_EXPORT result conf(info) noexcept; +/** + * @brief @brief Custom defined fmt_to_string method for imp::fmt + */ +inline std::string tag_invoke(decltype(::LIBIMP::fmt_to_string), error r) noexcept { + return error_msg(r.code()); +} + } // namespace sys LIBIMP_NAMESPACE_END_ diff --git a/src/libimp/fmt.cpp b/src/libimp/fmt.cpp index 9db9e13..613f3ad 100644 --- a/src/libimp/fmt.cpp +++ b/src/libimp/fmt.cpp @@ -208,7 +208,7 @@ std::string to_string(std::nullptr_t) noexcept { } template <> -std::string to_string(void *a) noexcept { +std::string to_string(void const volatile *a) noexcept { if (a == nullptr) { return to_string(nullptr); } diff --git a/src/libimp/log.cpp b/src/libimp/log.cpp index 4bfc2f0..925fc46 100644 --- a/src/libimp/log.cpp +++ b/src/libimp/log.cpp @@ -3,8 +3,6 @@ #include #include -#include "fmt/chrono.h" - LIBIMP_NAMESPACE_BEG_ namespace log { @@ -14,7 +12,7 @@ std::string to_string(context &&ctx) noexcept { }; LIBIMP_TRY { auto ms = std::chrono::time_point_cast(ctx.tp).time_since_epoch().count() % 1000; - return ::fmt::format("[{}][{:%Y-%m-%d %H:%M:%S}.{:03}][{}] {}", types[enum_cast(ctx.level)], ctx.tp, ms, ctx.func, ctx.text); + return fmt("[", types[enum_cast(ctx.level)], "][", ctx.tp, ".", spec("03")(ms), "][", ctx.func, "] ", ctx.text); } LIBIMP_CATCH(std::exception const &e) { /// @remark [TBD] std::string constructor may throw an exception return e.what(); diff --git a/src/libimp/platform/gnuc/demangle.h b/src/libimp/platform/gnuc/demangle.h index e1ef540..f843f7b 100644 --- a/src/libimp/platform/gnuc/demangle.h +++ b/src/libimp/platform/gnuc/demangle.h @@ -29,7 +29,7 @@ std::string demangle(span name) noexcept { int status = 0; char *realname = abi::__cxa_demangle(name.data(), buffer, &sz, &status); if (realname == nullptr) { - log.error("failed: abi::__cxa_demangle(sz = {}), status = {}", sz, status); + log.error("failed: abi::__cxa_demangle(sz = ", sz, "), status = ", status); std::free(buffer); return {}; } diff --git a/src/libimp/platform/posix/system.h b/src/libimp/platform/posix/system.h index b9ccd39..25e449d 100644 --- a/src/libimp/platform/posix/system.h +++ b/src/libimp/platform/posix/system.h @@ -46,8 +46,9 @@ std::string error_str(result_code code) noexcept { #if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) LIBIMP_LOG_(); if (::strerror_r((int)code.value(), msg_buf, sizeof(msg_buf)) != 0) { - log.error("failed: strerror_r(code = {}, buf, buf-size = {}). error = {}", - (int)code.value(), sizeof(msg_buf), error_code()); + log.error("failed: strerror_r(code = ", (int)code.value(), + ", buf, buf-size = ", sizeof(msg_buf), + "). error = ", error_code()); return {}; } return msg_buf; @@ -70,11 +71,11 @@ result conf(info r) noexcept { break; } default: - log.error("invalid info = {}", enum_cast(r)); + log.error("invalid info = ", enum_cast(r)); return {}; } auto err = sys::error(); - log.error("info = {}, error = {}", enum_cast(r), err); + log.error("info = ", enum_cast(r), ", error = ", err); return {false, (int)err.value()}; } diff --git a/src/libimp/platform/win/codecvt.h b/src/libimp/platform/win/codecvt.h index abca909..edcb785 100644 --- a/src/libimp/platform/win/codecvt.h +++ b/src/libimp/platform/win/codecvt.h @@ -36,7 +36,7 @@ std::size_t cvt_cstr(char const *src, std::size_t slen, wchar_t *des, std::size_ int cch_wc = (des == nullptr) ? 0 : (int)dlen; int size_needed = ::MultiByteToWideChar(CP_ACP, 0, src, (int)slen, des, cch_wc); if (size_needed <= 0) { - log.error("failed: MultiByteToWideChar(CP_ACP). error = {}", sys::error_code()); + log.error("failed: MultiByteToWideChar(CP_ACP). error = ", sys::error_code()); } return size_needed; } @@ -51,7 +51,7 @@ std::size_t cvt_cstr(wchar_t const *src, std::size_t slen, char *des, std::size_ int cb_mb = (des == nullptr) ? 0 : (int)dlen; int size_needed = ::WideCharToMultiByte(CP_ACP, 0, src, (int)slen, des, cb_mb, NULL, NULL); if (size_needed <= 0) { - log.error("failed: WideCharToMultiByte(CP_ACP). error = {}", sys::error_code()); + log.error("failed: WideCharToMultiByte(CP_ACP). error = ", sys::error_code()); } return size_needed; } @@ -73,7 +73,7 @@ std::size_t cvt_cstr(char8_t const *src, std::size_t slen, wchar_t *des, std::si int cch_wc = (des == nullptr) ? 0 : (int)dlen; int size_needed = ::MultiByteToWideChar(CP_UTF8, 0, (char *)src, (int)slen, des, cch_wc); if (size_needed <= 0) { - log.error("failed: MultiByteToWideChar(CP_UTF8). error = {}", sys::error_code()); + log.error("failed: MultiByteToWideChar(CP_UTF8). error = ", sys::error_code()); } return size_needed; } @@ -88,7 +88,7 @@ std::size_t cvt_cstr(wchar_t const *src, std::size_t slen, char8_t *des, std::si int cb_mb = (des == nullptr) ? 0 : (int)dlen; int size_needed = ::WideCharToMultiByte(CP_UTF8, 0, src, (int)slen, (char *)des, cb_mb, NULL, NULL); if (size_needed <= 0) { - log.error("failed: WideCharToMultiByte(CP_UTF8). error = {}", sys::error_code()); + log.error("failed: WideCharToMultiByte(CP_UTF8). error = ", sys::error_code()); } return size_needed; } diff --git a/src/libimp/platform/win/system.h b/src/libimp/platform/win/system.h index d8a199d..a24763a 100644 --- a/src/libimp/platform/win/system.h +++ b/src/libimp/platform/win/system.h @@ -59,7 +59,7 @@ std::string error_str(result_code code) noexcept { MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpErrText, 0, NULL) == 0) { - log.error("failed: FormatMessage(dwMessageId = {}). error = {}", err, error_code()); + log.error("failed: FormatMessage(dwMessageId = ", err, "). error = ", error_code()); return {}; } LIBIMP_UNUSED auto buf_guard = std::unique_ptr, @@ -94,7 +94,7 @@ result conf(info r) noexcept { return (std::int64_t)info.dwPageSize; } default: - log.error("invalid info = {}", enum_cast(r)); + log.error("invalid info = ", enum_cast(r)); return {}; } } diff --git a/src/libimp/system.cpp b/src/libimp/system.cpp index b5b73dc..43d3972 100644 --- a/src/libimp/system.cpp +++ b/src/libimp/system.cpp @@ -1,6 +1,4 @@ -#include "fmt/format.h" - #include "libimp/detect_plat.h" #if defined(LIBIMP_OS_WIN) # include "libimp/platform/win/system.h" @@ -13,7 +11,7 @@ namespace sys { std::string error_msg(result_code code) noexcept { LIBIMP_TRY { - return ::fmt::format("[{}, \"{}\"]", code.value(), error_str(code)); + return fmt("[", code.value(), ", \"", error_str(code), "\"]"); } LIBIMP_CATCH(...) { return error_str(code); } diff --git a/src/libipc/platform/posix/shm_impl.h b/src/libipc/platform/posix/shm_impl.h index 366f53b..69955be 100644 --- a/src/libipc/platform/posix/shm_impl.h +++ b/src/libipc/platform/posix/shm_impl.h @@ -69,7 +69,7 @@ result shm_open_fd(std::string const &name, mode::type type) noexcept { flag |= O_CREAT; break; default: - log.error("mode type is invalid. type = {}", type); + log.error("mode type is invalid. type = ", type); return {}; } @@ -84,7 +84,7 @@ result_code ftruncate_fd(int fd, std::size_t size) noexcept { /// @see https://man7.org/linux/man-pages/man3/ftruncate.3p.html if (::ftruncate(fd, size) != posix::succ) { auto err = sys::error(); - log.error("failed: ftruncate({}, {}). error = {}", fd, size, err); + log.error("failed: ftruncate(", fd, ", ", size, "). error = ", err); return err.code(); } return {posix::succ}; @@ -102,8 +102,9 @@ result shm_open(std::string name, std::size_t size, mode::type type) noex auto fd = shm_open_fd(name, type); if (!fd) return {}; if (*fd == posix::failed) { - log.error("failed: shm_open(name = {}, type = {}). error = {}", - name, type, sys::error()); + log.error("failed: shm_open(name = ", name, + ", type = ", type, + "). error = ", sys::error()); return {}; } LIBIMP_UNUSED auto guard = std::unique_ptr { @@ -114,7 +115,7 @@ result shm_open(std::string name, std::size_t size, mode::type type) noex /// @brief Try to get the size of this fd struct stat st; if (::fstat(*fd, &st) == posix::failed) { - log.error("failed: fstat(fd = {}). error = {}", *fd, sys::error()); + log.error("failed: fstat(fd = ", *fd, "). error = ", sys::error()); return {}; } @@ -132,7 +133,7 @@ result shm_open(std::string name, std::size_t size, mode::type type) noex /// @brief Creates a new mapping in the virtual address space of the calling process. void *mem = ::mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, *fd, 0); if (mem == MAP_FAILED) { - log.error("failed: mmap(size = {}, fd = {}). error = {}", size, *fd, sys::error()); + log.error("failed: mmap(size = ", size, ", fd = ", *fd, "). error = ", sys::error()); return {}; } return new shm_handle{std::move(name), size, mem}; @@ -147,7 +148,7 @@ result_code shm_close(shm_t h) noexcept { if (shm == nullptr) return {}; if (::munmap(shm->memp, shm->f_sz) == posix::failed) { auto err = sys::error(); - log.error("failed: munmap({}, {}). error = {}", shm->memp, shm->f_sz, err); + log.error("failed: munmap(", shm->memp, ", ", shm->f_sz"). error = ", err); return err.code(); } /// @brief no unlink the file. diff --git a/src/libipc/platform/win/get_sa.h b/src/libipc/platform/win/get_sa.h index 05887ee..3964188 100644 --- a/src/libipc/platform/win/get_sa.h +++ b/src/libipc/platform/win/get_sa.h @@ -30,11 +30,11 @@ inline LPSECURITY_ATTRIBUTES get_sa() { using namespace ::LIBIMP; log::grip log {"get_sa"}; if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) { - log.error("failed: InitializeSecurityDescriptor(SECURITY_DESCRIPTOR_REVISION). error = {}", sys::error()); + log.error("failed: InitializeSecurityDescriptor(SECURITY_DESCRIPTOR_REVISION). error = ", sys::error()); return; } if (!::SetSecurityDescriptorDacl(&sd_, TRUE, NULL, FALSE)) { - log.error("failed: SetSecurityDescriptorDacl. error = {}", sys::error()); + log.error("failed: SetSecurityDescriptorDacl. error = ", sys::error()); return; } sa_.nLength = sizeof(SECURITY_ATTRIBUTES); diff --git a/src/libipc/platform/win/mmap_impl.h b/src/libipc/platform/win/mmap_impl.h index e7392ce..58623db 100644 --- a/src/libipc/platform/win/mmap_impl.h +++ b/src/libipc/platform/win/mmap_impl.h @@ -41,7 +41,7 @@ result_code mmap_close(HANDLE h) { } if (!::CloseHandle(h)) { auto err = sys::error(); - log.error("failed: CloseHandle({}). error = {}", h, err); + log.error("failed: CloseHandle(", h, "). error = ", err); return err.code(); } return {ERROR_SUCCESS}; @@ -77,7 +77,7 @@ result mmap_open(std::string const &file, std::size_t size, mode::type t HANDLE h = ::OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, t_name.c_str()); if (h == NULL) { auto err = sys::error(); - log.error("failed: OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, {}). error = {}", file, err); + log.error("failed: OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, ", file, "). error = ", err); return {nullptr, err.value()}; } return h; @@ -90,7 +90,7 @@ result mmap_open(std::string const &file, std::size_t size, mode::type t 0, static_cast(size), t_name.c_str()); if (h == NULL) { auto err = sys::error(); - log.error("failed: CreateFileMapping(PAGE_READWRITE | SEC_COMMIT, {}, {}). error = {}", size, file, err); + log.error("failed: CreateFileMapping(PAGE_READWRITE | SEC_COMMIT, ", size, ", ", file, "). error = ", err); return {nullptr, err.value()}; } return h; @@ -104,7 +104,7 @@ result mmap_open(std::string const &file, std::size_t size, mode::type t /// https://learn.microsoft.com/en-us/previous-versions/windows/embedded/aa517331(v=msdn.10) return try_open(); } else if (!(type & mode::create)) { - log.error("mode type is invalid. type = {}", type); + log.error("mode type is invalid. type = ", type); return {}; } auto h = try_create(); @@ -112,7 +112,7 @@ result mmap_open(std::string const &file, std::size_t size, mode::type t /// @remark If the object exists before the function call, the function returns a handle to the existing object /// (with its current size, not the specified size), and GetLastError returns ERROR_ALREADY_EXISTS. if ((type == mode::create) && (::GetLastError() == ERROR_ALREADY_EXISTS)) { - log.info("the file being created already exists. file = {}, type = {}", file, type); + log.info("the file being created already exists. file = ", file, ", type = ", type); mmap_close(*h); return {}; } @@ -132,7 +132,7 @@ result mmap_memof(HANDLE h) { LPVOID mem = ::MapViewOfFile(h, FILE_MAP_ALL_ACCESS, 0, 0, 0); if (mem == NULL) { auto err = sys::error(); - log.error("failed: MapViewOfFile({}, FILE_MAP_ALL_ACCESS). error = {}", h, err); + log.error("failed: MapViewOfFile(", h, ", FILE_MAP_ALL_ACCESS). error = ", err); return {nullptr, err.value()}; } return mem; @@ -151,7 +151,7 @@ result mmap_sizeof(LPCVOID mem) { MEMORY_BASIC_INFORMATION mem_info {}; if (::VirtualQuery(mem, &mem_info, sizeof(mem_info)) == 0) { auto err = sys::error(); - log.error("failed: VirtualQuery({}). error = {}", mem, err); + log.error("failed: VirtualQuery(", mem, "). error = ", err); return {false, (SIZE_T)err.value()}; } return mem_info.RegionSize; @@ -172,7 +172,7 @@ result_code mmap_release(HANDLE h, LPCVOID mem) { return {}; } if (!::UnmapViewOfFile(mem)) { - log.warning("failed: UnmapViewOfFile. error = {}", sys::error()); + log.warning("failed: UnmapViewOfFile. error = ", sys::error()); } return mmap_close(h); } diff --git a/src/libipc/platform/win/shm_impl.h b/src/libipc/platform/win/shm_impl.h index d601908..897d94b 100644 --- a/src/libipc/platform/win/shm_impl.h +++ b/src/libipc/platform/win/shm_impl.h @@ -21,18 +21,18 @@ result shm_open(std::string name, std::size_t size, mode::type type) noex LIBIMP_LOG_(); auto h = mmap_open(name, size, type); if (h == NULL) { - log.error("failed: mmap_open(name = {}, size = {}, type = {}).", name, size, type); + log.error("failed: mmap_open(name = ", name, ", size = ", size, ", type = ", type, ")."); return {nullptr, h.code_value()}; } auto mem = mmap_memof(*h); if (*mem == NULL) { - log.error("failed: mmap_memof({}).", *h); + log.error("failed: mmap_memof(", *h, ")."); mmap_close(*h); return {nullptr, mem.code_value()}; } auto sz = mmap_sizeof(*mem); if (!sz) { - log.error("failed: mmap_sizeof({}).", *mem); + log.error("failed: mmap_sizeof(", *mem, ")."); mmap_close(*h); return {nullptr, static_cast(sz.value())}; } diff --git a/src/libpmr/memory_resource.cpp b/src/libpmr/memory_resource.cpp index 7824e5d..9b3b4cc 100644 --- a/src/libpmr/memory_resource.cpp +++ b/src/libpmr/memory_resource.cpp @@ -18,7 +18,7 @@ bool verify_args(::LIBIMP::log::grip &log, std::size_t bytes, std::size_t alignm return false; } if ((alignment == 0) || (alignment & (alignment - 1)) != 0) { - log.error("invalid bytes = {}, alignment = {}", bytes, alignment); + log.error("invalid bytes = ", bytes, ", alignment = ", alignment); return false; } return true; @@ -66,8 +66,9 @@ void *new_delete_resource::allocate(std::size_t bytes, std::size_t alignment) no void *p = nullptr; int ret = ::posix_memalign(&p, alignment, bytes); if (ret != 0) { - log.error("failed: posix_memalign(alignment = {}, bytes = {}). error = {}", - alignment, bytes, sys::error(ret)); + log.error("failed: posix_memalign(alignment = ", alignment, + ", bytes = ", bytes, + "). error = ", sys::error(ret)); return nullptr; } return p; diff --git a/test/concur/test_concur_concurrent.cpp b/test/concur/test_concur_concurrent.cpp index 18efc87..6c43930 100644 --- a/test/concur/test_concur_concurrent.cpp +++ b/test/concur/test_concur_concurrent.cpp @@ -93,7 +93,7 @@ namespace { template void test_concur(std::size_t np, std::size_t nc, std::size_t k) { LIBIMP_LOG_(); - log.info("\n\tStart with: {}, {} producers, {} consumers...", imp::nameof(), np, nc); + log.info("\n\tStart with: ", imp::nameof(), ", ", np, " producers, ", nc, " consumers..."); constexpr static std::uint32_t loop_size = 100'0000; @@ -112,7 +112,7 @@ void test_concur(std::size_t np, std::size_t nc, std::size_t k) { std::this_thread::yield(); } if (i % (loop_size / 10) == 0) { - log.info("[{}] put count: {}", n, i); + log.info("[", n, "] put count: ", i); } } --running; diff --git a/test/imp/test_imp_result.cpp b/test/imp/test_imp_result.cpp index 8230469..e79600f 100644 --- a/test/imp/test_imp_result.cpp +++ b/test/imp/test_imp_result.cpp @@ -69,13 +69,13 @@ TEST(result, fmt) { imp::result r1 {false, -123}; EXPECT_EQ(fmt::format("{}", r1), fmt::format("[fail, value = {}]", -123)); imp::result r2 {&r1}; - EXPECT_EQ(fmt::format("{}", r2), fmt::format("[succ, value = {}]", (void *)&r1)); + EXPECT_EQ(fmt::format("{}", r2), imp::fmt("[succ, value = ", (void *)&r1, "]")); int aaa {}; imp::result r3 {&aaa}; - EXPECT_EQ(fmt::format("{}", r3), fmt::format("[succ, value = {}]", (void *)&aaa)); + EXPECT_EQ(fmt::format("{}", r3), imp::fmt("[succ, value = ", (void *)&aaa, "]")); imp::result r4 {nullptr}; - EXPECT_EQ(fmt::format("{}", r4), fmt::format("[fail, value = {}, code = 0]", nullptr)); + EXPECT_EQ(fmt::format("{}", r4), imp::fmt("[fail, value = ", nullptr, ", code = 0]")); r4 = {nullptr, 1234}; - EXPECT_EQ(fmt::format("{}", r4), fmt::format("[fail, value = {}, code = 1234]", nullptr)); + EXPECT_EQ(fmt::format("{}", r4), imp::fmt("[fail, value = ", nullptr, ", code = 1234]")); } } \ No newline at end of file