Skip to content

Commit 81e2b6c

Browse files
committed
Implement epoll_data union
1 parent 10ff5d4 commit 81e2b6c

File tree

4 files changed

+69
-25
lines changed

4 files changed

+69
-25
lines changed

libc-test/build.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,6 @@ fn test_solarish(target: &str) {
906906

907907
cfg.field_name(move |struct_, field| {
908908
match struct_ {
909-
// rust struct uses raw u64, rather than union
910-
"epoll_event" if field == "u64" => "data.u64".to_string(),
911909
// rust struct was committed with typo for Solaris
912910
"door_arg_t" if field == "dec_num" => "desc_num".to_string(),
913911
"stat" if field.ends_with("_nsec") => {
@@ -1176,7 +1174,6 @@ fn test_netbsd(target: &str) {
11761174
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
11771175
s.replace("e_nsec", ".tv_nsec")
11781176
}
1179-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
11801177
s => s.to_string(),
11811178
}
11821179
});
@@ -1386,7 +1383,6 @@ fn test_dragonflybsd(target: &str) {
13861383
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
13871384
s.replace("e_nsec", ".tv_nsec")
13881385
}
1389-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
13901386
// Field is named `type` in C but that is a Rust keyword,
13911387
// so these fields are translated to `type_` in the bindings.
13921388
"type_" if struct_ == "rtprio" => "type".to_string(),
@@ -1766,8 +1762,6 @@ fn test_android(target: &str) {
17661762
// Our stat *_nsec fields normally don't actually exist but are part
17671763
// of a timeval struct
17681764
s if s.ends_with("_nsec") && struct_.starts_with("stat") => s.to_string(),
1769-
// FIXME: appears that `epoll_event.data` is an union
1770-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
17711765
// The following structs have a field called `type` in C,
17721766
// but `type` is a Rust keyword, so these fields are translated
17731767
// to `type_` in Rust.
@@ -2848,8 +2842,6 @@ fn test_emscripten(target: &str) {
28482842
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
28492843
s.replace("e_nsec", ".tv_nsec")
28502844
}
2851-
// Rust struct uses raw u64, rather than union
2852-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
28532845
s => s.to_string(),
28542846
}
28552847
});
@@ -3585,10 +3577,6 @@ fn test_linux(target: &str) {
35853577
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
35863578
s.replace("e_nsec", ".tv_nsec")
35873579
}
3588-
// FIXME(linux): epoll_event.data is actually a union in C, but in Rust
3589-
// it is only a u64 because we only expose one field
3590-
// http://man7.org/linux/man-pages/man2/epoll_wait.2.html
3591-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
35923580
// The following structs have a field called `type` in C,
35933581
// but `type` is a Rust keyword, so these fields are translated
35943582
// to `type_` in Rust.

src/fuchsia/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,13 @@ s! {
419419

420420
pub struct epoll_event {
421421
pub events: u32,
422+
pub data: epoll_data,
423+
}
424+
425+
pub union epoll_data {
426+
pub ptr: *mut c_void,
427+
pub fd: c_int,
428+
pub u32: u32,
422429
pub u64: u64,
423430
}
424431

src/unix/linux_like/mod.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@ s_no_extra_traits! {
265265
)]
266266
pub struct epoll_event {
267267
pub events: u32,
268+
pub data: epoll_data,
269+
}
270+
271+
pub union epoll_data {
272+
pub ptr: *mut c_void,
273+
pub fd: c_int,
274+
pub u32: u32,
268275
pub u64: u64,
269276
}
270277

@@ -314,26 +321,28 @@ cfg_if! {
314321
if #[cfg(feature = "extra_traits")] {
315322
impl PartialEq for epoll_event {
316323
fn eq(&self, other: &epoll_event) -> bool {
317-
self.events == other.events && self.u64 == other.u64
324+
unimplemented!("traits")
318325
}
319326
}
320327
impl Eq for epoll_event {}
321-
impl fmt::Debug for epoll_event {
322-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
323-
let events = self.events;
324-
let u64 = self.u64;
325-
f.debug_struct("epoll_event")
326-
.field("events", &events)
327-
.field("u64", &u64)
328-
.finish()
329-
}
330-
}
331328
impl hash::Hash for epoll_event {
332329
fn hash<H: hash::Hasher>(&self, state: &mut H) {
333330
let events = self.events;
334-
let u64 = self.u64;
331+
let data = self.data;
335332
events.hash(state);
336-
u64.hash(state);
333+
data.hash(state);
334+
}
335+
}
336+
337+
impl PartialEq for epoll_data {
338+
fn eq(&self, other: &epoll_data) -> bool {
339+
unimplemented!("traits")
340+
}
341+
}
342+
impl Eq for epoll_data {}
343+
impl hash::Hash for epoll_data {
344+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
345+
unimplemented!("traits")
337346
}
338347
}
339348

src/unix/solarish/mod.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,22 @@ s! {
501501
}
502502

503503
s_no_extra_traits! {
504+
#[cfg_attr(any(
505+
target_arch = "x86", target_arch = "x86_64"),
506+
repr(packed(4))
507+
)]
508+
pub struct epoll_event {
509+
pub events: u32,
510+
pub data: epoll_data,
511+
}
512+
513+
pub union epoll_data {
514+
pub ptr: *mut c_void,
515+
pub fd: c_int,
516+
pub u32: u32,
517+
pub u64: u64,
518+
}
519+
504520
pub struct sockaddr_un {
505521
pub sun_family: sa_family_t,
506522
pub sun_path: [c_char; 108],
@@ -573,6 +589,30 @@ s_no_extra_traits! {
573589

574590
cfg_if! {
575591
if #[cfg(feature = "extra_traits")] {
592+
impl PartialEq for epoll_event {
593+
fn eq(&self, other: &epoll_event) -> bool {
594+
unimplemented!("traits")
595+
}
596+
}
597+
impl Eq for epoll_event {}
598+
impl hash::Hash for epoll_event {
599+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
600+
unimplemented!("traits")
601+
}
602+
}
603+
604+
impl PartialEq for epoll_data {
605+
fn eq(&self, other: &epoll_data) -> bool {
606+
unimplemented!("traits")
607+
}
608+
}
609+
impl Eq for epoll_data {}
610+
impl hash::Hash for epoll_data {
611+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
612+
unimplemented!("traits")
613+
}
614+
}
615+
576616
impl PartialEq for sockaddr_un {
577617
fn eq(&self, other: &sockaddr_un) -> bool {
578618
self.sun_family == other.sun_family

0 commit comments

Comments
 (0)