Skip to content

Commit

Permalink
Auto merge of #1271 - Susurrus:more_debug_impls, r=gnzlbg
Browse files Browse the repository at this point in the history
Implement more extra_traits

Finishing the implementation of rust-lang/rust#57715 now that all platforms are tested in CI. I plan to expand this CI to all platforms that need this treatment (solarish, empscripten, freebsd, and netbsd), but thought I'd get the part I've already started running in CI since I can't test this changes locally.
  • Loading branch information
bors committed Feb 24, 2019
2 parents 2ea7206 + d795b07 commit 66f00d2
Show file tree
Hide file tree
Showing 16 changed files with 1,906 additions and 57 deletions.
73 changes: 70 additions & 3 deletions src/fuchsia/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ macro_rules! expand_align {
}

s_no_extra_traits! {
#[allow(missing_debug_implementations)]
#[cfg_attr(all(target_pointer_width = "32",
any(target_arch = "arm",
target_arch = "x86_64")),
Expand All @@ -45,7 +44,6 @@ macro_rules! expand_align {
size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T],
}

#[allow(missing_debug_implementations)]
#[cfg_attr(all(target_pointer_width = "32",
any(target_arch = "arm",
target_arch = "x86_64")),
Expand All @@ -58,7 +56,6 @@ macro_rules! expand_align {
size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T],
}

#[allow(missing_debug_implementations)]
#[cfg_attr(target_pointer_width = "32",
repr(align(4)))]
#[cfg_attr(target_pointer_width = "64",
Expand All @@ -71,5 +68,75 @@ macro_rules! expand_align {
size: [u8; ::__SIZEOF_PTHREAD_COND_T],
}
}

cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for pthread_cond_t {
fn eq(&self, other: &pthread_cond_t) -> bool {
self.size
.iter()
.zip(other.size.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_cond_t {}
impl ::fmt::Debug for pthread_cond_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_cond_t")
// FIXME: .field("size", &self.size)
.finish()
}
}
impl ::hash::Hash for pthread_cond_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
}
}

impl PartialEq for pthread_mutex_t {
fn eq(&self, other: &pthread_mutex_t) -> bool {
self.size
.iter()
.zip(other.size.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_mutex_t {}
impl ::fmt::Debug for pthread_mutex_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_mutex_t")
// FIXME: .field("size", &self.size)
.finish()
}
}
impl ::hash::Hash for pthread_mutex_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
}
}

impl PartialEq for pthread_rwlock_t {
fn eq(&self, other: &pthread_rwlock_t) -> bool {
self.size
.iter()
.zip(other.size.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_rwlock_t {}
impl ::fmt::Debug for pthread_rwlock_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_rwlock_t")
// FIXME: .field("size", &self.size)
.finish()
}
}
impl ::hash::Hash for pthread_rwlock_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
}
}
}
}
}
}
247 changes: 241 additions & 6 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,6 @@ s! {
}

