aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Farrell <jamesfarrell@google.com>2023-09-05 23:51:15 +0000
committerJames Farrell <jamesfarrell@google.com>2023-09-05 23:51:15 +0000
commit6146b87f3238258f52b7f32b370989b3ef8586ef (patch)
tree55e17a784a4f68296477f1a8138cd16288ac2592
parent4ef246142aed32fe3366914885a7af4b7228a235 (diff)
downloadmemoffset-6146b87f3238258f52b7f32b370989b3ef8586ef.tar.gz
Upgrade memoffset to 0.9.0
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/+/main:tools/external_updater/README.md Test: TreeHugger Change-Id: I8f2474290a200f9ea850b6162e6cdc6eae0757e3
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp4
-rw-r--r--Cargo.toml3
-rw-r--r--Cargo.toml.orig3
-rw-r--r--METADATA10
-rw-r--r--src/lib.rs1
-rw-r--r--src/offset_of.rs76
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
diff --git a/Android.bp b/Android.bp
index 0278558..62dbb42 100644
--- a/Android.bp
+++ b/Android.bp
@@ -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,
diff --git a/Cargo.toml b/Cargo.toml
index 5d71c64..77fe68f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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 = []
diff --git a/METADATA b/METADATA
index 5ccdb78..1bf6b94 100644
--- a/METADATA
+++ b/METADATA
@@ -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
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 356595d..f0aab7b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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 {