Skip to content
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 extra traits for all types #1035

Merged
merged 6 commits into from
Jun 12, 2019
Merged

Implement extra traits for all types #1035

merged 6 commits into from
Jun 12, 2019

Conversation

Susurrus
Copy link
Contributor

Now that I've gotten all the extra traits implemented for libc, they can be easily derived for nix's types. Note that this requires a bump to the minimum supported Rust version, but it's still at least 2 versions behind, so it fits in with policy.

One thing I did notice is that we have an inconsistent approach to our newtypes, where some use a struct and some a tuple struct. We should be consistent here, and should probably use a tuple struct since the name of the single field is irrelevant. This style is already suggested in our CONVENTIONS.md doc, so this should be uncontroversial. I'll file a PR after this is merged adding that.

src/mqueue.rs Show resolved Hide resolved
src/sys/socket/addr.rs Show resolved Hide resolved
src/sys/socket/addr.rs Show resolved Hide resolved
src/sys/socket/addr.rs Show resolved Hide resolved
src/sys/socket/addr.rs Show resolved Hide resolved
src/sys/socket/addr.rs Show resolved Hide resolved
@euclio
Copy link
Contributor

euclio commented Apr 2, 2019

Would it be possible to split out just the Debug portion of this PR if the rest of the traits are blocked on upstream libc?

@Susurrus
Copy link
Contributor Author

Susurrus commented Jun 4, 2019

Now that rust-lang/libc#1371 was merged, it's time to come back to this. That should have resolved most of the issues. Gonna test this through CI then do another pass through @asomers' comments.

@Susurrus Susurrus mentioned this pull request Jun 4, 2019
@Susurrus
Copy link
Contributor Author

Susurrus commented Jun 5, 2019 via email

@asomers
Copy link
Member

asomers commented Jun 6, 2019

Sorry I wasn't clear. I was planning to write new tests. The problem is that I dont know how to write them. I can handcraft sockaddr_un structs to test equality, but that seems like I'm coding the same logic in the test and I'm testing for and I dont think it'll provide much value. Or I can modify the stack so that all values are nonzero and use UnixAddr directly to do the comparison. I think the latter would be a better implementation, but I don't know how to do it.

I think the most straightforward way would be to handcraft a libc::sockaddr_un, cast to a libc::sockaddr_storage, convert to a UnixAddr via sockaddr_storage_to_addr, then compare UnixAddrs. That way you'll have byte-level control of the data using only the regular API.

@Susurrus
Copy link
Contributor Author

Susurrus commented Jun 7, 2019

Alright, I implemented something that I think is a reasonable test. Tests passed on my local computer, so if CI passed, I think this is good to go.

@Susurrus Susurrus force-pushed the extra_traits branch 2 times, most recently from 932a219 to af31e92 Compare June 7, 2019 04:45
@Susurrus
Copy link
Contributor Author

Susurrus commented Jun 7, 2019

Looks like PTRACE_ATTACH was changed in a commit at some point I guess and now it can't be found for mips64 targets. However, I'm not finding anywhere where that changed in libc or nix. So that's it for me tonight, I'll need to come back and dig in to it again later.

@asomers
Copy link
Member

asomers commented Jun 7, 2019

Looks like PTRACE_ATTACH was changed in a commit at some point I guess and now it can't be found for mips64 targets. However, I'm not finding anywhere where that changed in libc or nix. So that's it for me tonight, I'll need to come back and dig in to it again later.

Yeah, that one stumped me too. I installed the exact mips64 target for the 1.24.1 toolchain and checked that I'm building against the exact same revision of libc as Travis used, but for me it works.

@Susurrus
Copy link
Contributor Author

Susurrus commented Jun 7, 2019

Figured out I wasn't synced to HEAD and 4bd419ebec2d691f55331e91e799d5fa96180044 was the problem. Filed rust-lang/libc#1393 to resolve.

bors added a commit to rust-lang/libc that referenced this pull request Jun 7, 2019
Re-add PTRACE_DETACH for mips64 GNU targets

During the refactor in 4bd419e, `PTRACE_DETACH` was accidentally removed on
these targets. This re-adds it.

Fixes brokenness encountered during nix-rust/nix#1035

CC @asomers
@asomers asomers mentioned this pull request Jun 7, 2019
@Susurrus
Copy link
Contributor Author

Susurrus commented Jun 7, 2019

Alright, looks like we should be all good to go here now that my libc PR was merged!

test/sys/test_socket.rs Outdated Show resolved Hide resolved
src/sys/signal.rs Show resolved Hide resolved
src/sys/aio.rs Outdated Show resolved Hide resolved
src/dir.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Also bump Rust requirement to 1.25 which is a requirement of that feature
Susurrus added 3 commits June 9, 2019 11:31
Derive Clone, Copy, Eq, Hash, and PartialEq for all types. Not all
traits are supported by all types, which is why many are missing
some.
As this is now derived, having a test is unnecessary
bors added a commit to rust-lang/libc that referenced this pull request Jun 11, 2019
Switch to manual trait impls for sigevent

`sigevent` on most platforms have padding or unused fields. Rather
than display those in the `Debug` impl by deriving it, manually implement
all `extra_traits` instead ignoring those fields.

I do worry that my `PartialEq` implementations for this for some platforms (like Linux) is not correct due to ignoring bytes that shouldn't be ignored because these structs don't have a proper union set up.

cc @asomers
Part of nix-rust/nix#1035
@Susurrus
Copy link
Contributor Author

Alright, I think we're all good with this one. Libc changes have all been merged and tests are all padsing

src/dir.rs Outdated Show resolved Hide resolved
src/sys/socket/addr.rs Show resolved Hide resolved
src/sys/socket/addr.rs Show resolved Hide resolved
test/sys/test_socket.rs Outdated Show resolved Hide resolved
Abstract paths should always be N-1 in length where N is the length of
the `sun_path` field (first byte is \0). Given that,
`UnixAddr::new_abstract()` should always return this N-1 length, not
just the length of the string provided (the rest of the array will be
\0s).
This is a minor optimization that allows for reduced sizes of datatypes. Since this pointer
will never be NULL, it's safe to use here
@Susurrus
Copy link
Contributor Author

Hopefully this is the final necessary batch of changes!

@Susurrus Susurrus requested a review from asomers June 12, 2019 03:16
Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

Woohoo! This is going to be a big improvement.

bors r+

bors bot added a commit that referenced this pull request Jun 12, 2019
1035: Implement extra traits for all types r=asomers a=Susurrus

Now that I've gotten all the extra traits implemented for `libc`, they can be easily derived for `nix`'s types. Note that this requires a bump to the minimum supported Rust version, but it's still at least 2 versions behind, so it fits in with policy.

One thing I did notice is that we have an inconsistent approach to our newtypes, where some use a struct and some a tuple struct. We should be consistent here, and should probably use a tuple struct since the name of the single field is irrelevant. This style is already suggested in our `CONVENTIONS.md` doc, so this should be uncontroversial. I'll file a PR after this is merged adding that.

Co-authored-by: Bryant Mairs <[email protected]>
@bors
Copy link
Contributor

bors bot commented Jun 12, 2019

Build succeeded

@bors bors bot merged commit 37929c7 into master Jun 12, 2019
@Susurrus Susurrus deleted the extra_traits branch June 12, 2019 04:40
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.

3 participants