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

Crash when non-move closure passed to Generator::new #65

Open
rhn opened this issue Feb 17, 2017 · 2 comments
Open

Crash when non-move closure passed to Generator::new #65

rhn opened this issue Feb 17, 2017 · 2 comments

Comments

@rhn
Copy link

rhn commented Feb 17, 2017

Using a move closure inside a struct::fn which borrows a struct field results in corrupted memory when that closure is not move.

Example:

extern crate fringe;
use std::iter::Iterator;
use fringe::generator::Yielder;
use fringe::{OsStack, Generator};

struct Gpx {
    creator: String,
}

type Generator_<T> = fringe::Generator<(), T, fringe::OsStack>;

impl Gpx {
    pub fn events<'a>(&'a self) -> Generator_<&'a str> {
        let stack = OsStack::new(1 << 24).unwrap();
        Generator::new(stack, |ctx, ()| { // broken
        // Generator::new(stack, move |ctx, ()| { // working
            ctx.suspend(self.creator.as_str());
        })
    }
}

fn main() {
    let data = Gpx{ creator: String::from("xyz") };
    println!("{:?}", data.events().next());
}

Unfortunately, I don't know if it's a problem with type checking or the unsafe portion. Given some pointers, I will try to debug it myself.

@edef1c
Copy link
Owner

edef1c commented Feb 18, 2017

That's.. surprising. The generator shouldn't be able to outlive the captures.

@edef1c
Copy link
Owner

edef1c commented Feb 18, 2017

Ah. This is fixed in master (intended to be released as 2.x), but we had a bunch of stuff blocking the release, and then real life intervened.. Time to pick that back up I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants