Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "C-unwind" API in our vtable #6930

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ slint-cpp = { version = "=1.9.0", path = "api/cpp", default-features = false }
slint-interpreter = { version = "=1.9.0", path = "internal/interpreter", default-features = false }
slint-macros = { version = "=1.9.0", path = "api/rs/macros", default-features = false }

vtable = { version = "0.2", path = "helper_crates/vtable", default-features = false }
vtable = { version = "0.2.1", path = "helper_crates/vtable", default-features = false }

by_address = { version = "1.0.4" }
bytemuck = { version = "1.13.1" }
Expand Down
4 changes: 2 additions & 2 deletions helper_crates/vtable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "vtable"
version = "0.2.0"
version = "0.2.1"
authors = ["Slint Developers <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -14,7 +14,7 @@ homepage = "https://slint.dev"
[lib]

[dependencies]
vtable-macro = { version = "=0.2.0", path = "./macro" }
vtable-macro = { version = "=0.2.1", path = "./macro" }
const-field-offset = { version = "0.1", path = "../const-field-offset" }
stable_deref_trait = { version = "1.2.0", default-features = false }
portable-atomic = "1"
2 changes: 1 addition & 1 deletion helper_crates/vtable/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "vtable-macro"
version = "0.2.0"
version = "0.2.1"
authors = ["Slint Developers <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
11 changes: 8 additions & 3 deletions helper_crates/vtable/macro/macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ pub fn vtable(_attr: TokenStream, item: TokenStream) -> TokenStream {
};

let mut sig_extern = sig.clone();
sig_extern.abi = Some(parse_str("extern \"C\"").unwrap());
sig_extern.generics = parse_str(&format!("<T : {}>", trait_name)).unwrap();

// check parameters
Expand Down Expand Up @@ -389,12 +388,18 @@ pub fn vtable(_attr: TokenStream, item: TokenStream) -> TokenStream {

// Add extern "C" if it isn't there
if let Some(a) = &f.abi {
if !a.name.as_ref().map(|s| s.value() == "C").unwrap_or(false) {
if !a
.name
.as_ref()
.map(|s| matches!(s.value().as_str(), "C" | "C-unwind"))
.unwrap_or(false)
{
return Error::new(a.span(), "invalid ABI").to_compile_error().into();
}
} else {
f.abi.clone_from(&sig_extern.abi);
f.abi = Some(parse_str("extern \"C\"").unwrap());
}
sig_extern.abi.clone_from(&f.abi);

let mut wrap_trait_call = None;
if !has_self {
Expand Down
4 changes: 2 additions & 2 deletions helper_crates/vtable/tests/test_vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use vtable::*;
/// This is the actual doc
struct HelloVTable {
foo: fn(VRef<'_, HelloVTable>, u32) -> u32,
foo_mut: fn(VRefMut<'_, HelloVTable>, u32) -> u32,
foo_mut: extern "C" fn(VRefMut<'_, HelloVTable>, u32) -> u32,
construct: fn(*const HelloVTable, u32) -> VBox<HelloVTable>,
assoc: fn(*const HelloVTable) -> isize,
with_lifetime: fn(VRef<'_, HelloVTable>) -> &'_ u32,
with_lifetime: extern "C-unwind" fn(VRef<'_, HelloVTable>) -> &'_ u32,

drop: fn(VRefMut<'_, HelloVTable>),

Expand Down
41 changes: 23 additions & 18 deletions internal/core/item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,25 @@ pub struct ItemTreeVTable {
/// Visit the children of the item at index `index`.
/// Note that the root item is at index 0, so passing 0 would visit the item under root (the children of root).
/// If you want to visit the root item, you need to pass -1 as an index.
pub visit_children_item: extern "C" fn(
pub visit_children_item: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemTreeVTable>>,
index: isize,
order: TraversalOrder,
visitor: VRefMut<ItemVisitorVTable>,
) -> VisitChildrenResult,

/// Return a reference to an item using the given index
pub get_item_ref: extern "C" fn(
pub get_item_ref: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemTreeVTable>>,
index: u32,
) -> core::pin::Pin<VRef<ItemVTable>>,

/// Return the range of indices below the dynamic `ItemTreeNode` at `index`
pub get_subtree_range:
extern "C" fn(core::pin::Pin<VRef<ItemTreeVTable>>, index: u32) -> IndexRange,
extern "C-unwind" fn(core::pin::Pin<VRef<ItemTreeVTable>>, index: u32) -> IndexRange,

/// Return the `ItemTreeRc` at `subindex` below the dynamic `ItemTreeNode` at `index`
pub get_subtree: extern "C" fn(
pub get_subtree: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemTreeVTable>>,
index: u32,
subindex: usize,
Expand All @@ -75,70 +75,75 @@ pub struct ItemTreeVTable {
/// Return the item tree that is defined by this `ItemTree`.
/// The return value is an item weak because it can be null if there is no parent.
/// And the return value is passed by &mut because ItemWeak has a destructor
pub get_item_tree: extern "C" fn(core::pin::Pin<VRef<ItemTreeVTable>>) -> Slice<ItemTreeNode>,
pub get_item_tree:
extern "C-unwind" fn(core::pin::Pin<VRef<ItemTreeVTable>>) -> Slice<ItemTreeNode>,

/// Return the node this ItemTree is a part of in the parent ItemTree.
///
/// The return value is an item weak because it can be null if there is no parent.
/// And the return value is passed by &mut because ItemWeak has a destructor
/// Note that the returned value will typically point to a repeater node, which is
/// strictly speaking not an Item at all!
pub parent_node: extern "C" fn(core::pin::Pin<VRef<ItemTreeVTable>>, result: &mut ItemWeak),
pub parent_node:
extern "C-unwind" fn(core::pin::Pin<VRef<ItemTreeVTable>>, result: &mut ItemWeak),

/// This embeds this ItemTree into the item tree of another ItemTree
///
/// Returns `true` if this ItemTree was embedded into the `parent`
/// at `parent_item_tree_index`.
pub embed_component: extern "C" fn(
pub embed_component: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemTreeVTable>>,
parent: &VWeak<ItemTreeVTable>,
parent_item_tree_index: u32,
) -> bool,

/// Return the index of the current subtree or usize::MAX if this is not a subtree
pub subtree_index: extern "C" fn(core::pin::Pin<VRef<ItemTreeVTable>>) -> usize,
pub subtree_index: extern "C-unwind" fn(core::pin::Pin<VRef<ItemTreeVTable>>) -> usize,

/// Returns the layout info for the root of the ItemTree
pub layout_info: extern "C" fn(core::pin::Pin<VRef<ItemTreeVTable>>, Orientation) -> LayoutInfo,
pub layout_info:
extern "C-unwind" fn(core::pin::Pin<VRef<ItemTreeVTable>>, Orientation) -> LayoutInfo,

/// Returns the item's geometry (relative to its parent item)
pub item_geometry:
extern "C" fn(core::pin::Pin<VRef<ItemTreeVTable>>, item_index: u32) -> LogicalRect,
extern "C-unwind" fn(core::pin::Pin<VRef<ItemTreeVTable>>, item_index: u32) -> LogicalRect,

/// Returns the accessible role for a given item
pub accessible_role:
extern "C" fn(core::pin::Pin<VRef<ItemTreeVTable>>, item_index: u32) -> AccessibleRole,
pub accessible_role: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemTreeVTable>>,
item_index: u32,
) -> AccessibleRole,

/// Returns the accessible property via the `result`. Returns true if such a property exists.
pub accessible_string_property: extern "C" fn(
pub accessible_string_property: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemTreeVTable>>,
item_index: u32,
what: AccessibleStringProperty,
result: &mut SharedString,
) -> bool,

/// Executes an accessibility action.
pub accessibility_action: extern "C" fn(
pub accessibility_action: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemTreeVTable>>,
item_index: u32,
action: &AccessibilityAction,
),

/// Returns the supported accessibility actions.
pub supported_accessibility_actions: extern "C" fn(
pub supported_accessibility_actions: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemTreeVTable>>,
item_index: u32,
) -> SupportedAccessibilityAction,

/// Add the `ElementName::id` entries of the given item
pub item_element_infos: extern "C" fn(
pub item_element_infos: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemTreeVTable>>,
item_index: u32,
result: &mut SharedString,
) -> bool,

/// Returns a Window, creating a fresh one if `do_create` is true.
pub window_adapter: extern "C" fn(
pub window_adapter: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemTreeVTable>>,
do_create: bool,
result: &mut Option<WindowAdapterRc>,
Expand Down Expand Up @@ -1162,7 +1167,7 @@ pub(crate) mod ffi {
index: isize,
order: TraversalOrder,
visitor: VRefMut<ItemVisitorVTable>,
visit_dynamic: extern "C" fn(
visit_dynamic: extern "C-unwind" fn(
base: *const c_void,
order: TraversalOrder,
visitor: vtable::VRefMut<ItemVisitorVTable>,
Expand Down
14 changes: 7 additions & 7 deletions internal/core/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub struct ItemVTable {
/// This function is called by the run-time after the memory for the item
/// has been allocated and initialized. It will be called before any user specified
/// bindings are set.
pub init: extern "C" fn(core::pin::Pin<VRef<ItemVTable>>, my_item: &ItemRc),
pub init: extern "C-unwind" fn(core::pin::Pin<VRef<ItemVTable>>, my_item: &ItemRc),

/// offset in bytes from the *const ItemImpl.
/// isize::MAX means None
Expand All @@ -122,7 +122,7 @@ pub struct ItemVTable {
pub cached_rendering_data_offset: usize,

/// We would need max/min/preferred size, and all layout info
pub layout_info: extern "C" fn(
pub layout_info: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemVTable>>,
orientation: Orientation,
window_adapter: &WindowAdapterRc,
Expand All @@ -132,36 +132,36 @@ pub struct ItemVTable {
/// Then, depending on the return value, it is called for the children, and their children, then
/// [`Self::input_event`] is called on the children, and finally [`Self::input_event`] is called
/// on this item again.
pub input_event_filter_before_children: extern "C" fn(
pub input_event_filter_before_children: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemVTable>>,
MouseEvent,
window_adapter: &WindowAdapterRc,
self_rc: &ItemRc,
) -> InputEventFilterResult,

/// Handle input event for mouse and touch event
pub input_event: extern "C" fn(
pub input_event: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemVTable>>,
MouseEvent,
window_adapter: &WindowAdapterRc,
self_rc: &ItemRc,
) -> InputEventResult,

pub focus_event: extern "C" fn(
pub focus_event: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemVTable>>,
&FocusEvent,
window_adapter: &WindowAdapterRc,
self_rc: &ItemRc,
) -> FocusEventResult,

pub key_event: extern "C" fn(
pub key_event: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemVTable>>,
&KeyEvent,
window_adapter: &WindowAdapterRc,
self_rc: &ItemRc,
) -> KeyEventResult,

pub render: extern "C" fn(
pub render: extern "C-unwind" fn(
core::pin::Pin<VRef<ItemVTable>>,
backend: &mut ItemRendererRef,
self_rc: &ItemRc,
Expand Down
Loading
Loading