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

mismatched types between c_void and boxed closure #59

Closed
izgzhen opened this issue Oct 20, 2015 · 4 comments
Closed

mismatched types between c_void and boxed closure #59

izgzhen opened this issue Oct 20, 2015 · 4 comments

Comments

@izgzhen
Copy link
Contributor

izgzhen commented Oct 20, 2015

When compiled with nightly rustc, this line will report error:

src/asymmetric.rs:271:57: 271:74 error: mismatched types:
 expected `*mut libc::types::common::c95::c_void`,
    found `Box<[closure@src/asymmetric.rs:220:23: 269:10 puller_ref:_, f:_, coro_ref:_]>`
(expected *-ptr,
    found box) [E0308]    
src/asymmetric.rs:271         coro.context.init_with(coroutine_initialize, 0, Box::new(wrapper), &mut stack);

I searched a bit and find a solution from this post: change Box::new(wrapper) into &wrapper as *const _ as *mut libc::c_void

It compiled. But honestly, I am not very familiar with low-level rust so I have no idea why the Box::new is wrong and this casting is right.

@izgzhen
Copy link
Contributor Author

izgzhen commented Oct 20, 2015

Oh, this is still not working. I got bus error when trying to run examples/simple.rs

@zonyitoo
Copy link
Contributor

No, you can't. You should use Box::into_raw(wrapper) as *const _ as *mut libc::c_void

@izgzhen
Copy link
Contributor Author

izgzhen commented Oct 20, 2015

Not working, it doesn't typecheck :(

src/asymmetric.rs:271:71: 271:78 error: mismatched types:
 expected `Box<_>`,
    found `[closure@src/asymmetric.rs:220:23: 269:10 puller_ref:_, f:_, coro_ref:_]`
(expected box,
    found closure) [E0308]
src/asymmetric.rs:271         coro.context.init_with(coroutine_initialize, 0, Box::into_raw(wrapper) as *const _ as *mut libc::c_void, &mut stack);

Or if I first box it then Box::into_raw, it will still lead to runtime error

@zonyitoo
Copy link
Contributor

Please refer to this one: https://github.com/zonyitoo/context-rs/blob/master/examples/asymmetric.rs

They should be almost the same. I am extremely busy these days so I am not going to fix this lately.

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