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

Future-proof the kevent ABI #1572

Merged
merged 2 commits into from
May 8, 2022
Merged

Conversation

asomers
Copy link
Collaborator

@asomers asomers commented May 7, 2022

FreeBSD 12 adds some new private fields to struct kevent, and it changes
the type of "data" from intptr_t to i64. For now libc only binds the
11-compat ABI, but that will change some day. Adjust mio's structure
definitions for compatibility with either ABI.

This should work on all 32 and 64 bit platforms.

FreeBSD 12 adds some new private fields to struct kevent, and it changes
the type of "data" from intptr_t to i64.  For now libc only binds the
11-compat ABI, but that will change some day.  Adjust mio's structure
definitions for compatibility with either ABI.

This should work on all 32 and 64 bit platforms.
target_os = "ios",
target_os = "macos"
))]
type Data = libc::intptr_t;
Copy link
Collaborator

Choose a reason for hiding this comment

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

DragonFlyBSD and MacOS (and likely iOS) still use intptr_t in the manual. I think to be safe we should stick to that as well. You can just move FreeBSD down to NetBSD and OpenBSD.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Except that FreeBSD 11 also still uses intptr_t. And currently there's no way for a crate to select which libc ABI it wants to use. So by removing that type entirely we'll just rely on type inference.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But you're using as i64 in multiple places below, so it doesn't use type interference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. I changed the argument type of kevent_register to use i64 everywhere, instead of being platform-dependent. So now there's only one place that needs type inference: line 284 (and line 61, before my second commit). Those are the only places that actually use the libc type.

@@ -60,6 +49,7 @@ macro_rules! kevent {
fflags: 0,
data: 0,
udata: $data as UData,
..unsafe { mem::zeroed() }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a note that this is needed for FreeBSD?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure. Except, looking at it again, I realize that I should've just deleted the fflags and data field initializers.

@Thomasdezeeuw Thomasdezeeuw merged commit 5b7d8e2 into tokio-rs:master May 8, 2022
@Thomasdezeeuw
Copy link
Collaborator

Thanks @asomers.

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.

None yet

2 participants