mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
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:
parent
28701d2f90
commit
c6a4841cd4
2 changed files with 8 additions and 18 deletions
|
@ -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)())
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
// 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();
|
||||
# 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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue