forked from M-Labs/libfringe
Don't use unsafe for the forget_yielded test
Now that the Send bound is gone, we can simply use a Cell instead of a raw pointer.
This commit is contained in:
parent
661872f725
commit
dcde4fe920
|
@ -85,23 +85,22 @@ fn with_owned_stack() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn forget_yielded() {
|
fn forget_yielded() {
|
||||||
struct Dropper(*mut bool);
|
use std::cell::Cell;
|
||||||
|
struct Dropper<'a>(&'a Cell<bool>);
|
||||||
|
|
||||||
impl Drop for Dropper {
|
impl<'a> Drop for Dropper<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
if self.0.get() {
|
||||||
if *self.0 {
|
panic!("double drop!")
|
||||||
panic!("double drop!")
|
|
||||||
}
|
|
||||||
*self.0 = true;
|
|
||||||
}
|
}
|
||||||
|
self.0.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let stack = fringe::OsStack::new(1<<16).unwrap();
|
let stack = fringe::OsStack::new(1<<16).unwrap();
|
||||||
|
let flag = Cell::new(false);
|
||||||
let mut generator = Generator::new(stack, |yielder, ()| {
|
let mut generator = Generator::new(stack, |yielder, ()| {
|
||||||
let mut flag = false;
|
yielder.suspend(Dropper(&flag));
|
||||||
yielder.suspend(Dropper(&mut flag as *mut bool));
|
|
||||||
});
|
});
|
||||||
generator.resume(());
|
generator.resume(());
|
||||||
generator.resume(());
|
generator.resume(());
|
||||||
|
|
Loading…
Reference in New Issue