Construct test so that it would fail for old code
This commit is contained in:
parent
8b3637635b
commit
45d4bb2541
2 changed files with 22 additions and 5 deletions
|
|
@ -8,12 +8,28 @@ use std::cell::UnsafeCell;
|
|||
|
||||
pub fn main() {
|
||||
let cell = UnsafeCell::new(42);
|
||||
let mut root = Box::new(cell);
|
||||
let box1 = Box::new(cell);
|
||||
|
||||
let a = Box::as_mut_ptr(&mut root);
|
||||
unsafe {
|
||||
name!(a);
|
||||
let alloc_id = alloc_id!(a);
|
||||
let ptr1: *mut UnsafeCell<i32> = Box::into_raw(box1);
|
||||
name!(ptr1);
|
||||
|
||||
let mut box2 = Box::from_raw(ptr1);
|
||||
// `ptr2` will be a descendant of `ptr1`.
|
||||
let ptr2: *mut UnsafeCell<i32> = Box::as_mut_ptr(&mut box2);
|
||||
name!(ptr2);
|
||||
|
||||
// We perform a write through `x`.
|
||||
// Because `ptr1` is ReservedIM, a child write will make it transition to Active.
|
||||
// Because `ptr2` is ReservedIM, a foreign write doesn't have any effect on it.
|
||||
let x = (*ptr1).get();
|
||||
*x = 1;
|
||||
|
||||
// We can still read from `ptr2`.
|
||||
let val = *(*ptr2).get();
|
||||
assert_eq!(val, 1);
|
||||
|
||||
let alloc_id = alloc_id!(ptr1);
|
||||
print_state!(alloc_id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,5 +2,6 @@
|
|||
Warning: this tree is indicative only. Some tags may have been hidden.
|
||||
0.. 4
|
||||
| Act | └─┬──<TAG=root of the allocation>
|
||||
| ReIM| └────<TAG=a>
|
||||
| Act | └─┬──<TAG=ptr1>
|
||||
| ReIM| └────<TAG=ptr2>
|
||||
──────────────────────────────────────────────────
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue