Skip to content

Correct the definition of pthread_t on Darwin #4336

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

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

Conversation

highjeans
Copy link

@highjeans highjeans commented Mar 17, 2025

Description

This PR Fixes #2903, however I am not sure if the change to build.rs is the right way to do it. MacOS has the _opaque_pthread_t type, however in build.rs it gets classified as a type rather than a struct, resulting in the test case for it using _opaque_pthread_t rather than struct _opaque_pthread_t. Please let me know if there is a better way to test _opaque_pthread_t without having to modify the build.rs file.

Sources

https://github.com/apple-oss-distributions/xnu/blob/8d741a5de7ff4191bf97d57b9f54c2f6d4a15585/EXTERNAL_HEADERS/sys/_pthread/_pthread_types.h#L103
https://github.com/apple-oss-distributions/libpthread/blob/main/include/sys/_pthread/_pthread_t.h#L31

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2025

r? @tgross35

rustbot has assigned @tgross35.
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

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Sorry I never looked at this! Looks pretty good to me, just two small requests.

Comment on lines +10 to +16
if #[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
))] {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified to cfg(target_vendor = "apple")

}
}
} else {
pub type pthread_t = crate::uintptr_t;
Copy link
Contributor

Choose a reason for hiding this comment

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

@tgross35 tgross35 changed the title Incorrect pthread_t definition on Darwin (should be a raw pointer, not an uintptr_t) Correct the definition of pthread_t on Darwin Aug 10, 2025
Comment on lines +20 to +29
pub struct __darwin_pthread_handler_rec {
__routine: Option<unsafe extern "C" fn(*mut c_void)>,
__arg: *mut c_void,
__next: *mut __darwin_pthread_handler_rec,
}
pub struct _opaque_pthread_t {
__sig: c_long,
__cleanup_stack: *mut __darwin_pthread_handler_rec,
__opaque: [c_char; __PTHREAD_SIZE__],
}
Copy link
Contributor

Choose a reason for hiding this comment

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

One other thing, could you mark these #[non_exhaustive]? Doesn't really matter here since they are all private fields, but we are starting to do that for everything new

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.

Incorrect pthread_t definition on Darwin (should be a raw pointer, not an uintptr_t)
3 participants