s_no_extra_traits! {
#[allow(missing_debug_implementations)]
pub struct sysinfo {
pub uptime: ::c_ulong,
pub loads: [::c_ulong; 3],
Expand All @@ -940,20 +939,17 @@ s_no_extra_traits! {
pub __reserved: [::c_char; 256],
}

#[allow(missing_debug_implementations)]
pub struct sockaddr_un {
pub sun_family: sa_family_t,
pub sun_path: [::c_char; 108]
}

#[allow(missing_debug_implementations)]
pub struct sockaddr_storage {
pub ss_family: sa_family_t,
__ss_align: ::size_t,
__ss_pad2: [u8; 128 - 2 * 8],
}

#[allow(missing_debug_implementations)]
pub struct utsname {
pub sysname: [::c_char; 65],
pub nodename: [::c_char; 65],
Expand All @@ -963,7 +959,6 @@ s_no_extra_traits! {
pub domainname: [::c_char; 65]
}

#[allow(missing_debug_implementations)]
pub struct dirent {
pub d_ino: ::ino_t,
pub d_off: ::off_t,
Expand All @@ -972,7 +967,6 @@ s_no_extra_traits! {
pub d_name: [::c_char; 256],
}

#[allow(missing_debug_implementations)]
pub struct dirent64 {
pub d_ino: ::ino64_t,
pub d_off: ::off64_t,
Expand All @@ -982,6 +976,247 @@ s_no_extra_traits! {
}
}

cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for sysinfo {
fn eq(&self, other: &sysinfo) -> bool {
self.uptime == other.uptime
&& self.loads == other.loads
&& self.totalram == other.totalram
&& self.freeram == other.freeram
&& self.sharedram == other.sharedram
&& self.bufferram == other.bufferram
&& self.totalswap == other.totalswap
&& self.freeswap == other.freeswap
&& self.procs == other.procs
&& self.pad == other.pad
&& self.totalhigh == other.totalhigh
&& self.freehigh == other.freehigh
&& self.mem_unit == other.mem_unit
&& self
.__reserved
.iter()
.zip(other.__reserved.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for sysinfo {}
impl ::fmt::Debug for sysinfo {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("sysinfo")
.field("uptime", &self.uptime)
.field("loads", &self.loads)
.field("totalram", &self.totalram)
.field("freeram", &self.freeram)
.field("sharedram", &self.sharedram)
.field("bufferram", &self.bufferram)
.field("totalswap", &self.totalswap)
.field("freeswap", &self.freeswap)
.field("procs", &self.procs)
.field("pad", &self.pad)
.field("totalhigh", &self.totalhigh)
.field("freehigh", &self.freehigh)
.field("mem_unit", &self.mem_unit)
// FIXME: .field("__reserved", &self.__reserved)
.finish()
}
}
impl ::hash::Hash for sysinfo {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.uptime.hash(state);
self.loads.hash(state);
self.totalram.hash(state);
self.freeram.hash(state);
self.sharedram.hash(state);
self.bufferram.hash(state);
self.totalswap.hash(state);
self.freeswap.hash(state);
self.procs.hash(state);
self.pad.hash(state);
self.totalhigh.hash(state);
self.freehigh.hash(state);
self.mem_unit.hash(state);
self.__reserved.hash(state);
}
}

impl PartialEq for sockaddr_un {
fn eq(&self, other: &sockaddr_un) -> bool {
self.sun_family == other.sun_family
&& self
.sun_path
.iter()
.zip(other.sun_path.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for sockaddr_un {}
impl ::fmt::Debug for sockaddr_un {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("sockaddr_un")
.field("sun_family", &self.sun_family)
// FIXME: .field("sun_path", &self.sun_path)
.finish()
}
}
impl ::hash::Hash for sockaddr_un {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.sun_family.hash(state);
self.sun_path.hash(state);
}
}

impl PartialEq for sockaddr_storage {
fn eq(&self, other: &sockaddr_storage) -> bool {
self.ss_family == other.ss_family
&& self.__ss_align == other.__ss_align
&& self
.__ss_pad2
.iter()
.zip(other.__ss_pad2.iter())
.all(|(a, b)| a == b)
}
}
impl Eq for sockaddr_storage {}
impl ::fmt::Debug for sockaddr_storage {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("sockaddr_storage")
.field("ss_family", &self.ss_family)
.field("__ss_align", &self.__ss_align)
// FIXME: .field("__ss_pad2", &self.__ss_pad2)
.finish()
}
}
impl ::hash::Hash for sockaddr_storage {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.ss_family.hash(state);
self.__ss_align.hash(state);
self.__ss_pad2.hash(state);
}
}

impl PartialEq for utsname {
fn eq(&self, other: &utsname) -> bool {
self.sysname
.iter()
.zip(other.sysname.iter())
.all(|(a,b)| a == b)
&& self
.nodename
.iter()
.zip(other.nodename.iter())
.all(|(a,b)| a == b)
&& self
.release
.iter()
.zip(other.release.iter())
.all(|(a,b)| a == b)
&& self
.version
.iter()
.zip(other.version.iter())
.all(|(a,b)| a == b)
&& self
.machine
.iter()
.zip(other.machine.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for utsname {}
impl ::fmt::Debug for utsname {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("utsname")
// FIXME: .field("sysname", &self.sysname)
// FIXME: .field("nodename", &self.nodename)
// FIXME: .field("release", &self.release)
// FIXME: .field("version", &self.version)
// FIXME: .field("machine", &self.machine)
.finish()
}
}
impl ::hash::Hash for utsname {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.sysname.hash(state);
self.nodename.hash(state);
self.release.hash(state);
self.version.hash(state);
self.machine.hash(state);
}
}

impl PartialEq for dirent {
fn eq(&self, other: &dirent) -> bool {
self.d_ino == other.d_ino
&& self.d_off == other.d_off
&& self.d_reclen == other.d_reclen
&& self.d_type == other.d_type
&& self
.d_name
.iter()
.zip(other.d_name.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for dirent {}
impl ::fmt::Debug for dirent {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("dirent")
.field("d_ino", &self.d_ino)
.field("d_off", &self.d_off)
.field("d_reclen", &self.d_reclen)
.field("d_type", &self.d_type)
// FIXME: .field("d_name", &self.d_name)
.finish()
}
}
impl ::hash::Hash for dirent {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.d_ino.hash(state);
self.d_off.hash(state);
self.d_reclen.hash(state);
self.d_type.hash(state);
self.d_name.hash(state);
}
}

impl PartialEq for dirent64 {
fn eq(&self, other: &dirent64) -> bool {
self.d_ino == other.d_ino
&& self.d_off == other.d_off
&& self.d_reclen == other.d_reclen
&& self.d_type == other.d_type
&& self
.d_name
.iter()
.zip(other.d_name.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for dirent64 {}
impl ::fmt::Debug for dirent64 {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("dirent64")
.field("d_ino", &self.d_ino)
.field("d_off", &self.d_off)
.field("d_reclen", &self.d_reclen)
.field("d_type", &self.d_type)
// FIXME: .field("d_name", &self.d_name)
.finish()
}
}
impl ::hash::Hash for dirent64 {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.d_ino.hash(state);
self.d_off.hash(state);
self.d_reclen.hash(state);
self.d_type.hash(state);
self.d_name.hash(state);
}
}
}
}

// PUB_CONST

pub const INT_MIN: c_int = -2147483648;
Expand Down
Loading

0 comments on commit 66f00d2

Please sign in to comment.