Skip to content

Remove mem::transmute used in Box<str> conversions #44890

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

Merged
merged 9 commits into from
Oct 4, 2017

Conversation

nvzqz
Copy link
Contributor

@nvzqz nvzqz commented Sep 27, 2017

Given that #44877 is failing, I decided to make a separate PR. This is done with the same motivation: to avoid mem::transmute-ing non #[repr(C)] types.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton
Copy link
Member

@bors: r+

Thanks!

@bors
Copy link
Collaborator

bors commented Sep 27, 2017

📌 Commit 36d663f has been approved by alexcrichton

@aidanhs aidanhs added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Sep 28, 2017
@nvzqz
Copy link
Contributor Author

nvzqz commented Sep 28, 2017

I may add some more similar changes for OsStr and CStr APIs before this gets merged, if that's ok.

@alexcrichton
Copy link
Member

Sure! Feel free to just ping me when that happens

@@ -312,7 +312,7 @@ impl CString {
pub unsafe fn from_raw(ptr: *mut c_char) -> CString {
let len = libc::strlen(ptr) + 1; // Including the NUL byte
let slice = slice::from_raw_parts(ptr, len as usize);
CString { inner: mem::transmute(slice) }
CString { inner: Box::from_raw(slice as *mut [c_char] as *mut [u8]) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use slice::from_raw_parts_mut to get a &mut [i8].

[00:02:36] error[E0606]: casting `&[i8]` as `*mut [i8]` is invalid
[00:02:36]    --> /checkout/src/libstd/ffi/c_str.rs:315:40
[00:02:36]     |
[00:02:36] 315 |         CString { inner: Box::from_raw(slice as *mut [c_char] as *mut [u8]) }
[00:02:36]     |                                        ^^^^^^^^^^^^^^^^^^^^^^

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Collaborator

bors commented Sep 28, 2017

📌 Commit 627998e has been approved by alexcrichton

@nvzqz
Copy link
Contributor Author

nvzqz commented Sep 28, 2017

@alexcrichton this should be good to go once cb2a656 passes.

@alexcrichton
Copy link
Member

@bors: r+

Thanks!

@bors
Copy link
Collaborator

bors commented Sep 28, 2017

📌 Commit cb2a656 has been approved by alexcrichton

@bors
Copy link
Collaborator

bors commented Sep 30, 2017

⌛ Testing commit cb2a656 with merge 8b95ab453e0e8f3ccb3333a8f78007de889c8e39...

@bors
Copy link
Collaborator

bors commented Sep 30, 2017

💔 Test failed - status-appveyor

The innermost type is not [u8] on all platforms but is assumed to have
the same memory layout as [u8] since this conversion was done via
mem::transmute before.
@nvzqz
Copy link
Contributor Author

nvzqz commented Oct 1, 2017

@bors: retry

Edit: It was worth a shot 😅

@bors
Copy link
Collaborator

bors commented Oct 1, 2017

@nvzqz: 🔑 Insufficient privileges: and not in try users

1 similar comment
@bors
Copy link
Collaborator

bors commented Oct 1, 2017

@nvzqz: 🔑 Insufficient privileges: and not in try users

@kennytm
Copy link
Member

kennytm commented Oct 1, 2017

@nvzqz The bors error is legitimate.

@nvzqz
Copy link
Contributor Author

nvzqz commented Oct 1, 2017

@kennytm I committed another change that should fix the error on appveyor, so I was trying to get bors to try again with the new changes in this PR

@kennytm
Copy link
Member

kennytm commented Oct 2, 2017

@nvzqz retry only works on approved commits, if you create a new commit, someone will need to r+ it again 🙂

@nvzqz
Copy link
Contributor Author

nvzqz commented Oct 2, 2017

I didn't know that. Thanks!

@carols10cents carols10cents added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 2, 2017
@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Collaborator

bors commented Oct 4, 2017

📌 Commit f1798d3 has been approved by alexcrichton

@bors
Copy link
Collaborator

bors commented Oct 4, 2017

⌛ Testing commit f1798d3 with merge 417ffc9...

bors added a commit that referenced this pull request Oct 4, 2017
Remove mem::transmute used in Box<str> conversions

Given that #44877 is failing, I decided to make a separate PR. This is done with the same motivation: to avoid `mem::transmute`-ing non `#[repr(C)]` types.
@bors
Copy link
Collaborator

bors commented Oct 4, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 417ffc9 to master...

@bors bors merged commit f1798d3 into rust-lang:master Oct 4, 2017
weiznich added a commit to weiznich/diesel that referenced this pull request Dec 20, 2017
Neither PgConnection nor PgMetadataLookup are marked as `#[repr(C)]` so
this is at least implemetation defined behaviour.

(The implementation of `std::path::Path` changed in rust-lang/rust#44890)
@nvzqz nvzqz deleted the str-box-transmute branch December 25, 2017 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants