commit b837a5af5fe67b4bb9ba117eb8083473acbbdb00
parent 1ee15111e93aaf937d6a45167bf76d00bc297c86
Author: cfillion <cfillion@users.noreply.github.com>
Date: Tue, 2 Feb 2021 17:34:58 -0500
api: fix extraction of arguments smaller than a pointer
| void * | void * | void * | # argv from reaper
| const char * | int | int | # bad
| const char * | int | int | # correct
Diffstat:
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/api_helper.hpp b/src/api_helper.hpp
@@ -33,8 +33,7 @@ struct ReaScriptAPI<R(*)(Args...)>
if(static_cast<size_t>(argc) < sizeof...(Args))
return nullptr;
- const auto &voidArgs = makeTuple(argv, std::index_sequence_for<Args...>{});
- const auto &args = *reinterpret_cast<const std::tuple<Args...> *>(&voidArgs);
+ const auto &args = makeTuple(argv, std::index_sequence_for<Args...>{});
if constexpr (std::is_void_v<R>) {
std::apply(fn, args);
@@ -49,10 +48,13 @@ struct ReaScriptAPI<R(*)(Args...)>
}
private:
+ template<size_t I>
+ using NthType = typename std::tuple_element<I, std::tuple<Args...>>::type;
+
template<size_t... I>
static auto makeTuple(void **argv, std::index_sequence<I...>)
{
- return std::make_tuple(argv[I]...);
+ return std::make_tuple((NthType<I>)reinterpret_cast<intptr_t>(argv[I])...);
}
};