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

Fix the definition of sigevent on FreeBSD and Linux #3630

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

asomers
Copy link
Contributor

@asomers asomers commented Mar 23, 2024

It was originally defined back before rust could represent C unions. So instead of defining the union field correctly, it simply defined that union's most useful field. Define it correctly now.

Remove traits that can't be safely implemented on a union: PartialEq, Eq, and Hash. Define Debug, but exclude the union field. Leave Clone in place.

This PR is a rebase of #2813 that eschews all of the backwards-compatibility parts.

@rustbot
Copy link
Collaborator

rustbot commented Mar 23, 2024

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@JohnTitor
Copy link
Member

@asomers
Copy link
Contributor Author

asomers commented May 13, 2024

@JohnTitor I fixed the build failure on musl and rebased on main

@asomers
Copy link
Contributor Author

asomers commented May 13, 2024

The Sparc failure is not due to this PR.

@SteveLauC
Copy link
Contributor

Considering the main branch is for version 1.0, which allows breaking changes, I think we can move this forward.

@bors
Copy link
Contributor

bors commented Nov 14, 2024

☔ The latest upstream changes (presumably #3962) made this pull request unmergeable. Please resolve the merge conflicts.

@tgross35
Copy link
Contributor

tgross35 commented Nov 19, 2024

@asomers mind rebasing this when you get the chance? We can get this into main.

@rustbot author

@tgross35 tgross35 added this to the 1.0 milestone Nov 19, 2024
It was originally defined back before rust could represent C unions.  So
instead of defining the union field correctly, it simply defined that
union's most useful field.  Define it correctly now.

Remove traits that can't be safely implemented on a union: PartialEq,
Eq, and Hash.  Define Debug, but exclude the union field.
@asomers
Copy link
Contributor Author

asomers commented Nov 19, 2024

Rebased, @tgross35

This resulted from a merge conflict with 01c72ee when rebasing my PR
@asomers
Copy link
Contributor Author

asomers commented Nov 19, 2024

I think the build failure on s390x is unrelated.

@tgross35
Copy link
Contributor

That job seems to fail a lot, I wrote up #4112.

Thanks for the changes, I'll take a look today.

Comment on lines +1354 to +1356
__unused3: ::c_long,
__unused4: ::c_long,
__unused5: *mut ::c_void,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this maybe just be put in an __aiocb_private structure for clarity?

__unused5: *mut ::c_void,
pub aio_sigevent: sigevent,
pub struct __c_anonymous_sigev_thread {
pub _function: *mut ::c_void, // Actually a function pointer
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be a function pointer?

        pub _function: Option<extern "C" fn(sigval) -> *mut c_void>

__policy: ::c_int,
__error_code: ::c_int,
__return_value: ::ssize_t,
pub aio_offset: off_t,
Copy link
Contributor

@tgross35 tgross35 Nov 20, 2024

Choose a reason for hiding this comment

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

Since this changes depending on file64, could you add this fixme so we catch it when doing that update?

        // FIXME(off64): visible fields depend on __USE_FILE_OFFSET64
        pub aio_offset: off_t,

__return_value: ::ssize_t,
pub aio_offset: off_t,
#[cfg(all(not(target_arch = "x86_64"), target_pointer_width = "32"))]
__unused1: [::c_char; 4],
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't make much of a difference but it looks like glibc calls this __pad https://github.com/bminor/glibc/blob/d899b48a30b2dd27ab25e1cd90ce28b75f7c0755/rt/aio.h#L52

Comment on lines +416 to +419
#[cfg(target_pointer_width = "32")]
__dummy4: [::c_char; 24],
#[cfg(target_pointer_width = "64")]
__dummy4: [::c_char; 16],
Copy link
Contributor

@tgross35 tgross35 Nov 20, 2024

Choose a reason for hiding this comment

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

Assuming ctest complains about using an expression here, could you add a fixme?

Suggested change
#[cfg(target_pointer_width = "32")]
__dummy4: [::c_char; 24],
#[cfg(target_pointer_width = "64")]
__dummy4: [::c_char; 16],
// FIXME(ctest): length should be `32 - 2 * core::mem::size_of::<*const ()>()`
#[cfg(target_pointer_width = "32")]
__dummy4: [::c_char; 24],
#[cfg(target_pointer_width = "64")]
__dummy4: [::c_char; 16],

#[allow(missing_debug_implementations)]
pub union __c_anonymous_sigev_un {
#[cfg(target_pointer_width = "64")]
_pad: [::c_int; (64 - 2 * 4 - 8) / 4],
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you move this to a const SIGEV_PAD_SIZE: usize = ... to match the source?

@@ -12,6 +12,11 @@ missing! {
}

s! {
pub struct __c_anonymous_sigev_thread {
pub _function: *mut ::c_void, // Actually a function pointer
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub _function: *mut ::c_void, // Actually a function pointer
pub _function: Option<extern "C" fn(::sigval_t) -> *mut ::c_void>`

@tgross35
Copy link
Contributor

I went through line by line, everything looks correct here but I left a handful of consistency comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants