Skip to content

Commit 7173d20

Browse files
committed
Implement epoll_data union
1 parent 50c3958 commit 7173d20

File tree

4 files changed

+69
-15
lines changed

4 files changed

+69
-15
lines changed

libc-test/build.rs

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

11021102
cfg.field_name(move |struct_, field| {
11031103
match struct_ {
1104-
// rust struct uses raw u64, rather than union
1105-
"epoll_event" if field == "u64" => "data.u64".to_string(),
11061104
// rust struct was committed with typo for Solaris
11071105
"door_arg_t" if field == "dec_num" => "desc_num".to_string(),
11081106
"stat" if field.ends_with("_nsec") => {
@@ -1375,7 +1373,6 @@ fn test_netbsd(target: &str) {
13751373
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
13761374
s.replace("e_nsec", ".tv_nsec")
13771375
}
1378-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
13791376
s => s.to_string(),
13801377
}
13811378
});
@@ -1586,7 +1583,6 @@ fn test_dragonflybsd(target: &str) {
15861583
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
15871584
s.replace("e_nsec", ".tv_nsec")
15881585
}
1589-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
15901586
// Field is named `type` in C but that is a Rust keyword,
15911587
// so these fields are translated to `type_` in the bindings.
15921588
"type_" if struct_ == "rtprio" => "type".to_string(),
@@ -1968,8 +1964,6 @@ fn test_android(target: &str) {
19681964
// Our stat *_nsec fields normally don't actually exist but are part
19691965
// of a timeval struct
19701966
s if s.ends_with("_nsec") && struct_.starts_with("stat") => s.to_string(),
1971-
// FIXME(union): appears that `epoll_event.data` is an union
1972-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
19731967
// The following structs have a field called `type` in C,
19741968
// but `type` is a Rust keyword, so these fields are translated
19751969
// to `type_` in Rust.
@@ -3066,8 +3060,6 @@ fn test_emscripten(target: &str) {
30663060
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
30673061
s.replace("e_nsec", ".tv_nsec")
30683062
}
3069-
// Rust struct uses raw u64, rather than union
3070-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
30713063
s => s.to_string(),
30723064
}
30733065
});
@@ -3872,10 +3864,6 @@ fn test_linux(target: &str) {
38723864
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
38733865
s.replace("e_nsec", ".tv_nsec")
38743866
}
3875-
// FIXME(linux): epoll_event.data is actually a union in C, but in Rust
3876-
// it is only a u64 because we only expose one field
3877-
// http://man7.org/linux/man-pages/man2/epoll_wait.2.html
3878-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
38793867
// The following structs have a field called `type` in C,
38803868
// but `type` is a Rust keyword, so these fields are translated
38813869
// to `type_` in Rust.

src/fuchsia/mod.rs

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

409409
pub struct epoll_event {
410410
pub events: u32,
411+
pub data: epoll_data,
412+
}
413+
414+
pub union epoll_data {
415+
pub ptr: *mut c_void,
416+
pub fd: c_int,
417+
pub u32: u32,
411418
pub u64: u64,
412419
}
413420

src/unix/linux_like/mod.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ s_no_extra_traits! {
293293
)]
294294
pub struct epoll_event {
295295
pub events: u32,
296+
pub data: epoll_data,
297+
}
298+
299+
pub union epoll_data {
300+
pub ptr: *mut c_void,
301+
pub fd: c_int,
302+
pub u32: u32,
296303
pub u64: u64,
297304
}
298305

@@ -342,16 +349,28 @@ cfg_if! {
342349
if #[cfg(feature = "extra_traits")] {
343350
impl PartialEq for epoll_event {
344351
fn eq(&self, other: &epoll_event) -> bool {
345-
self.events == other.events && self.u64 == other.u64
352+
unimplemented!("traits")
346353
}
347354
}
348355
impl Eq for epoll_event {}
349356
impl hash::Hash for epoll_event {
350357
fn hash<H: hash::Hasher>(&self, state: &mut H) {
351358
let events = self.events;
352-
let u64 = self.u64;
359+
let data = self.data;
353360
events.hash(state);
354-
u64.hash(state);
361+
data.hash(state);
362+
}
363+
}
364+
365+
impl PartialEq for epoll_data {
366+
fn eq(&self, other: &epoll_data) -> bool {
367+
unimplemented!("traits")
368+
}
369+
}
370+
impl Eq for epoll_data {}
371+
impl hash::Hash for epoll_data {
372+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
373+
unimplemented!("traits")
355374
}
356375
}
357376

src/unix/solarish/mod.rs

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

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

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

0 commit comments

Comments
 (0)