Skip to content

Commit

Permalink
dynalib: fixes C++ variant of DYNALIB_FN_EXPORT() with recent GCC ver…
Browse files Browse the repository at this point in the history
…sions
  • Loading branch information
avtolstoy authored and YutingYou committed Dec 10, 2019
1 parent edf805c commit e68fab4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions dynalib/inc/dynalib.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,19 @@

#include <type_traits>

// XXX: casting is not allowed in constexpr functions (at least since C++14).
// We were previously casting to const void* in dynalib_checked_cast(), which resulted in
// dynalib tables being placed into .bss section with certain GCC versions.
// Miraculously, everything works correctly if the cast is outside of the constexpr function.

template<typename T1, typename T2>
constexpr const void* dynalib_checked_cast(T2 *p) {
constexpr T2* dynalib_checked_cast(T2 *p) {
static_assert(std::is_same<T1, T2>::value, "Signature of the dynamically exported function has changed");
return (const void*)p;
return p;
}

#define DYNALIB_FN_EXPORT(index, tablename, name, type) \
dynalib_checked_cast<type>(name),
reinterpret_cast<const void*>(dynalib_checked_cast<type>(name)),

#define DYNALIB_STATIC_ASSERT(cond, msg) \
static_assert(cond, msg)
Expand Down

0 comments on commit e68fab4

Please sign in to comment.