Skip to content

Commit c65f640

Browse files
committed
Implement epoll_data union
1 parent efb9ed7 commit c65f640

File tree

4 files changed

+69
-18
lines changed

4 files changed

+69
-18
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: 25 additions & 6 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

@@ -341,17 +348,29 @@ s_no_extra_traits! {
341348
cfg_if! {
342349
if #[cfg(feature = "extra_traits")] {
343350
impl PartialEq for epoll_event {
344-
fn eq(&self, other: &epoll_event) -> bool {
345-
self.events == other.events && self.u64 == other.u64
351+
fn eq(&self, _other: &epoll_event) -> bool {
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

@@ -441,13 +460,13 @@ cfg_if! {
441460
}
442461

443462
impl PartialEq for __c_anonymous_ifa_ifu {
444-
fn eq(&self, other: &__c_anonymous_ifa_ifu) -> bool {
463+
fn eq(&self, _other: &__c_anonymous_ifa_ifu) -> bool {
445464
unimplemented!("traits")
446465
}
447466
}
448467
impl Eq for __c_anonymous_ifa_ifu {}
449468
impl hash::Hash for __c_anonymous_ifa_ifu {
450-
fn hash<H: hash::Hasher>(&self, state: &mut H) {
469+
fn hash<H: hash::Hasher>(&self, _state: &mut H) {
451470
unimplemented!("traits")
452471
}
453472
}

src/unix/solarish/mod.rs

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

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

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

0 commit comments

Comments
 (0)