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,14 +190,16 @@ impl<T: Config> ConfigEntryGen<T> {
size: usize, size: usize,
) -> *const u8 { ) -> *const u8 {
logging::init(); logging::init();
init( unsafe {
srv_data, init(
srv_unref, srv_data,
srv_handler, srv_unref,
init_data, srv_handler,
size, init_data,
T::configure, size,
) T::configure,
)
}
} }
} }
@ -239,21 +241,25 @@ 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;
drop(Rc::from_raw(client)); unsafe {
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) {
with_client(data, |client| { unsafe {
let msg = slice::from_raw_parts(msg, size); with_client(data, |client| {
client.handle_msg(msg); let msg = slice::from_raw_parts(msg, size);
}); client.handle_msg(msg);
});
}
} }
macro_rules! get_response { macro_rules! get_response {

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},