diff options
-rw-r--r-- | libbutl/utility.ixx | 9 | ||||
-rw-r--r-- | libbutl/utility.mxx | 6 | ||||
-rw-r--r-- | libbutl/uuid-linux.cxx | 13 |
3 files changed, 17 insertions, 11 deletions
diff --git a/libbutl/utility.ixx b/libbutl/utility.ixx index 565a694..e17462a 100644 --- a/libbutl/utility.ixx +++ b/libbutl/utility.ixx @@ -212,4 +212,13 @@ namespace butl return nullopt; } + + template <typename F> + inline F + function_cast (void* p) + { + union { void* p; F f; } r; + r.p = p; + return r.f; + } } diff --git a/libbutl/utility.mxx b/libbutl/utility.mxx index 54c7b43..f944599 100644 --- a/libbutl/utility.mxx +++ b/libbutl/utility.mxx @@ -315,6 +315,12 @@ LIBBUTL_MODEXPORT namespace butl F f_; }; + // Cleanly cast dlsym() result (void*) to a function pointer. + // + template <typename F> + F + function_cast (void*); + // Call a function if there is an exception. // diff --git a/libbutl/uuid-linux.cxx b/libbutl/uuid-linux.cxx index 7396910..cae8aae 100644 --- a/libbutl/uuid-linux.cxx +++ b/libbutl/uuid-linux.cxx @@ -14,6 +14,8 @@ #include <utility> // move() #include <system_error> +#include <libbutl/utility.mxx> // function_cast() + using namespace std; namespace butl @@ -48,17 +50,6 @@ namespace butl static void* libuuid; - // Use a union to cleanly cast dlsym() result (void*) to a function pointer. - // - template <typename F> - static inline F - function_cast (void* p) - { - union { void* p; F f; } r; - r.p = p; - return r.f; - }; - static inline void dlfail (string what) { |