Skip to content

Commit

Permalink
MacOS: move ifconf to s_no_extra_traits
Browse files Browse the repository at this point in the history
The derived implementations were causing a CI failure that didn't show
up before. Manually implement `PartialEq` and `Debug` to work around
this.
  • Loading branch information
tgross35 committed Nov 16, 2024
1 parent a4b5bf8 commit 6093ce0
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,15 +1143,6 @@ s! {
pub nativeattr: attribute_set_t,
}

#[cfg_attr(libc_packedN, repr(packed(4)))]
pub struct ifconf {
pub ifc_len: ::c_int,
#[cfg(libc_union)]
pub ifc_ifcu: __c_anonymous_ifc_ifcu,
#[cfg(not(libc_union))]
pub ifc_ifcu: *mut ifreq,
}

#[cfg_attr(libc_align, repr(align(8)))]
pub struct tcp_connection_info {
pub tcpi_state: u8,
Expand Down Expand Up @@ -1202,6 +1193,15 @@ s! {
}

s_no_extra_traits! {
#[cfg_attr(libc_packedN, repr(packed(4)))]
pub struct ifconf {
pub ifc_len: ::c_int,
#[cfg(libc_union)]
pub ifc_ifcu: __c_anonymous_ifc_ifcu,
#[cfg(not(libc_union))]
pub ifc_ifcu: *mut ifreq,
}

#[cfg_attr(libc_packedN, repr(packed(4)))]
pub struct kevent {
pub ident: ::uintptr_t,
Expand Down Expand Up @@ -1617,6 +1617,32 @@ cfg_if! {

cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for ifconf
where
Self: Copy
{
fn eq(&self, other: &Self) -> bool {
let len_ptr1 = core::ptr::addr_of!(self.ifc_len);
let len_ptr2 = core::ptr::addr_of!(other.ifc_len);
let ifcu_ptr1 = core::ptr::addr_of!(self.ifc_ifcu);
let ifcu_ptr2 = core::ptr::addr_of!(other.ifc_ifcu);

// SAFETY: `ifconf` implements `Copy` so the reads are valid
let len1 = unsafe { len_ptr1.read_unaligned() };
let len2 = unsafe { len_ptr2.read_unaligned() };
let ifcu1 = unsafe { ifcu_ptr1.read_unaligned() };
let ifcu2 = unsafe { ifcu_ptr2.read_unaligned() };

len1 == len2 && ifcu1 == ifcu2
}
}
impl Eq for ifconf {}
impl ::fmt::Debug for ifconf {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("ifconf").finish_non_exhaustive()
}
}

impl PartialEq for kevent {
fn eq(&self, other: &kevent) -> bool {
self.ident == other.ident
Expand All @@ -1627,6 +1653,7 @@ cfg_if! {
&& self.udata == other.udata
}
}

impl Eq for kevent {}
impl ::fmt::Debug for kevent {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
Expand Down

0 comments on commit 6093ce0

Please sign in to comment.