Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rustfmt.toml with tab_spaces set to 2 & run cargo fmt #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions benches/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
#![feature(test)]
extern crate test;
extern crate fringe;
extern crate test;

use fringe::{OsStack, Generator};
use fringe::{Generator, OsStack};

#[bench]
fn generate(b: &mut test::Bencher) {
let stack = OsStack::new(0).unwrap();
let mut identity = Generator::new(stack, move |yielder, mut input| {
loop { input = yielder.suspend(input) }
let mut identity = Generator::new(stack, move |yielder, mut input| loop {
input = yielder.suspend(input)
});

b.iter(|| for _ in 0..10 { test::black_box(identity.resume(test::black_box(0))); });
unsafe { identity.unsafe_unwrap(); }
b.iter(|| {
for _ in 0..10 {
test::black_box(identity.resume(test::black_box(0)));
}
});
unsafe {
identity.unsafe_unwrap();
}
}
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tab_spaces = 2
8 changes: 5 additions & 3 deletions tests/fpe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#![feature(asm)]
extern crate fringe;
extern crate test;
use fringe::{OsStack, Generator};
use fringe::{Generator, OsStack};
use test::black_box;

const FE_DIVBYZERO: i32 = 0x4;
extern {
extern "C" {
fn feenableexcept(except: i32) -> i32;
}

Expand All @@ -27,6 +27,8 @@ fn fpe() {
yielder.suspend(1.0 / black_box(0.0));
});

unsafe { feenableexcept(FE_DIVBYZERO); }
unsafe {
feenableexcept(FE_DIVBYZERO);
}
println!("{:?}", gen.resume(()));
}
14 changes: 7 additions & 7 deletions tests/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
// copied, modified, or distributed except according to those terms.
extern crate fringe;

use fringe::{SliceStack, OwnedStack, OsStack};
use fringe::generator::{Generator, Yielder};
use fringe::{OsStack, OwnedStack, SliceStack};

fn add_one_fn(yielder: &Yielder<i32, i32>, mut input: i32) {
loop {
if input == 0 { break }
if input == 0 {
break;
}
input = yielder.suspend(input + 1)
}
}
Expand Down Expand Up @@ -48,7 +50,7 @@ fn move_after_new() {
#[should_panic]
fn panic_safety() {
struct Wrapper {
gen: Generator<'static, (), (), OsStack>
gen: Generator<'static, (), (), OsStack>,
}

impl Drop for Wrapper {
Expand All @@ -58,9 +60,7 @@ fn panic_safety() {
}

let stack = OsStack::new(4 << 20).unwrap();
let gen = Generator::new(stack, move |_yielder, ()| {
panic!("foo")
});
let gen = Generator::new(stack, move |_yielder, ()| panic!("foo"));

let mut wrapper = Wrapper { gen: gen };
wrapper.gen.resume(());
Expand Down Expand Up @@ -99,7 +99,7 @@ fn forget_yielded() {
}
}

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, ()| {
yielder.suspend(Dropper(&flag));
Expand Down
10 changes: 7 additions & 3 deletions tests/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
// copied, modified, or distributed except according to those terms.
extern crate fringe;

use fringe::OsStack;
use fringe::generator::Generator;
use fringe::OsStack;

#[test]
fn producer() {
let stack = OsStack::new(0).unwrap();
let mut gen = Generator::new(stack, move |yielder, ()| {
for i in 0.. { yielder.suspend(i) }
for i in 0.. {
yielder.suspend(i)
}
});
assert_eq!(gen.next(), Some(0));
assert_eq!(gen.next(), Some(1));
assert_eq!(gen.next(), Some(2));
unsafe { gen.unsafe_unwrap(); }
unsafe {
gen.unsafe_unwrap();
}
}
12 changes: 8 additions & 4 deletions tests/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
// copied, modified, or distributed except according to those terms.
#![feature(alloc, allocator_api)]

extern crate core;
extern crate alloc;
extern crate core;
extern crate fringe;

use alloc::alloc::alloc;
use core::alloc::Layout;

use alloc::boxed::Box;
use fringe::{OsStack, OwnedStack, SliceStack, Stack, STACK_ALIGNMENT};
use std::slice;
use fringe::{STACK_ALIGNMENT, Stack, SliceStack, OwnedStack, OsStack};

unsafe fn heap_allocate(size: usize, align: usize) -> *mut u8 {
alloc(Layout::from_size_align_unchecked(size, align))
Expand Down Expand Up @@ -90,7 +90,9 @@ fn default_os_stack() {
assert_eq!(stack.limit() as usize & (STACK_ALIGNMENT - 1), 0);

// Make sure the topmost page of the stack, at least, is accessible.
unsafe { *(stack.base().offset(-1)) = 0; }
unsafe {
*(stack.base().offset(-1)) = 0;
}
}

#[test]
Expand All @@ -100,5 +102,7 @@ fn one_page_os_stack() {
assert_eq!(stack.limit() as usize & (STACK_ALIGNMENT - 1), 0);

// Make sure the topmost page of the stack, at least, is accessible.
unsafe { *(stack.base().offset(-1)) = 0; }
unsafe {
*(stack.base().offset(-1)) = 0;
}
}