-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Oibit send and friends #20119
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
Oibit send and friends #20119
Conversation
Can we add a lint or something for "probably wrong" implementations of I'm also not really sure why |
Er, I may have misremembered the OIBIT RFC. The plan is that |
|
||
/// A version of `UnsafeCell` intended for use in concurrent data | ||
/// structures (for example, you might put it in an `Arc`). | ||
pub struct RacyCell<T>(pub UnsafeCell<T>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may not necessarily be a public-facing API that we're willing to commit to at this time, could this be moved into just the std::comm
implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Actually, @nikomatsakis had asked me to do that already. I haven't done it yet because I didn't quite understand the need. Now I do, thanks for the comment :D
Awesome work! Can't wait for this to land! |
@sfackler Yes, your summary is basically an accurate depiction of the end goal. This RFC does not get all the way there, but it does a big chunk of the work. This RFC doesn't offer a means to explicitly opt out (beyond the marker types that already exist). However, it DOES require an unsafe, explicit opt in if your type contains unsafe pointers (or marker types, but that'd be kind of silly). In a follow-up RFC, we will also make it so that types containing |
b6db832
to
60bb169
Compare
Hmm, so, I think |
@nikomatsakis I believe |
b8e171d
to
28b3496
Compare
This looks great! r+ modulo the "DOX" comments |
31d93c4
to
0b5bc5c
Compare
Giving high priority because this is an important language change, and also somewhat conflict prone. |
1ba46e0
to
386f910
Compare
823830c
to
cb8e06b
Compare
RacyCell is not exactly what we'd like as a final implementation for this. Therefore, we're moving it under `std::comm` and also making it private.
Mostly following the convention in RFC 356
Besides the above making sense, it'll also allow us to make `RacyCell` private and use UnsafeCell instead.
cb8e06b
to
bb315f2
Compare
@@ -59,7 +60,8 @@ fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> Option<CVec<u8>> { | |||
&mut outsz, | |||
flags); | |||
if !res.is_null() { | |||
Some(CVec::new_with_dtor(res as *mut u8, outsz as uint, move|:| libc::free(res))) | |||
let res = Unique(res); | |||
Some(CVec::new_with_dtor(res.0 as *mut u8, outsz as uint, move|:| libc::free(res.0))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cast it to a Unique
and immediately cast it back?
ad5233b
to
11f71ec
Compare
…tsakis More work on opt-in built in traits. `Send` and `Sync` are not opt-in, `OwnedPtr` renamed to `UniquePtr` and the `Send` and `Sync` traits are now unsafe. NOTE: This likely needs to be rebased on top of the yet-to-land snapshot. r? @nikomatsakis cc #13231
💯 |
This is a breaking change; please tag it as such. Any ffi library that was previously using *c_void pointers to have Send wrappers around a c interface (eg. database handle) will be broken after this change. |
To others who find this, the solution is to manually implement Send boilerplate on your type, as shown in the change log above:
|
@shadowmint note that it's not always required a As for the broken For example: extern crate core;
extern crate libc;
use libc::c_int;
use core::ptr::Unique;
fn test_send<T:Send>(s: T) {}
fn main() {
let x = Unique(0 as *mut libc::c_int);
test_send(x);
// test_send(0 as *mut libc::c_int); // this fails
} |
More work on opt-in built in traits.
Send
andSync
are not opt-in,OwnedPtr
renamed toUniquePtr
and theSend
andSync
traits are now unsafe.NOTE: This likely needs to be rebased on top of the yet-to-land snapshot.
r? @nikomatsakis
[breaking-change]
cc #13231