-
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
SCTP support for FreeBSD, NetBSD #786
Conversation
@alexcrichton I'm fairly new to Rust, so I have a couple of questions for you about this PR:
|
@@ -281,6 +285,419 @@ s! { | |||
pub ifm_index: ::c_ushort, | |||
pub ifm_data: if_data, | |||
} | |||
|
|||
// SCTP support | |||
// sys/netinet/sctp.h |
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.
without sys/
here and in the next line
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.
You're right, I'll fix the comment -- thanks!
Thanks for the NetBSD patch! |
Thanks for the PR @jack-pappas! To help answer your questions, I think you should be able to add For |
Thank you for your response Alex. I'll try adding As for |
Nah right now we avoid that sort of conditional compilation, it's easier and more robust to stick to one source. |
I've added |
c18e369
to
f16544e
Compare
I changed the main type using There are some errors remaining, which appear to be due to some of the new structs using the equivalent of a C99 flexible array; they can't implement the |
pub struct sctp_gen_error_cause { | ||
pub code: ::uint16_t, | ||
pub length: ::uint16_t, | ||
pub info: [::uint8_t] |
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.
Oh this I don't think is FFI-safe or possible for us to define, for something like this historically I've just defined a 0-length array here instead of a DST array
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.
Does fixing this fix the all the remaining errors?
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 can check to see if using a zero-length array instead fixes the errors, but why would using the flexible / dynamically-sized arrays be FFI-unsafe? If the definition of the struct
in the Rust code matches what's in the C header, isn't that all that's needed for FFI-compatibility?
It seems much more unsafe to use a zero-length array -- consumers of the type will need to use that array like a raw pointer. If the struct is moved or copied somewhere else in memory, the array data won't be copied along with it, and consumers of the struct won't have any real way to tell whether they're looking at the "original" struct with valid data in the array or a copy that's been moved and now has invalid/garbage data where it's expecting the array to be.
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.
Sorry I don't have a lot of time to go in depth, but the errors here basically show how a dynamically sized array is a no-go. If it worked that'd be great and for sure better than a zero-length array, but I don't believe it works.
b72aafc
to
79cf2c8
Compare
☔ The latest upstream changes (presumably #809) made this pull request unmergeable. Please resolve the merge conflicts. |
I've fixed the merge conflicts and made the suggested changes for the arrays. I'm still getting two linter errors:
Does that mean it's not possible to define constants used for the array lengths within the struct definitions? If not, I'll just change the arrays in the structs to inline the constant values, but figured it'd be nicer to preserve the constant as in the original C headers. |
Oh that's just a stylistic lint which just requires a few things to move around. |
☔ The latest upstream changes (presumably #802) made this pull request unmergeable. Please resolve the merge conflicts. |
1f49e1d
to
b177cad
Compare
707d8d8
to
294f776
Compare
@alexcrichton One of the structs (as defined in the C headers) has a field called There are also a few remaining issues in the tests where the generated C code is doing |
Ah I've typically just been callng such field I think the same script should enable you to ignore certain fields in particular structs which may help? |
4bcf752
to
9ab9525
Compare
☔ The latest upstream changes (presumably #840) made this pull request unmergeable. Please resolve the merge conflicts. |
Notification and log `union` types are exposed as partially-opaque structs for now, until libc targets a version of Rust which supports unions.
☔ The latest upstream changes (presumably #867) made this pull request unmergeable. Please resolve the merge conflicts. |
I'm gonna close this due to inactivity, but it can always be resubmitted! |
This PR adds constants, structs, and functions for SCTP networking support on FreeBSD and NetBSD.