Expose unsafe_unwrap

This at least ensures we don't have to needlessly leak generators in the
tests, and covers similar use cases for consumers of libfringe.
This commit is contained in:
edef 2017-03-06 09:35:40 +01:00
parent d49557a55a
commit df7f261ca6
3 changed files with 5 additions and 5 deletions

View File

@ -8,7 +8,6 @@
extern crate test;
extern crate fringe;
use std::mem;
use fringe::{OsStack, Generator};
#[bench]
@ -19,5 +18,5 @@ fn generate(b: &mut test::Bencher) {
});
b.iter(|| for _ in 0..10 { test::black_box(identity.resume(test::black_box(0))); });
mem::forget(identity);
unsafe { identity.unsafe_unwrap(); }
}

View File

@ -201,7 +201,9 @@ impl<'a, Input, Output, Stack> Generator<'a, Input, Output, Stack>
}
}
unsafe fn unsafe_unwrap(mut self) -> Stack {
/// Extracts the stack from a generator without checking if the generator function has returned.
/// This will leave any pointers into the generator stack dangling, and won't run destructors.
pub unsafe fn unsafe_unwrap(mut self) -> Stack {
ptr::drop_in_place(&mut self.stack_id.value);
let stack = ptr::read(&mut self.stack.value);
mem::forget(self);

View File

@ -8,7 +8,6 @@ extern crate fringe;
use fringe::OsStack;
use fringe::generator::Generator;
use std::mem;
#[test]
fn producer() {
@ -19,5 +18,5 @@ fn producer() {
assert_eq!(gen.next(), Some(0));
assert_eq!(gen.next(), Some(1));
assert_eq!(gen.next(), Some(2));
mem::forget(gen);
unsafe { gen.unsafe_unwrap(); }
}