Skip to content

Memory issue with zero-sized types #7

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

Closed
eun-ice opened this issue Mar 26, 2019 · 2 comments
Closed

Memory issue with zero-sized types #7

eun-ice opened this issue Mar 26, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@eun-ice
Copy link
Contributor

eun-ice commented Mar 26, 2019

I have a serious issue I cannot explain. My guess is that copyless creates some sort of memory issue when called with static functions.

assume the following traits:

pub struct Runnable {
    runnable_box: Box<RunnableBox + Send>
}

impl Runnable {
    pub fn run(self) {
        self.runnable_box.run();
    }
}

trait RunnableBox {
    fn run(self: Box<Self>);
}

impl<F: FnOnce()> RunnableBox for F {
    fn run(self: Box<F>) {
        (*self)()
    }
}

And these two constructors, one using Box::new, the other using Box::alloc().init

impl Runnable {
    pub fn new_box<F>(func: F) -> Runnable
        where
            F: FnOnce() + Send + 'static {
        Runnable { runnable_box: Box::new(func) }
    }
    #[allow(dead_code)]
    pub fn new_copyless<F>(func: F) -> Runnable
        where
            F: FnOnce() + Send + 'static {
        Runnable { runnable_box: Box::alloc().init(func) }
    }
}

Creating a static Runnable seems to create some sort of memory overwrite I cannot exactly pin down:

Runnable::new_box(move || { println!("scheduled task 1"); }); // Works

Runnable::new_copyless(move || { println!("scheduled task 1"); }) // Error

let now = Instant::now();
Runnable::new_copyless(move || { println!("scheduled task 1 {:?}", now); }) // Works

I have attached a testcase that fails on macos and on linux using Rust 1.33 stable and rustc 1.35.0-nightly (0576ac109 2019-03-24).

copyless.tar.gz

@eun-ice
Copy link
Contributor Author

eun-ice commented Mar 26, 2019

This PR seems to fix the issue: #8

@kvark kvark added the bug Something isn't working label Mar 26, 2019
@kvark kvark changed the title Memory issue? Memory issue with zero-sized types Mar 26, 2019
@eun-ice
Copy link
Contributor Author

eun-ice commented Mar 26, 2019

Closing this issue since #8 has been merged. Will investigate and reopen if this issue pops up again.
Thank you @kvark

@eun-ice eun-ice closed this as completed Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants