Skip to content

Move last error into memory #977

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 4 commits into from
Oct 8, 2019
Merged

Move last error into memory #977

merged 4 commits into from
Oct 8, 2019

Conversation

pvdrz
Copy link
Contributor

@pvdrz pvdrz commented Oct 3, 2019

These changes move the Evaluator::last_error into miri's memory and implement the __errno_location() shim (which is used by the file handling functions when they fail).

@oli-obk
Copy link
Contributor

oli-obk commented Oct 7, 2019

The rustfmt changes are a bit annoying intermingled like that. Can you create a rustfmt commit on master and rebase this PR over it?

@pvdrz pvdrz requested a review from oli-obk October 7, 2019 14:43
@oli-obk
Copy link
Contributor

oli-obk commented Oct 8, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Oct 8, 2019

📌 Commit 459c65a has been approved by oli-obk

bors added a commit that referenced this pull request Oct 8, 2019
Move last error into memory

These changes move the `Evaluator::last_error` into miri's memory and implement the `__errno_location()` shim (which is used by the file handling functions when they fail).
@bors
Copy link
Contributor

bors commented Oct 8, 2019

⌛ Testing commit 459c65a with merge 9d03dd6...

@bors
Copy link
Contributor

bors commented Oct 8, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: oli-obk
Pushing 9d03dd6 to master...

@bors bors merged commit 459c65a into rust-lang:master Oct 8, 2019
@bors bors mentioned this pull request Oct 8, 2019
@@ -88,7 +92,7 @@ pub struct Evaluator<'tcx> {
pub(crate) cmd_line: Option<Pointer<Tag>>,

/// Last OS error.
Copy link
Member

Choose a reason for hiding this comment

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

Now that this is a memory location, the comment should say e.g. how big it is (seems to always be 4 bytes?). Also, this was previously used for Windows stuff, errno_location is a Linux thing; can the two really share the same field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add a comment about its size. It should work for windows in principle because windows uses an u32 and linux uses an i32.

I think only disadvantage of adding this is that we have the indirection of having to get the location pointer and then get the pointeé. But it shouldn't affect the capablities of setting and getting the error in either of the two platforms.

.not_undef()
}

fn consume_io_error(&mut self, e: std::io::Error) -> InterpResult<'tcx> {
Copy link
Member

Choose a reason for hiding this comment

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

"consume" is an odd choice of words for a "set_last_error" convenience wrapper.

Is it really worth to have a helper for set_last_error(e.raw_os_error().unwrap())? Maybe it is, but then please call it something that indicates in its name that this sets the last_error variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well I think its useful for fs related stuff because it allows to use the raw error itself to set errno instead of having to match the io::Error and set the proper errno for each case. I'll think about a decent name and add some comments explaining its behavior.

@RalfJung
Copy link
Member

This PR comes without any test... but looks like #976 some some errno things?

@pvdrz
Copy link
Contributor Author

pvdrz commented Oct 13, 2019

This PR comes without any test... but looks like #976 some some errno things?

Yes, there is no test in this PR. But the fs related functions use this when erroring. So that's why we tested that the fs functions failed correctly so late. Maybe I should add a comment about that in the test.

Edit: #992

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

Successfully merging this pull request may close these issues.

4 participants