Open thomcc opened 2 years ago
Hmm. Making this code incompatible in a new version of libc is actually probably fine? This was part of the reason that these modules were deprecated and the libc crate was made to replace it. Old code that uses a prior version of libc will not be broken if we do this on the 0.3 bump. It will become incompatible with the deprecated std::os::raw
definition, but... what else is new? That's been a problem for all FFI typedefs, and I don't believe std's ancient mistake is warranted as a blocking reason for fixing the bindings in the crate that was specifically made so that Rust could fix those bindings going forward.
This is a bug, but not one we can probably fix without breaking too much (it would break
std
's reexport ofpthread_t
). Aside from breaking code that treats it directly as an integer, it would meanpthread_t
would suddenly become!Send
and!Sync
, and I wouldn't be surprised if that's a problem for some.Anyway, on Darwin-based OSes,
pthread_t
should be a pointer, but is instead an integer. I noticed this when trying to passptr::null_mut()
into a function that Apple documents as having special behavior when passed aNULL
forpthread_t
.However, it's worth noting that the structure it points to is not opaque (at least not fully), and low level code on Darwin could potentially need to access it (at the moment this is likely not possible to do correctly on stable Rust, due to the lack of stable
"C-unwind"
). Specifically it has a list of functions that may be manipulated by code that wants to have cleanup functions run on thread cancellation. This list is directly manipulated by thepthread_cleanup_push
andpthread_cleanup_pop
function-style C macros, but this would be done directly by Rust code, which cannot use such macros. This is pretty niche, but is a case that's slightly relevant to https://github.com/rust-lang/rust/issues/95496.The correct definition on Darwin would look more like:
I suppose it's fine for code that cares about this to maintain its own bindings, though.