Skip to content

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

Open
@rhn

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions