-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add alignment feature and use #[repr(align(x))] #1044
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Experimented with running an extra iteration of |
If you like this approach and find it OK to merge, ping me and I'll add the same things to the remaining |
Looks good to me! I'd be ok using this for all remaining structs as well |
I think some tests may still be failing? |
Yes. Still some things to solve. I have been busy the last few days, so not entirely sure when I will be done with this. But will ping when I feel I have a finished solution :) |
Now I got a bit further. But are there maybe nicer ways to write what I have already done? Also, I struggle with figuring out the test failure on |
Ah I think u64 has a 4 byte alignment on 32-bit platforms (or at least on Linux), so that may need a conditional alignment attribute |
Finally had time to finish the rest of the structs and their corresponding constants. Some open questions:
|
Thanks! All the changes look good to me yeah, although I'd be fine without the For the feature, yeah, mind adding a blurb to the README about it? |
Done. I removed the commit that added the custom test and added a commit with an extra paragraph in the README. |
@bors: r+ Thanks! |
📌 Commit e167a73 has been approved by |
Add alignment feature and use #[repr(align(x))] Trying to solve #1042. Here I introduce the discussed feature that will allow going from struct alignment with a private `__align` field to using `#[repr(align(x))]`. However, I have not implemented it for all structs that require alignment yet, only `in6_addr`. This because I did not want to spend too much time before we have discussed and solved the remaining questions regarding this. One thing to discuss is testing. I have so far not done anything to the CI scripts. So currently they will still test the crate only with the `align` feature disabled. Thus they will make sure the `__align` fields are still correct. But no automatic tests make sure everything is correct when the `align` feature is turned on. What do we want to do about that? Can we insert another `cargo test` with `--features align` to make all the Travis jobs run the test suite twice, or will that slow things down too much? I have tried using this version of libc in rustc and the standard library. And successfully changed `Ipv6Addr::new` to not use any `unsafe` and to become a `const fn`. Whether or not we want that is out of scope for this PR, but my point was that the changes introduced with this PR allow much more flexible usage of the libc structs that have alignment.
☀️ Test successful - status-appveyor, status-travis |
…TimNN Make IpvXAddr::new const fns and the well known addresses associated constants Implements/fixes rust-lang#44582 I just got a PR towards libc (rust-lang/libc#1044) merged. With the new feature added in that PR it is now possible to create `in6_addr` instances as consts. This enables us to finally make the constructors of the IP structs const fns and to make the localhost/unspecified addresses associated constants, as agreed in the above mentioned tracking issue. I also added a BROADCAST constant. Personally this is the well known address I tend to need the most often.
Make IpvXAddr::new const fns and the well known addresses associated constants Implements/fixes #44582 I just got a PR towards libc (rust-lang/libc#1044) merged. With the new feature added in that PR it is now possible to create `in6_addr` instances as consts. This enables us to finally make the constructors of the IP structs const fns and to make the localhost/unspecified addresses associated constants, as agreed in the above mentioned tracking issue. I also added a BROADCAST constant. Personally this is the well known address I tend to need the most often.
Bump version to 0.2.43 Would be nice to have the new align feature from #1044 available for general use. But mostly I want this released since I have problems using the align feature for a PR on libstd, and I suspect it's somehow because I try to use an unpublished libc (rust-lang/rust#52872).
Make IpvXAddr::new const fns and the well known addresses associated constants Implements/fixes #44582 I just got a PR towards libc (rust-lang/libc#1044) merged. With the new feature added in that PR it is now possible to create `in6_addr` instances as consts. This enables us to finally make the constructors of the IP structs const fns and to make the localhost/unspecified addresses associated constants, as agreed in the above mentioned tracking issue. I also added a BROADCAST constant. Personally this is the well known address I tend to need the most often.
Trying to solve #1042.
Here I introduce the discussed feature that will allow going from struct alignment with a private
__align
field to using#[repr(align(x))]
. However, I have not implemented it for all structs that require alignment yet, onlyin6_addr
. This because I did not want to spend too much time before we have discussed and solved the remaining questions regarding this.One thing to discuss is testing. I have so far not done anything to the CI scripts. So currently they will still test the crate only with the
align
feature disabled. Thus they will make sure the__align
fields are still correct. But no automatic tests make sure everything is correct when thealign
feature is turned on. What do we want to do about that? Can we insert anothercargo test
with--features align
to make all the Travis jobs run the test suite twice, or will that slow things down too much?I have tried using this version of libc in rustc and the standard library. And successfully changed
Ipv6Addr::new
to not use anyunsafe
and to become aconst fn
. Whether or not we want that is out of scope for this PR, but my point was that the changes introduced with this PR allow much more flexible usage of the libc structs that have alignment.