diff --git a/Cargo.toml b/Cargo.toml index 7da23d5..5a30350 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.23.0" authors = ["The AccessKit contributors"] license = "MIT OR Apache-2.0" publish = false -edition = "2021" +edition = "2024" rust-version = "1.87" [lib] diff --git a/src/android.rs b/src/android.rs index ede4c11..1662237 100644 --- a/src/android.rs +++ b/src/android.rs @@ -7,9 +7,9 @@ use accesskit_android::*; use std::os::raw::c_void; use crate::{ - box_from_ptr, mut_from_ptr, ref_from_ptr, tree_update_factory, tree_update_factory_userdata, ActionHandlerCallback, ActivationHandlerCallback, BoxCastPtr, CastPtr, FfiActionHandler, - FfiActivationHandler, + FfiActivationHandler, box_from_ptr, mut_from_ptr, ref_from_ptr, tree_update_factory, + tree_update_factory_userdata, }; pub struct android_platform_action { @@ -23,7 +23,7 @@ impl CastPtr for android_platform_action { impl BoxCastPtr for android_platform_action {} impl android_platform_action { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_platform_action_from_java( env: *mut jni::sys::JNIEnv, action: jni::sys::jint, @@ -35,7 +35,7 @@ impl android_platform_action { BoxCastPtr::to_nullable_mut_ptr(platform_action) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_platform_action_free(action: *mut android_platform_action) { drop(box_from_ptr(action)); } @@ -53,7 +53,7 @@ impl BoxCastPtr for android_queued_events {} impl android_queued_events { /// Memory is also freed when calling this function. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_queued_events_raise( events: *mut android_queued_events, env: *mut jni::sys::JNIEnv, @@ -77,19 +77,19 @@ impl CastPtr for android_adapter { impl BoxCastPtr for android_adapter {} impl android_adapter { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_adapter_new() -> *mut android_adapter { let adapter = Adapter::default(); BoxCastPtr::to_mut_ptr(adapter) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_adapter_free(adapter: *mut android_adapter) { drop(box_from_ptr(adapter)); } /// You must call `accesskit_android_queued_events_raise` on the returned pointer. It can be null if the adapter is not active. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_adapter_update_if_active( adapter: *mut android_adapter, update_factory: tree_update_factory, @@ -103,7 +103,7 @@ impl android_adapter { BoxCastPtr::to_nullable_mut_ptr(events) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_adapter_create_accessibility_node_info( adapter: *mut android_adapter, activation_handler: ActivationHandlerCallback, @@ -127,7 +127,7 @@ impl android_adapter { .into_raw() } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_adapter_find_focus( adapter: *mut android_adapter, activation_handler: ActivationHandlerCallback, @@ -147,7 +147,7 @@ impl android_adapter { } /// You must call `accesskit_android_queued_events_raise` on the returned pointer. It can be null if the adapter is not active. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_adapter_perform_action( adapter: *mut android_adapter, action_handler: ActionHandlerCallback, @@ -163,7 +163,7 @@ impl android_adapter { } /// You must call `accesskit_android_queued_events_raise` on the returned pointer. It can be null if the adapter is not active. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_adapter_on_hover_event( adapter: *mut android_adapter, activation_handler: ActivationHandlerCallback, @@ -191,7 +191,7 @@ impl CastPtr for android_injecting_adapter { impl BoxCastPtr for android_injecting_adapter {} impl android_injecting_adapter { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_injecting_adapter_new( env: *mut jni::sys::JNIEnv, host: jni::sys::jobject, @@ -209,14 +209,14 @@ impl android_injecting_adapter { BoxCastPtr::to_mut_ptr(adapter) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_injecting_adapter_free( adapter: *mut android_injecting_adapter, ) { drop(box_from_ptr(adapter)); } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_android_injecting_adapter_update_if_active( adapter: *mut android_injecting_adapter, update_factory: tree_update_factory, diff --git a/src/common.rs b/src/common.rs index 9bab8ba..9a5586e 100644 --- a/src/common.rs +++ b/src/common.rs @@ -12,8 +12,8 @@ use std::{ }; use crate::{ - box_from_ptr, debug_repr_from_ptr, mut_from_ptr, opt_struct, ref_from_ptr, string_from_c_slice, - BoxCastPtr, CastPtr, + BoxCastPtr, CastPtr, box_from_ptr, debug_repr_from_ptr, mut_from_ptr, opt_struct, ref_from_ptr, + string_from_c_slice, }; pub struct node { @@ -29,7 +29,7 @@ impl BoxCastPtr for node {} macro_rules! clearer { ($c_clearer:ident, $clearer:ident) => { impl node { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $c_clearer(node: *mut node) { let node = mut_from_ptr(node); node.$clearer() @@ -41,12 +41,12 @@ macro_rules! clearer { macro_rules! flag_methods { ($(($c_getter:ident, $getter:ident, $c_setter:ident, $setter:ident, $c_clearer:ident, $clearer:ident)),+) => { $(impl node { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $c_getter(node: *const node) -> bool { let node = ref_from_ptr(node); node.$getter() } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $c_setter(node: *mut node) { let node = mut_from_ptr(node); node.$setter() @@ -60,7 +60,7 @@ macro_rules! array_setter { ($c_setter:ident, $setter:ident, $ffi_type:ty, $rust_type:ty) => { impl node { /// Caller is responsible for freeing `values`. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $c_setter(node: *mut node, length: usize, values: *const $ffi_type) { let node = mut_from_ptr(node); let values = if length == 0 { @@ -83,7 +83,7 @@ macro_rules! array_setter { macro_rules! property_getters { ($c_getter:ident, $getter:ident, *const $getter_result:tt) => { impl node { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $c_getter(node: *const node) -> *const $getter_result { let node = ref_from_ptr(node); match node.$getter() { @@ -105,7 +105,7 @@ macro_rules! property_getters { }; ($c_getter:ident, $getter:ident, $getter_result:tt) => { impl node { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $c_getter(node: *const node) -> $getter_result { let node = ref_from_ptr(node); node.$getter().into() @@ -118,7 +118,7 @@ macro_rules! simple_property_methods { ($c_getter:ident, $getter:ident, $getter_result:tt, $c_setter:ident, $setter:ident, $setter_param:tt, $c_clearer:ident, $clearer:ident) => { property_getters! { $c_getter, $getter, $getter_result } impl node { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $c_setter(node: *mut node, value: $setter_param) { let node = mut_from_ptr(node); node.$setter(value.into()); @@ -129,7 +129,7 @@ macro_rules! simple_property_methods { ($c_getter:ident, $getter:ident, *const $getter_result:tt, $c_setter:ident, $setter:ident, $setter_param:tt, $c_clearer:ident, $clearer:ident) => { property_getters! { $c_getter, $getter, *const $getter_result } impl node { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $c_setter(node: *mut node, value: $setter_param) { let node = mut_from_ptr(node); node.$setter(Box::new(value)); @@ -191,7 +191,7 @@ macro_rules! vec_property_methods { $(property_getters! { $c_getter, $getter, $getter_result } array_setter! { $c_setter, $setter, $setter_param, $item_type } impl node { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $c_pusher(node: *mut node, item: $setter_param) { let node = mut_from_ptr(node); node.$pusher(item.into()); @@ -223,7 +223,7 @@ impl From for TreeId { } } -#[no_mangle] +#[unsafe(no_mangle)] pub static ACCESSKIT_TREE_ID_ROOT: tree_id = tree_id { bytes: [0; 16] }; slice_struct! { node_ids, NodeId, node_id } @@ -249,7 +249,7 @@ macro_rules! string_property_methods { ($(($c_getter:ident, $getter:ident, $c_setter:ident, $c_setter_with_length:ident, $setter:ident, $c_clearer:ident, $clearer:ident)),+) => { $(impl node { /// Caller must call `accesskit_string_free` with the return value. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $c_getter(node: *const node) -> *mut c_char { let node = ref_from_ptr(node); match node.$getter() { @@ -258,14 +258,14 @@ macro_rules! string_property_methods { } } /// Caller is responsible for freeing the memory pointed by `value`. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $c_setter(node: *mut node, value: *const c_char) { let node = mut_from_ptr(node); let value = unsafe { CStr::from_ptr(value) }; node.$setter(value.to_string_lossy()); } /// Caller is responsible for freeing the memory pointed by `value`. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn $c_setter_with_length(node: *mut node, value: *const c_char, length: usize) { let node = mut_from_ptr(node); node.$setter(unsafe { string_from_c_slice(value, length) }); @@ -390,7 +390,7 @@ macro_rules! unique_enum_property_methods { property_getters! { accesskit_node_role, role, Role } impl node { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_set_role(node: *mut node, value: Role) { let node = mut_from_ptr(node); node.set_role(value); @@ -398,25 +398,25 @@ impl node { } impl node { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_supports_action(node: *const node, action: Action) -> bool { let node = ref_from_ptr(node); node.supports_action(action) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_add_action(node: *mut node, action: Action) { let node = mut_from_ptr(node); node.add_action(action); } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_remove_action(node: *mut node, action: Action) { let node = mut_from_ptr(node); node.remove_action(action); } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_clear_actions(node: *mut node) { let node = mut_from_ptr(node); node.clear_actions(); @@ -424,7 +424,7 @@ impl node { /// Return whether the specified action is in the set supported on this node's /// direct children in the filtered tree. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_child_supports_action( node: *const node, action: Action, @@ -435,7 +435,7 @@ impl node { /// Add the specified action to the set supported on this node's direct /// children in the filtered tree. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_add_child_action(node: *mut node, action: Action) { let node = mut_from_ptr(node); node.add_child_action(action); @@ -443,7 +443,7 @@ impl node { /// Remove the specified action from the set supported on this node's direct /// children in the filtered tree. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_remove_child_action(node: *mut node, action: Action) { let node = mut_from_ptr(node); node.remove_child_action(action); @@ -451,7 +451,7 @@ impl node { /// Clear the set of actions supported on this node's direct children in the /// filtered tree. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_clear_child_actions(node: *mut node) { let node = mut_from_ptr(node); node.clear_child_actions(); @@ -507,7 +507,7 @@ simple_property_methods! { } /// Only call this function with a string that originated from AccessKit. -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_string_free(string: *mut c_char) { assert!(!string.is_null()); drop(unsafe { CString::from_raw(string) }); @@ -678,7 +678,7 @@ impl From<&TextSelection> for text_selection { opt_struct! { opt_text_selection, text_selection } property_getters! { accesskit_node_text_selection, text_selection, opt_text_selection } impl node { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_set_text_selection(node: *mut node, value: text_selection) { let node = mut_from_ptr(node); node.set_text_selection(Box::new(value.into())); @@ -697,7 +697,7 @@ impl CastPtr for custom_action { impl BoxCastPtr for custom_action {} impl custom_action { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_custom_action_new(id: i32) -> *mut custom_action { let action = CustomAction { id, @@ -706,25 +706,25 @@ impl custom_action { BoxCastPtr::to_mut_ptr(action) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_custom_action_free(action: *mut custom_action) { drop(box_from_ptr(action)); } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_custom_action_id(action: *const custom_action) -> i32 { let action = ref_from_ptr(action); action.id } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_custom_action_set_id(action: *mut custom_action, id: i32) { let action = mut_from_ptr(action); action.id = id; } /// Caller must call `accesskit_string_free` with the return value. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_custom_action_description( action: *const custom_action, ) -> *mut c_char { @@ -733,7 +733,7 @@ impl custom_action { } /// Caller is responsible for freeing the memory pointed by `description`. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_custom_action_set_description( action: *mut custom_action, description: *const c_char, @@ -745,7 +745,7 @@ impl custom_action { } /// Caller is responsible for freeing the memory pointed by `description`. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_custom_action_set_description_with_length( action: *mut custom_action, description: *const c_char, @@ -769,7 +769,7 @@ impl CastPtr for custom_actions { impl BoxCastPtr for custom_actions {} impl custom_actions { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_custom_actions_free(value: *mut custom_actions) { let array = box_from_ptr(value); let values = unsafe { Vec::from_raw_parts(array.values, array.length, array.length) }; @@ -799,7 +799,7 @@ impl From<&[CustomAction]> for custom_actions { impl node { /// Caller must call `accesskit_custom_actions_free` with the return value. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_custom_actions(node: *const node) -> *mut custom_actions { let node = ref_from_ptr(node); BoxCastPtr::to_mut_ptr(node.custom_actions().into()) @@ -807,7 +807,7 @@ impl node { /// Caller is responsible for freeing each `custom_action` in the array /// as well as the `values` array itself. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_set_custom_actions( node: *mut node, length: usize, @@ -828,7 +828,7 @@ impl node { } /// Takes ownership of `action`. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_push_custom_action( node: *mut node, action: *mut custom_action, @@ -842,19 +842,19 @@ impl node { clearer! { accesskit_node_clear_custom_actions, clear_custom_actions } impl node { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_new(role: Role) -> *mut node { let node = Node::new(role); BoxCastPtr::to_mut_ptr(node) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_free(node: *mut node) { drop(box_from_ptr(node)); } /// Caller must call `accesskit_string_free` with the return value. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_node_debug(node: *const node) -> *mut c_char { debug_repr_from_ptr(node) } @@ -871,19 +871,19 @@ impl CastPtr for tree_info { impl BoxCastPtr for tree_info {} impl tree_info { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_info_new(root: node_id) -> *mut tree_info { let tree = TreeInfo::new(root.into()); BoxCastPtr::to_mut_ptr(tree) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_info_free(tree: *mut tree_info) { drop(box_from_ptr(tree)); } /// Caller must call `accesskit_string_free` with the return value. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_info_get_toolkit_name(tree: *const tree_info) -> *mut c_char { let tree = ref_from_ptr(tree); match tree.toolkit_name.as_ref() { @@ -893,7 +893,7 @@ impl tree_info { } /// Caller is responsible for freeing the memory pointed by `toolkit_name` - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_info_set_toolkit_name( tree: *mut tree_info, toolkit_name: *const c_char, @@ -905,7 +905,7 @@ impl tree_info { } /// Caller is responsible for freeing the memory pointed by `toolkit_name` - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_info_set_toolkit_name_with_length( tree: *mut tree_info, toolkit_name: *const c_char, @@ -915,14 +915,14 @@ impl tree_info { tree.toolkit_name = Some(unsafe { string_from_c_slice(toolkit_name, length) }) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_info_clear_toolkit_name(tree: *mut tree_info) { let tree = mut_from_ptr(tree); tree.toolkit_name = None; } /// Caller must call `accesskit_string_free` with the return value. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_info_get_toolkit_version( tree: *const tree_info, ) -> *mut c_char { @@ -934,7 +934,7 @@ impl tree_info { } /// Caller is responsible for freeing the memory pointed by `toolkit_version` - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_info_set_toolkit_version( tree: *mut tree_info, toolkit_version: *const c_char, @@ -946,7 +946,7 @@ impl tree_info { } /// Caller is responsible for freeing the memory pointed by `toolkit_version` - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_info_set_toolkit_version_with_length( tree: *mut tree_info, toolkit_version: *const c_char, @@ -956,14 +956,14 @@ impl tree_info { tree.toolkit_version = Some(unsafe { string_from_c_slice(toolkit_version, length) }); } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_info_clear_toolkit_version(tree: *mut tree_info) { let tree = mut_from_ptr(tree); tree.toolkit_version = None; } /// Caller must call `accesskit_string_free` with the return value. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_info_debug(tree: *const tree_info) -> *mut c_char { debug_repr_from_ptr(tree) } @@ -980,7 +980,7 @@ impl CastPtr for tree_update { impl BoxCastPtr for tree_update {} impl tree_update { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_update_with_focus(focus: node_id) -> *mut tree_update { let update = TreeUpdate { nodes: vec![], @@ -991,7 +991,7 @@ impl tree_update { BoxCastPtr::to_mut_ptr(update) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_update_with_capacity_and_focus( capacity: usize, focus: node_id, @@ -1005,14 +1005,14 @@ impl tree_update { BoxCastPtr::to_mut_ptr(update) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_update_free(update: *mut tree_update) { drop(box_from_ptr(update)); } /// Appends the provided node to the tree update's list of nodes. /// Takes ownership of `node`. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_update_push_node( update: *mut tree_update, id: node_id, @@ -1023,7 +1023,7 @@ impl tree_update { update.nodes.push((id.into(), *node)); } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_update_set_tree_info( update: *mut tree_update, tree: *mut tree_info, @@ -1032,25 +1032,25 @@ impl tree_update { update.tree = Some(*box_from_ptr(tree)); } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_update_clear_tree_info(update: *mut tree_update) { let update = mut_from_ptr(update); update.tree = None; } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_update_set_focus(update: *mut tree_update, focus: node_id) { let update = mut_from_ptr(update); update.focus = focus.into(); } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_update_get_tree_id(update: *const tree_update) -> tree_id { let update = ref_from_ptr(update); update.tree_id.into() } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_update_set_tree_id( update: *mut tree_update, tree_id: tree_id, @@ -1060,7 +1060,7 @@ impl tree_update { } /// Caller must call `accesskit_string_free` with the return value. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_tree_update_debug(tree_update: *const tree_update) -> *mut c_char { debug_repr_from_ptr(tree_update) } @@ -1125,7 +1125,7 @@ impl From for action_request { } } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_action_request_free(request: *mut action_request) { drop(unsafe { Box::from_raw(request) }); } diff --git a/src/geometry.rs b/src/geometry.rs index ed5b8d2..07ad087 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -5,57 +5,57 @@ use accesskit::{Affine, Point, Rect, Size, Vec2}; -#[no_mangle] +#[unsafe(no_mangle)] pub const extern "C" fn accesskit_affine_identity() -> Affine { Affine::scale(1.0) } -#[no_mangle] +#[unsafe(no_mangle)] pub const extern "C" fn accesskit_affine_flip_y() -> Affine { Affine::new([1.0, 0., 0., -1.0, 0., 0.]) } -#[no_mangle] +#[unsafe(no_mangle)] pub const extern "C" fn accesskit_affine_flip_x() -> Affine { Affine::new([-1.0, 0., 0., 1.0, 0., 0.]) } -#[no_mangle] +#[unsafe(no_mangle)] pub const extern "C" fn accesskit_affine_scale(s: f64) -> Affine { Affine::scale(s) } -#[no_mangle] +#[unsafe(no_mangle)] pub const extern "C" fn accesskit_affine_scale_non_uniform(s_x: f64, s_y: f64) -> Affine { Affine::scale_non_uniform(s_x, s_y) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_affine_translate(p: Vec2) -> Affine { Affine::translate(p) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_affine_map_unit_square(rect: Rect) -> Affine { Affine::map_unit_square(rect) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_affine_determinant(affine: Affine) -> f64 { Affine::determinant(affine) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_affine_inverse(affine: Affine) -> Affine { Affine::inverse(affine) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_affine_transform_rect_bbox(affine: Affine, rect: Rect) -> Rect { Affine::transform_rect_bbox(affine, rect) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_affine_is_finite(affine: *const Affine) -> bool { if affine.is_null() { false @@ -64,7 +64,7 @@ pub extern "C" fn accesskit_affine_is_finite(affine: *const Affine) -> bool { } } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_affine_is_nan(affine: *const Affine) -> bool { if affine.is_null() { false @@ -73,64 +73,64 @@ pub extern "C" fn accesskit_affine_is_nan(affine: *const Affine) -> bool { } } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_affine_mul(a: Affine, b: Affine) -> Affine { a * b } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_affine_transform_point(affine: Affine, point: Point) -> Point { affine * point } -#[no_mangle] +#[unsafe(no_mangle)] pub const extern "C" fn accesskit_point_to_vec2(point: Point) -> Vec2 { Point::to_vec2(point) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_point_add_vec2(point: Point, vec: Vec2) -> Point { point + vec } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_point_sub_vec2(point: Point, vec: Vec2) -> Point { point - vec } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_point_sub_point(a: Point, b: Point) -> Vec2 { a - b } -#[no_mangle] +#[unsafe(no_mangle)] pub const extern "C" fn accesskit_rect_new(x0: f64, y0: f64, x1: f64, y1: f64) -> Rect { Rect::new(x0, y0, x1, y1) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_rect_from_points(p0: Point, p1: Point) -> Rect { Rect::from_points(p0, p1) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_rect_from_origin_size(origin: Point, size: Size) -> Rect { Rect::from_origin_size(origin, size) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_rect_with_origin(rect: Rect, origin: Point) -> Rect { Rect::with_origin(rect, origin) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_rect_with_size(rect: Rect, size: Size) -> Rect { Rect::with_size(rect, size) } macro_rules! rect_getter_methods { ($(($c_getter:ident, $getter:ident, $getter_result:ty, $default_value:expr)),+) => { - $(#[no_mangle] + $(#[unsafe(no_mangle)] pub extern "C" fn $c_getter(rect: *const Rect) -> $getter_result { if rect.is_null() { $default_value @@ -155,7 +155,7 @@ rect_getter_methods! { (accesskit_rect_is_empty, is_empty, bool, true) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_rect_contains(rect: *const Rect, point: Point) -> bool { if rect.is_null() { false @@ -164,7 +164,7 @@ pub extern "C" fn accesskit_rect_contains(rect: *const Rect, point: Point) -> bo } } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_rect_union(rect: *const Rect, other: Rect) -> Rect { if rect.is_null() { Rect::ZERO @@ -173,7 +173,7 @@ pub extern "C" fn accesskit_rect_union(rect: *const Rect, other: Rect) -> Rect { } } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_rect_union_pt(rect: *const Rect, pt: Point) -> Rect { if rect.is_null() { Rect::ZERO @@ -182,7 +182,7 @@ pub extern "C" fn accesskit_rect_union_pt(rect: *const Rect, pt: Point) -> Rect } } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_rect_intersect(rect: *const Rect, other: Rect) -> Rect { if rect.is_null() { Rect::ZERO @@ -191,57 +191,57 @@ pub extern "C" fn accesskit_rect_intersect(rect: *const Rect, other: Rect) -> Re } } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_rect_translate(rect: Rect, translation: Vec2) -> Rect { rect + translation } -#[no_mangle] +#[unsafe(no_mangle)] pub const extern "C" fn accesskit_size_to_vec2(size: Size) -> Vec2 { Size::to_vec2(size) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_size_scale(size: Size, scalar: f64) -> Size { size * scalar } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_size_add(a: Size, b: Size) -> Size { a + b } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_size_sub(a: Size, b: Size) -> Size { a - b } -#[no_mangle] +#[unsafe(no_mangle)] pub const extern "C" fn accesskit_vec2_to_point(vec2: Vec2) -> Point { Vec2::to_point(vec2) } -#[no_mangle] +#[unsafe(no_mangle)] pub const extern "C" fn accesskit_vec2_to_size(vec2: Vec2) -> Size { Vec2::to_size(vec2) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_vec2_add(a: Vec2, b: Vec2) -> Vec2 { a + b } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_vec2_sub(a: Vec2, b: Vec2) -> Vec2 { a - b } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_vec2_scale(vec: Vec2, scalar: f64) -> Vec2 { vec * scalar } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn accesskit_vec2_neg(vec: Vec2) -> Vec2 { -vec } diff --git a/src/ios.rs b/src/ios.rs index 32d1299..331a84f 100644 --- a/src/ios.rs +++ b/src/ios.rs @@ -7,10 +7,10 @@ use accesskit_ios::{Adapter, CGPoint, QueuedEvents, SubclassingAdapter}; use std::ffi::{c_char, c_void}; use crate::{ + ActionHandlerCallback, ActivationHandlerCallback, BoxCastPtr, CastPtr, + DeactivationHandlerCallback, FfiActionHandler, FfiActivationHandler, FfiDeactivationHandler, box_from_ptr, debug_repr_from_ptr, mut_from_ptr, tree_update_factory, - tree_update_factory_userdata, ActionHandlerCallback, ActivationHandlerCallback, BoxCastPtr, - CastPtr, DeactivationHandlerCallback, FfiActionHandler, FfiActivationHandler, - FfiDeactivationHandler, + tree_update_factory_userdata, }; pub struct ios_queued_events { @@ -25,7 +25,7 @@ impl BoxCastPtr for ios_queued_events {} impl ios_queued_events { /// Memory is also freed when calling this function. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_ios_queued_events_raise(events: *mut ios_queued_events) { let events = box_from_ptr(events); events.raise(); @@ -49,7 +49,7 @@ impl ios_adapter { /// # Safety /// /// `view` must be a valid, unreleased pointer to a `UIView`. - #[no_mangle] + #[unsafe(no_mangle)] pub unsafe extern "C" fn accesskit_ios_adapter_new( view: *mut c_void, activation_handler: ActivationHandlerCallback, @@ -64,22 +64,24 @@ impl ios_adapter { let action_handler = FfiActionHandler::new(action_handler, action_handler_userdata); let deactivation_handler = FfiDeactivationHandler::new(deactivation_handler, deactivation_handler_userdata); - let adapter = Adapter::new( - view, - activation_handler, - action_handler, - deactivation_handler, - ); + let adapter = unsafe { + Adapter::new( + view, + activation_handler, + action_handler, + deactivation_handler, + ) + }; BoxCastPtr::to_mut_ptr(adapter) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_ios_adapter_free(adapter: *mut ios_adapter) { drop(box_from_ptr(adapter)); } /// You must call `accesskit_ios_queued_events_raise` on the returned pointer. It can be null if the adapter is not active. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_ios_adapter_update_if_active( adapter: *mut ios_adapter, update_factory: tree_update_factory, @@ -98,7 +100,7 @@ impl ios_adapter { /// accessibility tree. /// /// You must call `accesskit_ios_queued_events_raise` on the returned pointer. It can be null if the adapter is not active. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_ios_adapter_view_did_appear( adapter: *mut ios_adapter, ) -> *mut ios_queued_events { @@ -109,7 +111,7 @@ impl ios_adapter { /// Returns whether the view itself is an accessibility element. /// This corresponds to `isAccessibilityElement`. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_ios_adapter_is_accessibility_element( adapter: *mut ios_adapter, ) -> bool { @@ -120,7 +122,7 @@ impl ios_adapter { /// Returns a pointer to an `NSArray` of accessibility elements /// contained in the view. Ownership of the pointer is not transferred. /// This corresponds to `accessibilityElements`. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_ios_adapter_accessibility_elements( adapter: *mut ios_adapter, ) -> *mut c_void { @@ -131,7 +133,7 @@ impl ios_adapter { /// Returns a pointer to the accessibility element at the specified point, /// or null if none. Ownership of the pointer is not transferred. /// This corresponds to `accessibilityHitTest:`. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_ios_adapter_hit_test( adapter: *mut ios_adapter, x: f64, @@ -142,7 +144,7 @@ impl ios_adapter { } /// Caller must call `accesskit_string_free` with the return value. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_ios_adapter_debug(adapter: *const ios_adapter) -> *mut c_char { debug_repr_from_ptr(adapter) } @@ -164,7 +166,7 @@ impl ios_subclassing_adapter { /// # Safety /// /// `view` must be a valid, unreleased pointer to a `UIView`. - #[no_mangle] + #[unsafe(no_mangle)] pub unsafe extern "C" fn accesskit_ios_subclassing_adapter_new( view: *mut c_void, activation_handler: ActivationHandlerCallback, @@ -179,12 +181,14 @@ impl ios_subclassing_adapter { let action_handler = FfiActionHandler::new(action_handler, action_handler_userdata); let deactivation_handler = FfiDeactivationHandler::new(deactivation_handler, deactivation_handler_userdata); - let adapter = SubclassingAdapter::new( - view, - activation_handler, - action_handler, - deactivation_handler, - ); + let adapter = unsafe { + SubclassingAdapter::new( + view, + activation_handler, + action_handler, + deactivation_handler, + ) + }; BoxCastPtr::to_mut_ptr(adapter) } @@ -198,7 +202,7 @@ impl ios_subclassing_adapter { /// /// This function panics if the specified window doesn't currently have /// a root view controller with a view. - #[no_mangle] + #[unsafe(no_mangle)] pub unsafe extern "C" fn accesskit_ios_subclassing_adapter_for_window( window: *mut c_void, activation_handler: ActivationHandlerCallback, @@ -213,16 +217,18 @@ impl ios_subclassing_adapter { let action_handler = FfiActionHandler::new(action_handler, action_handler_userdata); let deactivation_handler = FfiDeactivationHandler::new(deactivation_handler, deactivation_handler_userdata); - let adapter = SubclassingAdapter::for_window( - window, - activation_handler, - action_handler, - deactivation_handler, - ); + let adapter = unsafe { + SubclassingAdapter::for_window( + window, + activation_handler, + action_handler, + deactivation_handler, + ) + }; BoxCastPtr::to_mut_ptr(adapter) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_ios_subclassing_adapter_free( adapter: *mut ios_subclassing_adapter, ) { @@ -230,7 +236,7 @@ impl ios_subclassing_adapter { } /// You must call `accesskit_ios_queued_events_raise` on the returned pointer. It can be null if the adapter is not active. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_ios_subclassing_adapter_update_if_active( adapter: *mut ios_subclassing_adapter, update_factory: tree_update_factory, diff --git a/src/lib.rs b/src/lib.rs index 6bf80a7..de4ccfe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,7 +41,7 @@ mod unix; mod windows; use std::{ - ffi::{c_char, CString}, + ffi::{CString, c_char}, fmt::Debug, slice, }; @@ -218,7 +218,7 @@ unsafe fn string_from_c_slice(value: *const c_char, length: usize) -> String { String::new() } else { #[allow(clippy::unnecessary_cast)] - let bytes = slice::from_raw_parts(value as *const u8, length); + let bytes = unsafe { slice::from_raw_parts(value as *const u8, length) }; String::from_utf8_lossy(bytes).into_owned() } } diff --git a/src/macos.rs b/src/macos.rs index 23bf519..f30eba4 100644 --- a/src/macos.rs +++ b/src/macos.rs @@ -4,14 +4,14 @@ // the LICENSE-MIT file), at your option. use accesskit_macos::{ - add_focus_forwarder_to_window_class, Adapter, NSPoint, QueuedEvents, SubclassingAdapter, + Adapter, NSPoint, QueuedEvents, SubclassingAdapter, add_focus_forwarder_to_window_class, }; -use std::ffi::{c_char, c_void, CStr}; +use std::ffi::{CStr, c_char, c_void}; use crate::{ - box_from_ptr, debug_repr_from_ptr, mut_from_ptr, string_from_c_slice, tree_update_factory, - tree_update_factory_userdata, ActionHandlerCallback, ActivationHandlerCallback, BoxCastPtr, - CastPtr, FfiActionHandler, FfiActivationHandler, + ActionHandlerCallback, ActivationHandlerCallback, BoxCastPtr, CastPtr, FfiActionHandler, + FfiActivationHandler, box_from_ptr, debug_repr_from_ptr, mut_from_ptr, string_from_c_slice, + tree_update_factory, tree_update_factory_userdata, }; pub struct macos_queued_events { @@ -26,7 +26,7 @@ impl BoxCastPtr for macos_queued_events {} impl macos_queued_events { /// Memory is also freed when calling this function. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_macos_queued_events_raise(events: *mut macos_queued_events) { let events = box_from_ptr(events); events.raise(); @@ -47,7 +47,7 @@ impl macos_adapter { /// # Safety /// /// `view` must be a valid, unreleased pointer to an `NSView`. - #[no_mangle] + #[unsafe(no_mangle)] pub unsafe extern "C" fn accesskit_macos_adapter_new( view: *mut c_void, is_view_focused: bool, @@ -55,17 +55,17 @@ impl macos_adapter { action_handler_userdata: *mut c_void, ) -> *mut macos_adapter { let action_handler = FfiActionHandler::new(action_handler, action_handler_userdata); - let adapter = Adapter::new(view, is_view_focused, action_handler); + let adapter = unsafe { Adapter::new(view, is_view_focused, action_handler) }; BoxCastPtr::to_mut_ptr(adapter) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_macos_adapter_free(adapter: *mut macos_adapter) { drop(box_from_ptr(adapter)); } /// You must call `accesskit_macos_queued_events_raise` on the returned pointer. It can be null if the adapter is not active. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_macos_adapter_update_if_active( adapter: *mut macos_adapter, update_factory: tree_update_factory, @@ -82,7 +82,7 @@ impl macos_adapter { /// Update the tree state based on whether the window is focused. /// /// You must call `accesskit_macos_queued_events_raise` on the returned pointer. It can be null if the adapter is not active. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_macos_adapter_update_view_focus_state( adapter: *mut macos_adapter, is_focused: bool, @@ -93,7 +93,7 @@ impl macos_adapter { } /// Returns a pointer to an `NSArray`. Ownership of the pointer is not transferred. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_macos_adapter_view_children( adapter: *mut macos_adapter, activation_handler: ActivationHandlerCallback, @@ -106,7 +106,7 @@ impl macos_adapter { } /// Returns a pointer to an `NSObject`. Ownership of the pointer is not transferred. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_macos_adapter_focus( adapter: *mut macos_adapter, activation_handler: ActivationHandlerCallback, @@ -119,7 +119,7 @@ impl macos_adapter { } /// Returns a pointer to an `NSObject`. Ownership of the pointer is not transferred. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_macos_adapter_hit_test( adapter: *mut macos_adapter, x: f64, @@ -134,7 +134,7 @@ impl macos_adapter { } /// Caller must call `accesskit_string_free` with the return value. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_macos_adapter_debug(adapter: *const macos_adapter) -> *mut c_char { debug_repr_from_ptr(adapter) } @@ -154,7 +154,7 @@ impl macos_subclassing_adapter { /// # Safety /// /// `view` must be a valid, unreleased pointer to an `NSView`. - #[no_mangle] + #[unsafe(no_mangle)] pub unsafe extern "C" fn accesskit_macos_subclassing_adapter_new( view: *mut c_void, activation_handler: ActivationHandlerCallback, @@ -165,7 +165,7 @@ impl macos_subclassing_adapter { let activation_handler = FfiActivationHandler::new(activation_handler, activation_handler_userdata); let action_handler = FfiActionHandler::new(action_handler, action_handler_userdata); - let adapter = SubclassingAdapter::new(view, activation_handler, action_handler); + let adapter = unsafe { SubclassingAdapter::new(view, activation_handler, action_handler) }; BoxCastPtr::to_mut_ptr(adapter) } @@ -177,7 +177,7 @@ impl macos_subclassing_adapter { /// /// This function panics if the specified window doesn't currently have /// a content view. - #[no_mangle] + #[unsafe(no_mangle)] pub unsafe extern "C" fn accesskit_macos_subclassing_adapter_for_window( window: *mut c_void, activation_handler: ActivationHandlerCallback, @@ -188,11 +188,12 @@ impl macos_subclassing_adapter { let activation_handler = FfiActivationHandler::new(activation_handler, activation_handler_userdata); let action_handler = FfiActionHandler::new(action_handler, action_handler_userdata); - let adapter = SubclassingAdapter::for_window(window, activation_handler, action_handler); + let adapter = + unsafe { SubclassingAdapter::for_window(window, activation_handler, action_handler) }; BoxCastPtr::to_mut_ptr(adapter) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_macos_subclassing_adapter_free( adapter: *mut macos_subclassing_adapter, ) { @@ -200,7 +201,7 @@ impl macos_subclassing_adapter { } /// You must call `accesskit_macos_queued_events_raise` on the returned pointer. It can be null if the adapter is not active. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_macos_subclassing_adapter_update_if_active( adapter: *mut macos_subclassing_adapter, update_factory: tree_update_factory, @@ -217,7 +218,7 @@ impl macos_subclassing_adapter { /// Update the tree state based on whether the window is focused. /// /// You must call `accesskit_macos_queued_events_raise` on the returned pointer. It can be null if the adapter is not active. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_macos_subclassing_adapter_update_view_focus_state( adapter: *mut macos_subclassing_adapter, is_focused: bool, @@ -242,12 +243,12 @@ impl macos_subclassing_adapter { /// if this library is statically linked into the application's main executable. /// Also, this function assumes that the specified class is a subclass /// of `NSWindow`. -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn accesskit_macos_add_focus_forwarder_to_window_class( class_name: *const c_char, ) { let class_name = unsafe { CStr::from_ptr(class_name).to_string_lossy() }; - add_focus_forwarder_to_window_class(&class_name); + unsafe { add_focus_forwarder_to_window_class(&class_name) }; } /// Modifies the specified class, which must be a subclass of `NSWindow`, @@ -265,11 +266,11 @@ pub unsafe extern "C" fn accesskit_macos_add_focus_forwarder_to_window_class( /// if this library is statically linked into the application's main executable. /// Also, this function assumes that the specified class is a subclass /// of `NSWindow`. -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn accesskit_macos_add_focus_forwarder_to_window_class_with_length( class_name: *const c_char, length: usize, ) { - let class_name = string_from_c_slice(class_name, length); - add_focus_forwarder_to_window_class(&class_name); + let class_name = unsafe { string_from_c_slice(class_name, length) }; + unsafe { add_focus_forwarder_to_window_class(&class_name) }; } diff --git a/src/unix.rs b/src/unix.rs index ca84dcc..c41b7f3 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -8,10 +8,10 @@ use accesskit_unix::Adapter; use std::ffi::{c_char, c_void}; use crate::{ + ActionHandlerCallback, ActivationHandlerCallback, BoxCastPtr, CastPtr, + DeactivationHandlerCallback, FfiActionHandler, FfiActivationHandler, FfiDeactivationHandler, box_from_ptr, debug_repr_from_ptr, mut_from_ptr, tree_update_factory, - tree_update_factory_userdata, ActionHandlerCallback, ActivationHandlerCallback, BoxCastPtr, - CastPtr, DeactivationHandlerCallback, FfiActionHandler, FfiActivationHandler, - FfiDeactivationHandler, + tree_update_factory_userdata, }; pub struct unix_adapter { @@ -26,7 +26,7 @@ impl BoxCastPtr for unix_adapter {} impl unix_adapter { /// All of the handlers will always be called from another thread. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_unix_adapter_new( activation_handler: ActivationHandlerCallback, activation_handler_userdata: *mut c_void, @@ -44,7 +44,7 @@ impl unix_adapter { BoxCastPtr::to_mut_ptr(adapter) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_unix_adapter_free(adapter: *mut unix_adapter) { drop(box_from_ptr(adapter)); } @@ -56,7 +56,7 @@ impl unix_adapter { /// /// Since an application can not get the position of its window under /// Wayland, calling this method only makes sense under X11. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_unix_adapter_set_root_window_bounds( adapter: *mut unix_adapter, outer: Rect, @@ -66,7 +66,7 @@ impl unix_adapter { adapter.set_root_window_bounds(outer, inner); } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_unix_adapter_update_if_active( adapter: *mut unix_adapter, update_factory: tree_update_factory, @@ -79,7 +79,7 @@ impl unix_adapter { } /// Update the tree state based on whether the window is focused. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_unix_adapter_update_window_focus_state( adapter: *mut unix_adapter, is_focused: bool, @@ -89,7 +89,7 @@ impl unix_adapter { } /// Caller must call `accesskit_string_free` with the return value. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_unix_adapter_debug(adapter: *const unix_adapter) -> *mut c_char { debug_repr_from_ptr(adapter) } diff --git a/src/windows.rs b/src/windows.rs index 65a423d..f50f453 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -7,9 +7,9 @@ use accesskit_windows::*; use std::ffi::{c_char, c_void}; use crate::{ - box_from_ptr, debug_repr_from_ptr, mut_from_ptr, opt_struct, tree_update_factory, - tree_update_factory_userdata, ActionHandlerCallback, ActivationHandlerCallback, BoxCastPtr, - CastPtr, FfiActionHandler, FfiActivationHandler, + ActionHandlerCallback, ActivationHandlerCallback, BoxCastPtr, CastPtr, FfiActionHandler, + FfiActivationHandler, box_from_ptr, debug_repr_from_ptr, mut_from_ptr, opt_struct, + tree_update_factory, tree_update_factory_userdata, }; pub struct windows_queued_events { @@ -24,7 +24,7 @@ impl BoxCastPtr for windows_queued_events {} impl windows_queued_events { /// Memory is also freed when calling this function. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_windows_queued_events_raise(events: *mut windows_queued_events) { let events = box_from_ptr(events); events.raise(); @@ -44,7 +44,7 @@ impl CastPtr for windows_adapter { impl BoxCastPtr for windows_adapter {} impl windows_adapter { - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_windows_adapter_new( hwnd: HWND, is_window_focused: bool, @@ -56,13 +56,13 @@ impl windows_adapter { BoxCastPtr::to_mut_ptr(adapter) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_windows_adapter_free(adapter: *mut windows_adapter) { drop(box_from_ptr(adapter)); } /// You must call `accesskit_windows_queued_events_raise` on the returned pointer. It can be null if the adapter is not active. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_windows_adapter_update_if_active( adapter: *mut windows_adapter, update_factory: tree_update_factory, @@ -79,7 +79,7 @@ impl windows_adapter { /// Update the tree state based on whether the window is focused. /// /// You must call `accesskit_windows_queued_events_raise` on the returned pointer. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_windows_adapter_update_window_focus_state( adapter: *mut windows_adapter, is_focused: bool, @@ -89,7 +89,7 @@ impl windows_adapter { BoxCastPtr::to_nullable_mut_ptr(events) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_windows_adapter_handle_wm_getobject( adapter: *mut windows_adapter, wparam: WPARAM, @@ -105,7 +105,7 @@ impl windows_adapter { } /// Caller must call `accesskit_string_free` with the return value. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_windows_adapter_debug( adapter: *const windows_adapter, ) -> *mut c_char { @@ -135,7 +135,7 @@ impl windows_subclassing_adapter { /// # Panics /// /// Panics if the window is already visible. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_windows_subclassing_adapter_new( hwnd: HWND, activation_handler: ActivationHandlerCallback, @@ -150,7 +150,7 @@ impl windows_subclassing_adapter { BoxCastPtr::to_mut_ptr(adapter) } - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_windows_subclassing_adapter_free( adapter: *mut windows_subclassing_adapter, ) { @@ -158,7 +158,7 @@ impl windows_subclassing_adapter { } /// You must call `accesskit_windows_queued_events_raise` on the returned pointer. It can be null if the adapter is not active. - #[no_mangle] + #[unsafe(no_mangle)] pub extern "C" fn accesskit_windows_subclassing_adapter_update_if_active( adapter: *mut windows_subclassing_adapter, update_factory: tree_update_factory,