From 5b9605a28b78481311804577f252d6e17f196167 Mon Sep 17 00:00:00 2001 From: Qiu Chaofan Date: Wed, 1 Feb 2023 14:46:04 +0800 Subject: [PATCH] Implement essential traits under extra_traits --- src/unix/aix/mod.rs | 144 ++++++++++++++- src/unix/aix/powerpc64.rs | 376 +++++++++++++++++++++++++++++++++++++- 2 files changed, 507 insertions(+), 13 deletions(-) diff --git a/src/unix/aix/mod.rs b/src/unix/aix/mod.rs index 4a4fbb659cff6..74c608015ef7d 100644 --- a/src/unix/aix/mod.rs +++ b/src/unix/aix/mod.rs @@ -345,21 +345,19 @@ s! { } s_no_extra_traits! { - #[allow(missing_debug_implementations)] #[cfg(libc_union)] pub union __sigaction_sa_union { pub __su_handler: extern fn(c: ::c_int), pub __su_sigaction: extern fn(c: ::c_int, info: *mut siginfo_t, ptr: *mut ::c_void), } - #[allow(missing_debug_implementations)] pub struct sigaction { + #[cfg(libc_union)] pub sa_union: __sigaction_sa_union, pub sa_mask: sigset_t, pub sa_flags: ::c_int, } - #[allow(missing_debug_implementations)] #[cfg(libc_union)] pub union __poll_ctl_ext_u { pub addr: *mut ::c_void, @@ -367,17 +365,155 @@ s_no_extra_traits! { pub data: u64, } - #[allow(missing_debug_implementations)] pub struct poll_ctl_ext { pub version: u8, pub command: u8, pub events: ::c_short, pub fd: ::c_int, + #[cfg(libc_union)] pub u: __poll_ctl_ext_u, pub reversed64: [u64; 6], } } +cfg_if! { + if #[cfg(feature = "extra_traits")] { + #[cfg(libc_union)] + impl PartialEq for __sigaction_sa_union { + fn eq(&self, other: &__sigaction_sa_union) -> bool { + unsafe { + self.__su_handler == other.__su_handler + && self.__su_sigaction == other.__su_sigaction + } + } + } + #[cfg(libc_union)] + impl Eq for __sigaction_sa_union {} + #[cfg(libc_union)] + impl ::fmt::Debug for __sigaction_sa_union { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("__sigaction_sa_union") + .field("__su_handler", unsafe { &self.__su_handler }) + .field("__su_sigaction", unsafe { &self.__su_sigaction }) + .finish() + } + } + #[cfg(libc_union)] + impl ::hash::Hash for __sigaction_sa_union { + fn hash(&self, state: &mut H) { + unsafe { + self.__su_handler.hash(state); + self.__su_sigaction.hash(state); + } + } + } + + impl PartialEq for sigaction { + fn eq(&self, other: &sigaction) -> bool { + #[cfg(libc_union)] + let union_eq = self.sa_union == other.sa_union; + #[cfg(not(libc_union))] + let union_eq = true; + self.sa_mask == other.sa_mask + && self.sa_flags == other.sa_flags + && union_eq + } + } + impl Eq for sigaction {} + impl ::fmt::Debug for sigaction { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let mut struct_formatter = f.debug_struct("sigaction"); + #[cfg(libc_union)] + struct_formatter.field("sa_union", &self.sa_union); + struct_formatter.field("sa_mask", &self.sa_mask); + struct_formatter.field("sa_flags", &self.sa_flags); + struct_formatter.finish() + } + } + impl ::hash::Hash for sigaction { + fn hash(&self, state: &mut H) { + #[cfg(libc_union)] + self.sa_union.hash(state); + self.sa_mask.hash(state); + self.sa_flags.hash(state); + } + } + + #[cfg(libc_union)] + impl PartialEq for __poll_ctl_ext_u { + fn eq(&self, other: &__poll_ctl_ext_u) -> bool { + unsafe { + self.addr == other.addr + && self.data32 == other.data32 + && self.data == other.data + } + } + } + #[cfg(libc_union)] + impl Eq for __poll_ctl_ext_u {} + #[cfg(libc_union)] + impl ::fmt::Debug for __poll_ctl_ext_u { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("__poll_ctl_ext_u") + .field("addr", unsafe { &self.addr }) + .field("data32", unsafe { &self.data32 }) + .field("data", unsafe { &self.data }) + .finish() + } + } + #[cfg(libc_union)] + impl ::hash::Hash for __poll_ctl_ext_u { + fn hash(&self, state: &mut H) { + unsafe { + self.addr.hash(state); + self.data32.hash(state); + self.data.hash(state); + } + } + } + + impl PartialEq for poll_ctl_ext { + fn eq(&self, other: &poll_ctl_ext) -> bool { + #[cfg(libc_union)] + let union_eq = self.u == other.u; + #[cfg(not(libc_union))] + let union_eq = true; + self.version == other.version + && self.command == other.command + && self.events == other.events + && self.fd == other.fd + && self.reversed64 == other.reversed64 + && union_eq + } + } + impl Eq for poll_ctl_ext {} + impl ::fmt::Debug for poll_ctl_ext { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let mut struct_formatter = f.debug_struct("poll_ctl_ext"); + struct_formatter.field("version", &self.version); + struct_formatter.field("command", &self.command); + struct_formatter.field("events", &self.events); + struct_formatter.field("fd", &self.fd); + #[cfg(libc_union)] + struct_formatter.field("u", &self.u); + struct_formatter.field("reversed64", &self.reversed64); + struct_formatter.finish() + } + } + impl ::hash::Hash for poll_ctl_ext { + fn hash(&self, state: &mut H) { + self.version.hash(state); + self.command.hash(state); + self.events.hash(state); + self.fd.hash(state); + #[cfg(libc_union)] + self.u.hash(state); + self.reversed64.hash(state); + } + } + } +} + // dlfcn.h pub const RTLD_LAZY: ::c_int = 0x4; pub const RTLD_NOW: ::c_int = 0x2; diff --git a/src/unix/aix/powerpc64.rs b/src/unix/aix/powerpc64.rs index a27be62d39449..1f96ae37ad850 100644 --- a/src/unix/aix/powerpc64.rs +++ b/src/unix/aix/powerpc64.rs @@ -96,14 +96,12 @@ s! { } s_no_extra_traits! { - #[allow(missing_debug_implementations)] #[cfg(libc_union)] pub union sigval { pub sival_ptr: *mut ::c_void, pub sival_int: ::c_int, } - #[allow(missing_debug_implementations)] pub struct siginfo_t { pub si_signo: ::c_int, pub si_errno: ::c_int, @@ -113,12 +111,12 @@ s_no_extra_traits! { pub si_status: ::c_int, pub si_addr: *mut ::c_void, pub si_band: ::c_long, + #[cfg(libc_union)] pub si_value: sigval, pub __si_flags: ::c_int, pub __pad: [::c_int; 3], } - #[allow(missing_debug_implementations)] #[cfg(libc_union)] pub union _kernel_simple_lock { pub _slock: ::c_long, @@ -126,7 +124,6 @@ s_no_extra_traits! { pub _slockp: *mut ::c_void, } - #[allow(missing_debug_implementations)] pub struct fileops_t { pub fo_rw: extern fn(file: *mut file, rw: ::uio_rw, io: *mut ::c_void, ext: ::c_long, secattr: *mut ::c_void) -> ::c_int, @@ -138,7 +135,6 @@ s_no_extra_traits! { pub fo_fstat: extern fn(file: *mut file, sstat: *mut ::stat) -> ::c_int, } - #[allow(missing_debug_implementations)] pub struct file { pub f_flag: ::c_long, pub f_count: ::c_int, @@ -150,7 +146,9 @@ s_no_extra_traits! { pub f_dir_off: ::c_long, // Should be pointer to 'cred' pub f_cred: *mut ::c_void, + #[cfg(libc_union)] pub f_lock: _kernel_simple_lock, + #[cfg(libc_union)] pub f_offset_lock: _kernel_simple_lock, pub f_vinfo: ::caddr_t, pub f_ops: *mut fileops_t, @@ -159,7 +157,6 @@ s_no_extra_traits! { pub f_fdata: [::c_char; 160], } - #[allow(missing_debug_implementations)] #[cfg(libc_union)] pub union __ld_info_file { pub _ldinfo_fd: ::c_int, @@ -167,10 +164,10 @@ s_no_extra_traits! { pub _core_offset: ::c_long, } - #[allow(missing_debug_implementations)] pub struct ld_info { pub ldinfo_next: ::c_uint, pub ldinfo_flags: ::c_uint, + #[cfg(libc_union)] pub _file: __ld_info_file, pub ldinfo_textorg: *mut ::c_void, pub ldinfo_textsize: ::c_ulong, @@ -179,7 +176,6 @@ s_no_extra_traits! { pub ldinfo_filename: [::c_char; 2], } - #[allow(missing_debug_implementations)] #[cfg(libc_union)] pub union __pollfd_ext_u { pub addr: *mut ::c_void, @@ -187,15 +183,377 @@ s_no_extra_traits! { pub data: u64, } - #[allow(missing_debug_implementations)] pub struct pollfd_ext { pub fd: ::c_int, pub events: ::c_ushort, pub revents: ::c_ushort, + #[cfg(libc_union)] pub data: __pollfd_ext_u, } } +cfg_if! { + if #[cfg(feature = "extra_traits")] { + #[cfg(libc_union)] + impl PartialEq for sigval { + fn eq(&self, other: &sigval) -> bool { + unsafe { + self.sival_ptr == other.sival_ptr + && self.sival_int == other.sival_int + } + } + } + #[cfg(libc_union)] + impl Eq for sigval {} + #[cfg(libc_union)] + impl ::fmt::Debug for sigval { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sigval") + .field("sival_ptr", unsafe { &self.sival_ptr }) + .field("sival_int", unsafe { &self.sival_int }) + .finish() + } + } + #[cfg(libc_union)] + impl ::hash::Hash for sigval { + fn hash(&self, state: &mut H) { + unsafe { + self.sival_ptr.hash(state); + self.sival_int.hash(state); + } + } + } + + impl PartialEq for siginfo_t { + fn eq(&self, other: &siginfo_t) -> bool { + #[cfg(libc_union)] + let value_eq = self.si_value == other.si_value; + #[cfg(not(libc_union))] + let value_eq = true; + self.si_signo == other.si_signo + && self.si_errno == other.si_errno + && self.si_code == other.si_code + && self.si_pid == other.si_pid + && self.si_uid == other.si_uid + && self.si_status == other.si_status + && self.si_addr == other.si_addr + && self.si_band == other.si_band + && self.__si_flags == other.__si_flags + && value_eq + } + } + impl Eq for siginfo_t {} + impl ::fmt::Debug for siginfo_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let mut struct_formatter = f.debug_struct("siginfo_t"); + struct_formatter.field("si_signo", &self.si_signo); + struct_formatter.field("si_errno", &self.si_errno); + struct_formatter.field("si_code", &self.si_code); + struct_formatter.field("si_pid", &self.si_pid); + struct_formatter.field("si_uid", &self.si_uid); + struct_formatter.field("si_status", &self.si_status); + struct_formatter.field("si_addr", &self.si_addr); + struct_formatter.field("si_band", &self.si_band); + #[cfg(libc_union)] + struct_formatter.field("si_value", &self.si_value); + struct_formatter.field("__si_flags", &self.__si_flags); + struct_formatter.finish() + } + } + impl ::hash::Hash for siginfo_t { + fn hash(&self, state: &mut H) { + self.si_signo.hash(state); + self.si_errno.hash(state); + self.si_code.hash(state); + self.si_pid.hash(state); + self.si_uid.hash(state); + self.si_status.hash(state); + self.si_addr.hash(state); + self.si_band.hash(state); + #[cfg(libc_union)] + self.si_value.hash(state); + self.__si_flags.hash(state); + } + } + + #[cfg(libc_union)] + impl PartialEq for _kernel_simple_lock { + fn eq(&self, other: &_kernel_simple_lock) -> bool { + unsafe { + self._slock == other._slock + && self._slockp == other._slockp + } + } + } + #[cfg(libc_union)] + impl Eq for _kernel_simple_lock {} + #[cfg(libc_union)] + impl ::fmt::Debug for _kernel_simple_lock { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sigval") + .field("_slock", unsafe { &self._slock }) + .field("_slockp", unsafe { &self._slockp }) + .finish() + } + } + #[cfg(libc_union)] + impl ::hash::Hash for _kernel_simple_lock { + fn hash(&self, state: &mut H) { + unsafe { + self._slock.hash(state); + self._slockp.hash(state); + } + } + } + + impl PartialEq for fileops_t { + fn eq(&self, other: &fileops_t) -> bool { + self.fo_rw == other.fo_rw + && self.fo_ioctl == other.fo_ioctl + && self.fo_select == other.fo_select + && self.fo_close == other.fo_close + && self.fo_fstat == other.fo_fstat + } + } + impl Eq for fileops_t {} + impl ::fmt::Debug for fileops_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let mut struct_formatter = f.debug_struct("fileops_t"); + struct_formatter.field("fo_rw", &self.fo_rw); + struct_formatter.field("fo_ioctl", &self.fo_ioctl); + struct_formatter.field("fo_select", &self.fo_select); + struct_formatter.field("fo_close", &self.fo_close); + struct_formatter.field("fo_fstat", &self.fo_fstat); + struct_formatter.finish() + } + } + impl ::hash::Hash for fileops_t { + fn hash(&self, state: &mut H) { + self.fo_rw.hash(state); + self.fo_ioctl.hash(state); + self.fo_select.hash(state); + self.fo_close.hash(state); + self.fo_fstat.hash(state); + } + } + + impl PartialEq for file { + fn eq(&self, other: &file) -> bool { + #[cfg(libc_union)] + let lock_eq = self.f_lock == other.f_lock + && self.f_offset_lock == other.f_offset_lock; + #[cfg(not(libc_union))] + let lock_eq = true; + self.f_flag == other.f_flag + && self.f_count == other.f_count + && self.f_options == other.f_options + && self.f_type == other.f_type + && self.f_data == other.f_data + && self.f_offset == other.f_offset + && self.f_dir_off == other.f_dir_off + && self.f_cred == other.f_cred + && self.f_vinfo == other.f_vinfo + && self.f_ops == other.f_ops + && self.f_parentp == other.f_parentp + && self.f_fnamep == other.f_fnamep + && self.f_fdata == other.f_fdata + && lock_eq + } + } + impl Eq for file {} + impl ::fmt::Debug for file { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let mut struct_formatter = f.debug_struct("file"); + struct_formatter.field("f_flag", &self.f_flag); + struct_formatter.field("f_count", &self.f_count); + struct_formatter.field("f_options", &self.f_options); + struct_formatter.field("f_type", &self.f_type); + struct_formatter.field("f_data", &self.f_data); + struct_formatter.field("f_offset", &self.f_offset); + struct_formatter.field("f_dir_off", &self.f_dir_off); + struct_formatter.field("f_cred", &self.f_cred); + #[cfg(libc_union)] + struct_formatter.field("f_lock", &self.f_lock); + #[cfg(libc_union)] + struct_formatter.field("f_offset_lock", &self.f_offset_lock); + struct_formatter.field("f_vinfo", &self.f_vinfo); + struct_formatter.field("f_ops", &self.f_ops); + struct_formatter.field("f_parentp", &self.f_parentp); + struct_formatter.field("f_fnamep", &self.f_fnamep); + struct_formatter.field("f_fdata", &self.f_fdata); + struct_formatter.finish() + } + } + impl ::hash::Hash for file { + fn hash(&self, state: &mut H) { + self.f_flag.hash(state); + self.f_count.hash(state); + self.f_options.hash(state); + self.f_type.hash(state); + self.f_data.hash(state); + self.f_offset.hash(state); + self.f_dir_off.hash(state); + self.f_cred.hash(state); + #[cfg(libc_union)] + self.f_lock.hash(state); + #[cfg(libc_union)] + self.f_offset_lock.hash(state); + self.f_vinfo.hash(state); + self.f_ops.hash(state); + self.f_parentp.hash(state); + self.f_fnamep.hash(state); + self.f_fdata.hash(state); + } + } + + #[cfg(libc_union)] + impl PartialEq for __ld_info_file { + fn eq(&self, other: &__ld_info_file) -> bool { + unsafe { + self._ldinfo_fd == other._ldinfo_fd + && self._ldinfo_fp == other._ldinfo_fp + && self._core_offset == other._core_offset + } + } + } + #[cfg(libc_union)] + impl Eq for __ld_info_file {} + #[cfg(libc_union)] + impl ::fmt::Debug for __ld_info_file { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("__ld_info_file") + .field("_ldinfo_fd", unsafe { &self._ldinfo_fd }) + .field("_ldinfo_fp", unsafe { &self._ldinfo_fp }) + .field("_core_offset", unsafe { &self._core_offset }) + .finish() + } + } + #[cfg(libc_union)] + impl ::hash::Hash for __ld_info_file { + fn hash(&self, state: &mut H) { + unsafe { + self._ldinfo_fd.hash(state); + self._ldinfo_fp.hash(state); + self._core_offset.hash(state); + } + } + } + + impl PartialEq for ld_info { + fn eq(&self, other: &ld_info) -> bool { + #[cfg(libc_union)] + let file_eq = self._file == other._file; + #[cfg(not(libc_union))] + let file_eq = true; + self.ldinfo_next == other.ldinfo_next + && self.ldinfo_flags == other.ldinfo_flags + && self.ldinfo_textorg == other.ldinfo_textorg + && self.ldinfo_textsize == other.ldinfo_textsize + && self.ldinfo_dataorg == other.ldinfo_dataorg + && self.ldinfo_datasize == other.ldinfo_datasize + && self.ldinfo_filename == other.ldinfo_filename + && file_eq + } + } + impl Eq for ld_info {} + impl ::fmt::Debug for ld_info { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let mut struct_formatter = f.debug_struct("ld_info"); + struct_formatter.field("ldinfo_next", &self.ldinfo_next); + struct_formatter.field("ldinfo_flags", &self.ldinfo_flags); + struct_formatter.field("ldinfo_textorg", &self.ldinfo_textorg); + struct_formatter.field("ldinfo_textsize", &self.ldinfo_textsize); + struct_formatter.field("ldinfo_dataorg", &self.ldinfo_dataorg); + struct_formatter.field("ldinfo_datasize", &self.ldinfo_datasize); + struct_formatter.field("ldinfo_filename", &self.ldinfo_filename); + #[cfg(libc_union)] + struct_formatter.field("_file", &self._file); + struct_formatter.finish() + } + } + impl ::hash::Hash for ld_info { + fn hash(&self, state: &mut H) { + self.ldinfo_next.hash(state); + self.ldinfo_flags.hash(state); + self.ldinfo_textorg.hash(state); + self.ldinfo_textsize.hash(state); + self.ldinfo_dataorg.hash(state); + self.ldinfo_datasize.hash(state); + self.ldinfo_filename.hash(state); + #[cfg(libc_union)] + self._file.hash(state); + } + } + + #[cfg(libc_union)] + impl PartialEq for __pollfd_ext_u { + fn eq(&self, other: &__pollfd_ext_u) -> bool { + unsafe { + self.addr == other.addr + && self.data32 == other.data32 + && self.data == other.data + } + } + } + #[cfg(libc_union)] + impl Eq for __pollfd_ext_u {} + #[cfg(libc_union)] + impl ::fmt::Debug for __pollfd_ext_u { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("__pollfd_ext_u") + .field("addr", unsafe { &self.addr }) + .field("data32", unsafe { &self.data32 }) + .field("data", unsafe { &self.data }) + .finish() + } + } + #[cfg(libc_union)] + impl ::hash::Hash for __pollfd_ext_u { + fn hash(&self, state: &mut H) { + unsafe { + self.addr.hash(state); + self.data.hash(state); + self.data32.hash(state); + } + } + } + + impl PartialEq for pollfd_ext { + fn eq(&self, other: &pollfd_ext) -> bool { + #[cfg(libc_union)] + let data_eq = self.data == other.data; + #[cfg(not(libc_union))] + let data_eq = true; + self.fd == other.fd + && self.events == other.events + && self.revents == other.revents + && data_eq + } + } + impl Eq for pollfd_ext {} + impl ::fmt::Debug for pollfd_ext { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + let mut struct_formatter = f.debug_struct("pollfd_ext"); + struct_formatter.field("fd", &self.fd); + struct_formatter.field("events", &self.events); + struct_formatter.field("revents", &self.revents); + #[cfg(libc_union)] + struct_formatter.field("data", &self.data); + struct_formatter.finish() + } + } + impl ::hash::Hash for pollfd_ext { + fn hash(&self, state: &mut H) { + self.fd.hash(state); + self.events.hash(state); + self.revents.hash(state); + #[cfg(libc_union)] + self.data.hash(state); + } + } + } +} + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { __mt_word: [0, 2, 0, 0, 0, 0, 0, 0], };