mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
chore: Move unsafe operations in unsafe functions to unsafe blocks (#36017)
Signed-off-by: DK Liao <dklassic@gmail.com>
This commit is contained in:
parent
eb3c48f9d3
commit
bcdd34e2aa
5 changed files with 59 additions and 57 deletions
|
@ -23,6 +23,3 @@ windows-sys = { workspace = true, features = ["Win32_System_Memory"] }
|
|||
|
||||
[target.'cfg(target_env = "ohos")'.dependencies]
|
||||
libc = { workspace = true }
|
||||
|
||||
[lints.rust]
|
||||
unsafe_op_in_unsafe_fn = { level = "allow" }
|
||||
|
|
|
@ -45,10 +45,14 @@ mod platform {
|
|||
/// Passing a non-heap allocated pointer to this function results in undefined behavior.
|
||||
pub unsafe extern "C" fn usable_size(ptr: *const c_void) -> usize {
|
||||
#[cfg(target_vendor = "apple")]
|
||||
return libc::malloc_size(ptr);
|
||||
unsafe {
|
||||
return libc::malloc_size(ptr);
|
||||
}
|
||||
|
||||
#[cfg(not(target_vendor = "apple"))]
|
||||
return libc::malloc_usable_size(ptr as *mut _);
|
||||
unsafe {
|
||||
return libc::malloc_usable_size(ptr as *mut _);
|
||||
}
|
||||
}
|
||||
|
||||
pub mod libc_compat {
|
||||
|
@ -70,12 +74,14 @@ mod platform {
|
|||
///
|
||||
/// Passing a non-heap allocated pointer to this function results in undefined behavior.
|
||||
pub unsafe extern "C" fn usable_size(mut ptr: *const c_void) -> usize {
|
||||
let heap = GetProcessHeap();
|
||||
unsafe {
|
||||
let heap = GetProcessHeap();
|
||||
|
||||
if HeapValidate(heap, 0, ptr) == FALSE {
|
||||
ptr = *(ptr as *const *const c_void).offset(-1)
|
||||
if HeapValidate(heap, 0, ptr) == FALSE {
|
||||
ptr = *(ptr as *const *const c_void).offset(-1)
|
||||
}
|
||||
|
||||
HeapSize(heap, 0, ptr) as usize
|
||||
}
|
||||
|
||||
HeapSize(heap, 0, ptr) as usize
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue