diff options
author | James Farrell <jamesfarrell@google.com> | 2023-09-06 11:12:03 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-09-06 11:12:03 +0000 |
commit | 86f45b1c4c89207b803ab11ac8bc4c1d625f238f (patch) | |
tree | 55e17a784a4f68296477f1a8138cd16288ac2592 | |
parent | 51710b031a6337c178bb9505da77ae0b63600d33 (diff) | |
parent | 72d0371be058928d4ed336c41b6ab55aead795d4 (diff) | |
download | memoffset-86f45b1c4c89207b803ab11ac8bc4c1d625f238f.tar.gz |
Upgrade memoffset to 0.9.0 am: 6146b87f32 am: b5f8552293 am: 72d0371be0
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/memoffset/+/2741828
Change-Id: I51f0418d30b60640e7cf4edbd52cb60d9b3fa948
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 4 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | Cargo.toml.orig | 3 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/offset_of.rs | 76 |
7 files changed, 73 insertions, 26 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 161d06e..06c1c2e 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "0fac3ac6642dd017a36268c4cdba2f04ec050d11" + "sha1": "a380cb810818a3e3a205ce6d178ac2348c243a3b" }, "path_in_vcs": "" }
\ No newline at end of file @@ -23,7 +23,7 @@ rust_library { host_supported: true, crate_name: "memoffset", cargo_env_compat: true, - cargo_pkg_version: "0.8.0", + cargo_pkg_version: "0.9.0", srcs: ["src/lib.rs"], edition: "2015", features: ["default"], @@ -49,7 +49,7 @@ rust_test { host_supported: true, crate_name: "memoffset", cargo_env_compat: true, - cargo_pkg_version: "0.8.0", + cargo_pkg_version: "0.9.0", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -11,7 +11,7 @@ [package] name = "memoffset" -version = "0.8.0" +version = "0.9.0" authors = ["Gilad Naaman <gilad.naaman@gmail.com>"] description = "offset_of functionality for Rust structs." readme = "README.md" @@ -34,3 +34,4 @@ version = "1" [features] default = [] unstable_const = [] +unstable_offset_of = [] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 71bdc9e..ef70063 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "memoffset" -version = "0.8.0" +version = "0.9.0" authors = ["Gilad Naaman <gilad.naaman@gmail.com>"] description = "offset_of functionality for Rust structs." license = "MIT" @@ -18,3 +18,4 @@ doc-comment = "0.3" [features] default = [] unstable_const = [] +unstable_offset_of = [] @@ -1,6 +1,6 @@ # This project was upgraded with external_updater. # Usage: tools/external_updater/updater.sh update rust/crates/memoffset -# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md +# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md name: "memoffset" description: "offset_of functionality for Rust structs." @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/memoffset/memoffset-0.8.0.crate" + value: "https://static.crates.io/crates/memoffset/memoffset-0.9.0.crate" } - version: "0.8.0" + version: "0.9.0" license_type: NOTICE last_upgrade_date { year: 2023 - month: 2 - day: 3 + month: 9 + day: 5 } } @@ -62,6 +62,7 @@ feature(const_ptr_offset_from) )] #![cfg_attr(feature = "unstable_const", feature(const_refs_to_cell))] +#![cfg_attr(feature = "unstable_offset_of", feature(allow_internal_unstable))] #[macro_use] #[cfg(doctests)] diff --git a/src/offset_of.rs b/src/offset_of.rs index 9ce4ae2..190ca72 100644 --- a/src/offset_of.rs +++ b/src/offset_of.rs @@ -67,6 +67,28 @@ macro_rules! _memoffset_offset_from_unsafe { ($field as usize) - ($base as usize) }; } +#[cfg(not(feature = "unstable_offset_of"))] +#[macro_export(local_inner_macros)] +#[doc(hidden)] +macro_rules! _memoffset__offset_of_impl { + ($parent:path, $field:tt) => {{ + // Get a base pointer (non-dangling if rustc supports `MaybeUninit`). + _memoffset__let_base_ptr!(base_ptr, $parent); + // Get field pointer. + let field_ptr = raw_field!(base_ptr, $parent, $field); + // Compute offset. + _memoffset_offset_from_unsafe!(field_ptr, base_ptr) + }}; +} +#[cfg(feature = "unstable_offset_of")] +#[macro_export] +#[doc(hidden)] +#[allow_internal_unstable(offset_of)] +macro_rules! _memoffset__offset_of_impl { + ($parent:path, $field:tt) => {{ + $crate::__priv::mem::offset_of!($parent, $field) + }}; +} /// Calculates the offset of the specified field from the start of the named struct. /// @@ -98,14 +120,9 @@ macro_rules! _memoffset_offset_from_unsafe { /// As a result, the value should not be retained and used between different compilations. #[macro_export(local_inner_macros)] macro_rules! offset_of { - ($parent:path, $field:tt) => {{ - // Get a base pointer (non-dangling if rustc supports `MaybeUninit`). - _memoffset__let_base_ptr!(base_ptr, $parent); - // Get field pointer. - let field_ptr = raw_field!(base_ptr, $parent, $field); - // Compute offset. - _memoffset_offset_from_unsafe!(field_ptr, base_ptr) - }}; + ($parent:path, $field:tt) => { + _memoffset__offset_of_impl!($parent, $field) + }; } /// Calculates the offset of the specified field from the start of the tuple. @@ -131,6 +148,30 @@ macro_rules! offset_of_tuple { }}; } +#[cfg(not(feature = "unstable_offset_of"))] +#[macro_export(local_inner_macros)] +#[doc(hidden)] +macro_rules! _memoffset__offset_of_union_impl { + ($parent:path, $field:tt) => {{ + // Get a base pointer (non-dangling if rustc supports `MaybeUninit`). + _memoffset__let_base_ptr!(base_ptr, $parent); + // Get field pointer. + let field_ptr = raw_field_union!(base_ptr, $parent, $field); + // Compute offset. + _memoffset_offset_from_unsafe!(field_ptr, base_ptr) + }}; +} + +#[cfg(feature = "unstable_offset_of")] +#[macro_export(local_inner_macros)] +#[doc(hidden)] +#[allow_internal_unstable(offset_of)] +macro_rules! _memoffset__offset_of_union_impl { + ($parent:path, $field:tt) => {{ + $crate::__priv::mem::offset_of!($parent, $field) + }}; +} + /// Calculates the offset of the specified union member from the start of the union. /// /// ## Examples @@ -155,12 +196,7 @@ macro_rules! offset_of_tuple { #[macro_export(local_inner_macros)] macro_rules! offset_of_union { ($parent:path, $field:tt) => {{ - // Get a base pointer (non-dangling if rustc supports `MaybeUninit`). - _memoffset__let_base_ptr!(base_ptr, $parent); - // Get field pointer. - let field_ptr = raw_field_union!(base_ptr, $parent, $field); - // Compute offset. - _memoffset_offset_from_unsafe!(field_ptr, base_ptr) + _memoffset__offset_of_union_impl!($parent, $field) }}; } @@ -312,7 +348,11 @@ mod tests { assert_eq!(f_ptr as usize + 0, raw_field_union!(f_ptr, Foo, c) as usize); } - #[cfg(any(feature = "unstable_const", stable_const))] + #[cfg(any( + feature = "unstable_const", + feature = "unstable_offset_of", + stable_const + ))] #[test] fn const_offset() { #[repr(C)] @@ -337,7 +377,11 @@ mod tests { assert_eq!([0; offset_of!(Foo, b)].len(), 4); } - #[cfg(any(feature = "unstable_const", stable_const))] + #[cfg(any( + feature = "unstable_const", + feature = "unstable_offset_of", + stable_const + ))] #[test] fn const_fn_offset() { const fn test_fn() -> usize { |