Fix clippy errors

In wgpu-remote, some functions are now marked `unsafe` on the outside,
because they dereferenced a raw pointer they couldn't have checked
themselves.
This commit is contained in:
yanchith
2020-01-17 14:20:20 +01:00
parent 3a41272cba
commit 741844cc2b
2 changed files with 14 additions and 18 deletions

View File

@@ -71,20 +71,20 @@ pub extern "C" fn wgpu_client_new() -> Infrastructure {
}
#[no_mangle]
pub extern "C" fn wgpu_client_delete(client: *mut Client) {
pub unsafe extern "C" fn wgpu_client_delete(client: *mut Client) {
log::info!("Terminating WGPU client");
let _client = unsafe { Box::from_raw(client) };
let _client = Box::from_raw(client);
}
#[no_mangle]
pub extern "C" fn wgpu_client_make_adapter_ids(
pub unsafe extern "C" fn wgpu_client_make_adapter_ids(
client: &Client,
ids: *mut id::AdapterId,
id_length: usize,
) -> usize {
let mut identities = client.identities.lock();
assert_ne!(id_length, 0);
let mut ids = unsafe { slice::from_raw_parts_mut(ids, id_length) }.iter_mut();
let mut ids = slice::from_raw_parts_mut(ids, id_length).iter_mut();
*ids.next().unwrap() = identities.vulkan.adapters.alloc(Backend::Vulkan);
@@ -101,13 +101,13 @@ pub extern "C" fn wgpu_client_make_adapter_ids(
}
#[no_mangle]
pub extern "C" fn wgpu_client_kill_adapter_ids(
pub unsafe extern "C" fn wgpu_client_kill_adapter_ids(
client: &Client,
ids: *const id::AdapterId,
id_length: usize,
) {
let mut identity = client.identities.lock();
let ids = unsafe { slice::from_raw_parts(ids, id_length) };
let ids = slice::from_raw_parts(ids, id_length);
for &id in ids {
identity.select(id.backend()).adapters.free(id)
}

View File

@@ -15,9 +15,9 @@ pub extern "C" fn wgpu_server_new() -> *mut Global {
}
#[no_mangle]
pub extern "C" fn wgpu_server_delete(global: *mut Global) {
pub unsafe extern "C" fn wgpu_server_delete(global: *mut Global) {
log::info!("Terminating WGPU server");
unsafe { Box::from_raw(global) }.delete();
Box::from_raw(global).delete();
log::info!("\t...done");
}
@@ -26,13 +26,13 @@ pub extern "C" fn wgpu_server_delete(global: *mut Global) {
///
/// Returns the index in this list, or -1 if unable to pick.
#[no_mangle]
pub extern "C" fn wgpu_server_instance_request_adapter(
pub unsafe extern "C" fn wgpu_server_instance_request_adapter(
global: &Global,
desc: &core::instance::RequestAdapterOptions,
ids: *const id::AdapterId,
id_length: usize,
) -> i8 {
let ids = unsafe { slice::from_raw_parts(ids, id_length) };
let ids = slice::from_raw_parts(ids, id_length);
match global.pick_adapter(
desc,
core::instance::AdapterInputs::IdSet(ids, |i| i.backend()),
@@ -68,7 +68,7 @@ pub extern "C" fn wgpu_server_device_create_buffer(
}
#[no_mangle]
pub extern "C" fn wgpu_server_device_set_buffer_sub_data(
pub unsafe extern "C" fn wgpu_server_device_set_buffer_sub_data(
global: &Global,
self_id: id::DeviceId,
buffer_id: id::BufferId,
@@ -76,14 +76,12 @@ pub extern "C" fn wgpu_server_device_set_buffer_sub_data(
data: *const u8,
size: core::BufferAddress,
) {
let slice = unsafe {
slice::from_raw_parts(data, size as usize)
};
let slice = slice::from_raw_parts(data, size as usize);
gfx_select!(self_id => global.device_set_buffer_sub_data(self_id, buffer_id, offset, slice));
}
#[no_mangle]
pub extern "C" fn wgpu_server_device_get_buffer_sub_data(
pub unsafe extern "C" fn wgpu_server_device_get_buffer_sub_data(
global: &Global,
self_id: id::DeviceId,
buffer_id: id::BufferId,
@@ -91,9 +89,7 @@ pub extern "C" fn wgpu_server_device_get_buffer_sub_data(
data: *mut u8,
size: core::BufferAddress,
) {
let slice = unsafe {
slice::from_raw_parts_mut(data, size as usize)
};
let slice = slice::from_raw_parts_mut(data, size as usize);
gfx_select!(self_id => global.device_get_buffer_sub_data(self_id, buffer_id, offset, slice));
}