mirror of
https://github.com/denoland/deno.git
synced 2025-10-02 23:24:37 +00:00
fix(serde_v8): update bytes::Bytes layout assumptions (#15718)
This commit is contained in:
parent
e267ec6ed5
commit
73b4597dec
4 changed files with 40 additions and 3 deletions
|
@ -26,11 +26,25 @@ impl RawBytes {
|
|||
}
|
||||
}
|
||||
|
||||
// Validate some bytes::Bytes layout assumptions at compile time.
|
||||
const _: () = {
|
||||
assert!(
|
||||
core::mem::size_of::<RawBytes>() == core::mem::size_of::<bytes::Bytes>(),
|
||||
);
|
||||
assert!(
|
||||
core::mem::align_of::<RawBytes>() == core::mem::align_of::<bytes::Bytes>(),
|
||||
);
|
||||
};
|
||||
|
||||
#[allow(unused)]
|
||||
pub(crate) struct Vtable {
|
||||
/// fn(data, ptr, len)
|
||||
pub clone: unsafe fn(&AtomicPtr<()>, *const u8, usize) -> bytes::Bytes,
|
||||
/// fn(data, ptr, len)
|
||||
///
|
||||
/// takes `Bytes` to value
|
||||
pub to_vec: unsafe fn(&AtomicPtr<()>, *const u8, usize) -> Vec<u8>,
|
||||
/// fn(data, ptr, len)
|
||||
pub drop: unsafe fn(&mut AtomicPtr<()>, *const u8, usize),
|
||||
}
|
||||
|
||||
|
@ -55,6 +69,7 @@ mod tests {
|
|||
const STATIC_VTABLE: Vtable = Vtable {
|
||||
clone: static_clone,
|
||||
drop: static_drop,
|
||||
to_vec: static_to_vec,
|
||||
};
|
||||
|
||||
unsafe fn static_clone(
|
||||
|
@ -65,6 +80,15 @@ mod tests {
|
|||
from_static(std::slice::from_raw_parts(ptr, len)).into()
|
||||
}
|
||||
|
||||
unsafe fn static_to_vec(
|
||||
_: &AtomicPtr<()>,
|
||||
ptr: *const u8,
|
||||
len: usize,
|
||||
) -> Vec<u8> {
|
||||
let slice = std::slice::from_raw_parts(ptr, len);
|
||||
slice.to_vec()
|
||||
}
|
||||
|
||||
unsafe fn static_drop(_: &mut AtomicPtr<()>, _: *const u8, _: usize) {
|
||||
// nothing to drop for &'static [u8]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue