-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider alignment when computing into_raw (#138)
This commit fixes #137 by considering alignment when converting the raw Arc pointer to and raw its raw representation. Signed-off-by: John Nunley <dev@notgull.net>
- Loading branch information
Showing
2 changed files
with
33 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
#![cfg(any(feature = "std", feature = "alloc"))] | ||
|
||
use portable_atomic_util::Arc; | ||
|
||
#[test] | ||
fn over_aligned() { | ||
#[repr(align(128))] | ||
struct Aligned(u32); | ||
|
||
let value = Arc::new(Aligned(128)); | ||
let ptr = Arc::into_raw(value); | ||
// SAFETY: `ptr` should always be a valid `Aligned`. | ||
assert_eq!(unsafe { (&*ptr).0 }, 128); | ||
// SAFETY: `ptr` is a valid reference to an `Arc<Aligned>`. | ||
let value = unsafe { Arc::from_raw(ptr) }; | ||
assert_eq!(value.0, 128); | ||
} |