-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
libc::clone() should take an unsafe callback #2198
Comments
I'm not sure why this change is needed as that function should be usable currently.
Yup, it'll be a breaking change. |
Sure, it's possible to work around this via transmute. It just introduces another opportunity for error. I guess this is a breaking change because someone might care about the type of the |
If it's usable then I don't see any strong reason to change. Could you show some situation it should be changed? |
We can agree it's a bug, right? Just one that can be worked around. I defer to your judgment whether it's worth fixing; feel free to close. |
I don't think it's a bug but an improvement, though. So, adding |
is not libc still 0.x.y, which means it can have breaking changes? |
You don't have to use the context parameter. |
how? are not safe fn pointers implicitly castable to unsafe fn pointers? link to working example with the same typed fn pointer as the OP's suggestion:https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=use%20std%3A%3Affi%3A%3Ac_void%3B%0Ause%20std%3A%3Aos%3A%3Araw%3A%3Ac_int%3B%0A%0Aextern%20%22C%22%20fn%20foo(_%3A%20*mut%20c_void)%20-%3E%20c_int%20%7B%201%20%7D%0A%0Afn%20takes_unsafe_callback(callback%3A%20unsafe%20extern%20%22C%22%20fn(*mut%20c_void)%20-%3E%20c_int)%20%7B%0A%20%20%20%20unsafe%20%7B%20callback(0%20as%20_)%3B%20%7D%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20takes_unsafe_callback(foo%20as%20extern%20%22C%22%20fn(*mut%20c_void)%20-%3E%20c_int)%3B%0A%7D |
Let's just do this for 1.0, along with any other functions that take a callback with pointer arguments. PRs are welcome! |
Just for context, the problem is that Rust's best practices require all safe (even internal) functions to be sound when called with arbitrary arguments. However, a callback that doesn't just ignore its argument but casts it to I'm glad this is going to be fixed in 1.0. |
On Linux, clone takes a callback function pointer. The function pointer type is not marked
unsafe
, but there is basically no way to implement this callback with a safe function since it takes its context parameter by pointer.It seems to me that
unsafe
should be added to the function pointer type, e.g.:I'm not certain, but I don't think this would be a breaking change.
The text was updated successfully, but these errors were encountered: