-
Notifications
You must be signed in to change notification settings - Fork 349
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
Implement readlink
#1564
Implement readlink
#1564
Conversation
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.
Thanks a lot. I particularly like the extensive test. :)
src/shims/os_str.rs
Outdated
@@ -62,27 +62,28 @@ fn convert_path_separator<'a>( | |||
|
|||
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {} | |||
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> { | |||
|
|||
#[cfg(unix)] | |||
fn bytes_to_os_str<'a>(&self, bytes: &'a [u8]) -> InterpResult<'tcx, &'a OsStr> { |
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.
Why did you add a self
parameter?
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 makes it easier to invoke from outside this module - if it's an inherent or freestanding method, you need to name this module or this EvalContextExt
trait or explicitly.
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.
That's what we do for other context-independent helper functions though, so I think we should also do it here.
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.
Done
Thanks. :) |
📌 Commit e0ca8c4 has been approved by |
Implement `readlink` Due to the truncating behavior of `readlink`, I was not able to directly use any of the existing C-cstring helper functions.
💔 Test failed - status-appveyor |
tests/run-pass/fs.rs
Outdated
// and check that the last byte is not overwritten. | ||
let mut large_buf = vec![0xFF; expected_path.len() + 1]; | ||
let res = unsafe { libc::readlink(symlink_c_ptr, large_buf.as_mut_ptr().cast(), large_buf.len()) }; | ||
assert_eq!(res, large_buf.len() as isize - 1); |
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.
Looks like this assertion is failing on a Windows host when running the Linux target:
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `67`,
right: `68`', $DIR/fs.rs:242:9
@RalfJung: I've swapped the order of some of the assertions so that the actual paths will be compared first. Can we re-run the tests on windows? |
Implement `readlink` Due to the truncating behavior of `readlink`, I was not able to directly use any of the existing C-cstring helper functions.
Hm maybe I cannot have multiple bors commands in one comment? Or is the "+" mandatory here? @bors delegate+ |
✌️ @Aaron1011 can now approve this pull request |
💔 Test failed - status-appveyor |
Left path: It looks like we're joining the path with the wrong platform separator somewhere. |
Oh, I guess that's why those helper functions exist in the first place 😆 |
Due to the truncating behavior of `readlink`, I was not able to directly use any of the existing C-cstring helper functions.
Co-authored-by: Ralf Jung <post@ralfj.de>
@bors try |
Implement `readlink` Due to the truncating behavior of `readlink`, I was not able to directly use any of the existing C-cstring helper functions.
src/shims/os_str.rs
Outdated
@@ -14,52 +14,11 @@ use rustc_target::abi::LayoutOf; | |||
use crate::*; | |||
|
|||
/// Represent how path separator conversion should be done. | |||
enum Pathconversion { | |||
pub enum Pathconversion { |
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.
While you are at it, could you rename this to PathConversion
?
💔 Test failed - status-appveyor |
We're getting closer: Left: We're now returning a 'correct' path from |
Yeah I ran into this before, where paths from the environment are the wrong way... The thing is, the Linux target should work as well as possible on a Windows host out of the box, so we cannot necessarily expect the environment to do path conversion. But I also see no good way to do this automatically in the interpreter. We could do something in the test (normalize separators in |
@bors try |
Implement `readlink` Due to the truncating behavior of `readlink`, I was not able to directly use any of the existing C-cstring helper functions.
☀️ Try build successful - checks-travis, status-appveyor |
|
||
#[cfg(not(windows))] | ||
return PathBuf::from(tmp.replace("\\", "/")); | ||
}).unwrap_or_else(|_| std::env::temp_dir()) |
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.
I start to wonder if we should put this in a lazy_static to avoid recomputing all the time.^^ But that is a question for another PR.
Thanks, and nice work. :) |
📌 Commit 3aaab3d has been approved by |
☀️ Test successful - checks-travis, status-appveyor |
Due to the truncating behavior of
readlink
, I was not able todirectly use any of the existing C-cstring helper functions.