jhpratt / num_threads

Obtain the number of threads in the current process
https://docs.rs/num_threads
Apache License 2.0
12 stars 7 forks source link

Rewrite MacOS implementation to use public APIs only #6

Closed complexspaces closed 2 years ago

complexspaces commented 2 years ago

Hello,

While updating crates for a project, I noticed that time >= 0.3.6 began to depend on this crate. After reviewing what it was, I found that the APIs currently used on main are problematic for any consumers who ship Rust code in apps distributed via Apple's stores.

proc_pidinfo is what Apple considers a "private API" (see the top of its header location), which means that if they detect a library linking to or referencing the symbols during review, they will reject the upload. The sysinfo crate had a similar issue before.

This PR replaces the use of proc_pidinfo with public Mach APIs instead. mach_task_self and task_threads are both referenced in Apple's public facing documentation and kernel headers.

jhpratt commented 2 years ago

Rebased on a new commit that introduces tests to ensure things actually work as expected. Looks like this does. Thank you!