1
0
Fork 0
forked from wry/wry

config: warn on unsafe-op-in-unsafe-fn

This commit is contained in:
Julian Orth 2024-10-20 18:07:48 +02:00
parent b6345f095c
commit ce7488aa86
2 changed files with 22 additions and 15 deletions

View file

@ -164,7 +164,7 @@ unsafe fn with_client<T, F: FnOnce(&Client) -> T>(data: *const u8, f: F) -> T {
self.cell.set(self.val); self.cell.set(self.val);
} }
} }
CLIENT.with(|cell| { CLIENT.with(|cell| unsafe {
let client = data as *const Client; let client = data as *const Client;
Rc::increment_strong_count(client); Rc::increment_strong_count(client);
let client = Rc::from_raw(client); let client = Rc::from_raw(client);
@ -190,6 +190,7 @@ impl<T: Config> ConfigEntryGen<T> {
size: usize, size: usize,
) -> *const u8 { ) -> *const u8 {
logging::init(); logging::init();
unsafe {
init( init(
srv_data, srv_data,
srv_unref, srv_unref,
@ -200,6 +201,7 @@ impl<T: Config> ConfigEntryGen<T> {
) )
} }
} }
}
pub unsafe extern "C" fn init( pub unsafe extern "C" fn init(
srv_data: *const u8, srv_data: *const u8,
@ -239,22 +241,26 @@ pub unsafe extern "C" fn init(
pressed_keysym: Cell::new(None), pressed_keysym: Cell::new(None),
feat_mod_mask: Cell::new(false), feat_mod_mask: Cell::new(false),
}); });
let init = slice::from_raw_parts(init, size); let init = unsafe { slice::from_raw_parts(init, size) };
client.handle_init_msg(init); client.handle_init_msg(init);
Rc::into_raw(client) as *const u8 Rc::into_raw(client) as *const u8
} }
pub unsafe extern "C" fn unref(data: *const u8) { pub unsafe extern "C" fn unref(data: *const u8) {
let client = data as *const Client; let client = data as *const Client;
unsafe {
drop(Rc::from_raw(client)); drop(Rc::from_raw(client));
} }
}
pub unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) { pub unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
unsafe {
with_client(data, |client| { with_client(data, |client| {
let msg = slice::from_raw_parts(msg, size); let msg = slice::from_raw_parts(msg, size);
client.handle_msg(msg); client.handle_msg(msg);
}); });
} }
}
macro_rules! get_response { macro_rules! get_response {
($res:expr, $def:expr, $ty:ident { $($field:ident),+ }) => { ($res:expr, $def:expr, $ty:ident { $($field:ident),+ }) => {

View file

@ -41,6 +41,7 @@
clippy::single_char_add_str, clippy::single_char_add_str,
clippy::single_match clippy::single_match
)] )]
#![warn(unsafe_op_in_unsafe_fn)]
use { use {
crate::{_private::ipc::WorkspaceSource, keyboard::ModifiedKeySym, video::Connector}, crate::{_private::ipc::WorkspaceSource, keyboard::ModifiedKeySym, video::Connector},