mirror of
https://github.com/openharmony/third_party_rust_memoffset.git
synced 2026-07-21 01:45:27 -04:00
old rust compat
This commit is contained in:
+2
-2
@@ -76,10 +76,10 @@ macro_rules! field_check {
|
||||
#[macro_export]
|
||||
macro_rules! offset_of {
|
||||
($parent:tt, $field:tt) => {{
|
||||
$crate::field_check!($parent, $field);
|
||||
field_check!($parent, $field);
|
||||
|
||||
// Get a base pointer.
|
||||
$crate::let_base_ptr!(base_ptr, $parent);
|
||||
let_base_ptr!(base_ptr, $parent);
|
||||
// Get the field address. This is UB because we are creating a reference to
|
||||
// the uninitialized field.
|
||||
#[allow(unused_unsafe)] // for when the macro is used in an unsafe block
|
||||
|
||||
+12
-12
@@ -91,30 +91,30 @@ macro_rules! span_of {
|
||||
$root as usize + $crate::mem::size_of_val(&(*$root)))
|
||||
}};
|
||||
(@helper $root:ident, $parent:tt, [] ..= $field:tt) => {{
|
||||
$crate::field_check!($parent, $field);
|
||||
field_check!($parent, $field);
|
||||
($root as usize,
|
||||
&(*$root).$field as *const _ as usize + $crate::mem::size_of_val(&(*$root).$field))
|
||||
}};
|
||||
(@helper $root:ident, $parent:tt, [] .. $field:tt) => {{
|
||||
$crate::field_check!($parent, $field);
|
||||
field_check!($parent, $field);
|
||||
($root as usize, &(*$root).$field as *const _ as usize)
|
||||
}};
|
||||
// Explicit begin and end for range.
|
||||
(@helper $root:ident, $parent:tt, # $begin:tt [] ..= $end:tt) => {{
|
||||
$crate::field_check!($parent, $begin);
|
||||
$crate::field_check!($parent, $end);
|
||||
field_check!($parent, $begin);
|
||||
field_check!($parent, $end);
|
||||
(&(*$root).$begin as *const _ as usize,
|
||||
&(*$root).$end as *const _ as usize + $crate::mem::size_of_val(&(*$root).$end))
|
||||
}};
|
||||
(@helper $root:ident, $parent:tt, # $begin:tt [] .. $end:tt) => {{
|
||||
$crate::field_check!($parent, $begin);
|
||||
$crate::field_check!($parent, $end);
|
||||
field_check!($parent, $begin);
|
||||
field_check!($parent, $end);
|
||||
(&(*$root).$begin as *const _ as usize,
|
||||
&(*$root).$end as *const _ as usize)
|
||||
}};
|
||||
// No explicit end for range.
|
||||
(@helper $root:ident, $parent:tt, # $begin:tt [] ..) => {{
|
||||
$crate::field_check!($parent, $begin);
|
||||
field_check!($parent, $begin);
|
||||
(&(*$root).$begin as *const _ as usize,
|
||||
$root as usize + $crate::mem::size_of_val(&*$root))
|
||||
}};
|
||||
@@ -124,25 +124,25 @@ macro_rules! span_of {
|
||||
}};
|
||||
// Just one field.
|
||||
(@helper $root:ident, $parent:tt, # $begin:tt []) => {{
|
||||
$crate::field_check!($parent, $begin);
|
||||
field_check!($parent, $begin);
|
||||
(&(*$root).$begin as *const _ as usize,
|
||||
&(*$root).$begin as *const _ as usize + $crate::mem::size_of_val(&(*$root).$begin))
|
||||
}};
|
||||
// Parsing.
|
||||
(@helper $root:ident, $parent:tt, $(# $begin:tt)+ [] $tt:tt $($rest:tt)*) => {{
|
||||
$crate::span_of!(@helper $root, $parent, $(#$begin)* #$tt [] $($rest)*)
|
||||
span_of!(@helper $root, $parent, $(#$begin)* #$tt [] $($rest)*)
|
||||
}};
|
||||
(@helper $root:ident, $parent:tt, [] $tt:tt $($rest:tt)*) => {{
|
||||
$crate::span_of!(@helper $root, $parent, #$tt [] $($rest)*)
|
||||
span_of!(@helper $root, $parent, #$tt [] $($rest)*)
|
||||
}};
|
||||
|
||||
// Entry point.
|
||||
($sty:tt, $($exp:tt)+) => ({
|
||||
unsafe {
|
||||
// Get a base pointer.
|
||||
$crate::let_base_ptr!(root, $sty);
|
||||
let_base_ptr!(root, $sty);
|
||||
let base = root as usize;
|
||||
let (begin, end) = $crate::span_of!(@helper root, $sty, [] $($exp)*);
|
||||
let (begin, end) = span_of!(@helper root, $sty, [] $($exp)*);
|
||||
begin-base..end-base
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user