From cc3eeef1886500b5efc54c0a34e9b3c89bd7aa35 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 16 Nov 2020 15:21:19 +0800 Subject: [PATCH] log/Log: cast typed pointer to integer before printing it libfmt does not print pointer if it's not "void*", but "thread_t" is defined as a pointer pointing to "struct pthread" on FreeBSD, so we need to cast it either to "void*" or an integer". let's cast it to an integer so it's more consistent with the output on Linux where thread_t is defined as an integer. this change addresses the FTBFS on FreeBSD likee: In file included from /home/jenkins/workspace/ceph-master-compile/src/log/Log.cc:27: In file included from /usr/local/include/fmt/format.h:44: /usr/local/include/fmt/core.h:1043:20: error: invalid application of 'sizeof' to an incomplete type 'pthread' static_assert(!sizeof(T), "formatting of non-void pointers is disallowed"); ^~~~~~~~~ /usr/local/include/fmt/core.h:1259:32: note: in instantiation of function template specialization 'fmt::v7::detail::arg_mapper >, char> >::map' requested here return arg_mapper().map(val); ^ /usr/local/include/fmt/core.h:1408:23: note: in instantiation of function template specialization 'fmt::v7::detail::make_arg >, char>, fmt::v7::detail::type::int_type, pthread *, 0>' requested here data_{detail::make_arg< ^ /usr/local/include/fmt/core.h:1764:10: note: in instantiation of member function 'fmt::v7::format_arg_store >, char>, pthread *const, char *>::format_arg_store' requested here return {args...}; ^ /usr/local/include/fmt/core.h:1835:31: note: in instantiation of function template specialization 'fmt::v7::detail::make_args_checked' requested here const auto& vargs = detail::make_args_checked(format_str, args...); ^ /home/jenkins/workspace/ceph-master-compile/src/log/Log.cc:376:23: note: in instantiation of function template specialization 'fmt::v7::format' requested here _log_message(fmt::format(" {} / {}", pthread_id, (char*)pthread_name), true); ^ /usr/include/sys/_pthreadtypes.h:46:8: note: forward declaration of 'pthread' struct pthread; ^ 1 error generated. Signed-off-by: Kefu Chai --- src/log/Log.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/log/Log.cc b/src/log/Log.cc index 6d2647f579f..28f1dbf21e3 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -330,6 +330,16 @@ void Log::_log_message(std::string_view s, bool crash) } } +template +static uint64_t tid_to_int(T tid) +{ + if constexpr (std::is_pointer_v) { + return reinterpret_cast(tid); + } else { + return tid; + } +} + void Log::dump_recent() { std::scoped_lock lock1(m_flush_mutex); @@ -372,7 +382,8 @@ void Log::dump_recent() { char pthread_name[16] = {0}; //limited by 16B include terminating null byte. ceph_pthread_getname(pthread_id, pthread_name, sizeof(pthread_name)); - _log_message(fmt::format(" {} / {}", pthread_id, pthread_name), true); + _log_message(fmt::format(" {} / {}", + tid_to_int(pthread_id), pthread_name), true); } _log_message(fmt::format(" max_recent {:9}", m_max_recent), true); -- 2.39.5