From 2d9a83374760d3b2c36184710e103098566ec3ad Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 4 Jan 2022 17:42:35 +0100 Subject: uhd: Fix non-standard function name macros Throughout UHD, we are using a random mix of __FUNCTION__, __func__, __PRETTY_FUNCTION__, and BOOST_CURRENT_FUNCTION. Note that the first two macros are non-standard (although many compilers understand them), and the last requires Boost. __func__ is available since C++11, but is not the best choice because the C++ standard doesn't require it to be of any specific value. We thus define UHD_FUNCTION and UHD_PRETTY_FUNCTION as portable macros. The former simply contains the undecorated function name, the latter the expanded function with full signature. As it happens, our currently supported compilers didn't have any issues using non-standard macros, so the main fix here is the removal of the Boost macros and the harmonization of the other macros. --- host/include/uhd/config.hpp | 10 ++++++++++ host/include/uhd/exception.hpp | 9 ++++----- host/include/uhd/utils/log.hpp | 3 +-- 3 files changed, 15 insertions(+), 7 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp index 8504e0c18..c2b3f7f45 100644 --- a/host/include/uhd/config.hpp +++ b/host/include/uhd/config.hpp @@ -56,6 +56,8 @@ typedef SSIZE_T ssize_t; # define UHD_ALIGNED(x) __declspec(align(x)) # define UHD_UNUSED(x) x # define UHD_FALLTHROUGH +# define UHD_FUNCTION __FUNCTION__ +# define UHD_PRETTY_FUNCTION __FUNCSIG__ #elif defined(__MINGW32__) # define UHD_EXPORT __declspec(dllexport) # define UHD_IMPORT __declspec(dllimport) @@ -65,6 +67,8 @@ typedef SSIZE_T ssize_t; # define UHD_ALIGNED(x) __declspec(align(x)) # define UHD_UNUSED(x) x __attribute__((unused)) # define UHD_FALLTHROUGH +# define UHD_FUNCTION __func__ +# define UHD_PRETTY_FUNCTION __PRETTY_FUNCTION__ #elif defined(__GNUG__) && __GNUG__ >= 4 # define UHD_EXPORT __attribute__((visibility("default"))) # define UHD_IMPORT __attribute__((visibility("default"))) @@ -78,6 +82,8 @@ typedef SSIZE_T ssize_t; # else # define UHD_FALLTHROUGH # endif +# define UHD_FUNCTION __func__ +# define UHD_PRETTY_FUNCTION __PRETTY_FUNCTION__ #elif defined(__clang__) # define UHD_EXPORT __attribute__((visibility("default"))) # define UHD_IMPORT __attribute__((visibility("default"))) @@ -91,6 +97,8 @@ typedef SSIZE_T ssize_t; # else # define UHD_FALLTHROUGH # endif +# define UHD_FUNCTION __func__ +# define UHD_PRETTY_FUNCTION __PRETTY_FUNCTION__ #else # define UHD_EXPORT # define UHD_IMPORT @@ -100,6 +108,8 @@ typedef SSIZE_T ssize_t; # define UHD_ALIGNED(x) # define UHD_UNUSED(x) x # define UHD_FALLTHROUGH +# define UHD_FUNCTION __func__ +# define UHD_PRETTY_FUNCTION __func__ #endif // Define API declaration macro diff --git a/host/include/uhd/exception.hpp b/host/include/uhd/exception.hpp index f48f97ba3..d0f886a18 100644 --- a/host/include/uhd/exception.hpp +++ b/host/include/uhd/exception.hpp @@ -8,7 +8,6 @@ #pragma once #include -#include #include #include @@ -302,10 +301,10 @@ struct UHD_API routing_error : rfnoc_error * \param what the std::exception message * \return the formatted exception message */ -#define UHD_THROW_SITE_INFO(what) \ - std::string(std::string(what) + "\n" + " in " + std::string(BOOST_CURRENT_FUNCTION) \ - + "\n" + " at " + std::string(__FILE__) + ":" \ - + BOOST_STRINGIZE(__LINE__) + "\n") +#define UHD_THROW_SITE_INFO(what) \ + std::string(std::string(what) + "\n" + " in " + std::string(UHD_FUNCTION) + "\n" \ + + " at " + std::string(__FILE__) + ":" + BOOST_STRINGIZE(__LINE__) \ + + "\n") /*! * Throws an invalid code path exception with throw-site information. diff --git a/host/include/uhd/utils/log.hpp b/host/include/uhd/utils/log.hpp index f333f9594..7b76ec075 100644 --- a/host/include/uhd/utils/log.hpp +++ b/host/include/uhd/utils/log.hpp @@ -8,7 +8,6 @@ #pragma once #include -#include #include #include #include @@ -264,7 +263,7 @@ UHD_API void set_logger_level(const std::string& logger, uhd::log::severity_leve //! Helpful debug tool to print site info # define UHD_HERE() \ UHD_LOGGER_DEBUG("DEBUG") \ - << __FILE__ << ":" << __LINE__ << " (" << __PRETTY_FUNCTION__ << ")"; + << __FILE__ << ":" << __LINE__ << " (" << UHD_PRETTY_FUNCTION << ")"; #else //! Helpful debug tool to print site info # define UHD_HERE() UHD_LOGGER_DEBUG("DEBUG") << __FILE__ << ":" << __LINE__; -- cgit v1.2.3