Simplify item vtable retrieval in C++

Use a macro instead of a template function to make the getter vs. global
symbol choice.
This commit is contained in:
Simon Hausmann 2021-05-11 07:55:51 +02:00
parent 28701d2f90
commit c6a4841cd4
2 changed files with 8 additions and 18 deletions

View file

@ -204,23 +204,16 @@ inline vtable::Layout drop_in_place(ComponentRef component)
return vtable::Layout { sizeof(T), alignof(T) };
}
template<typename VTableType>
constexpr inline const VTableType *get_vtable(const VTableType *vtable_symbol,
const VTableType *(*getter)())
{
// On Windows cross-dll data relocations are not supported:
// https://docs.microsoft.com/en-us/cpp/c-language/rules-and-limitations-for-dllimport-dllexport?view=msvc-160
// so we have a relocation to a function that returns the address we seek. That
// relocation will be resolved to the locally linked stub library, the implementation of
// which will be patched.
#if defined(_WIN32) || defined(_WIN64)
(void)vtable_symbol;
return getter();
// On Windows cross-dll data relocations are not supported:
// https://docs.microsoft.com/en-us/cpp/c-language/rules-and-limitations-for-dllimport-dllexport?view=msvc-160
// so we have a relocation to a function that returns the address we seek. That
// relocation will be resolved to the locally linked stub library, the implementation of
// which will be patched.
# define SIXTYFPS_GET_ITEM_VTABLE(VTableName) sixtyfps::private_api::sixtyfps_get_##VTableName()
#else
(void)getter;
return vtable_symbol;
# define SIXTYFPS_GET_ITEM_VTABLE(VTableName) (&sixtyfps::private_api::VTableName)
#endif
}
template<typename T>
struct ReturnWrapper

View file

@ -501,10 +501,7 @@ pub struct NativeClass {
impl NativeClass {
pub fn new(class_name: &str) -> Self {
let cpp_vtable_getter = format!(
"sixtyfps::private_api::get_vtable(&sixtyfps::private_api::{}VTable, &sixtyfps::private_api::sixtyfps_get_{}VTable)",
class_name, class_name
);
let cpp_vtable_getter = format!("SIXTYFPS_GET_ITEM_VTABLE({}VTable)", class_name);
Self {
class_name: class_name.into(),
cpp_vtable_getter,