Skip to content

Commit 15d0d58

Browse files
committed
Implement epoll_data union
1 parent 9775467 commit 15d0d58

File tree

4 files changed

+71
-20
lines changed

4 files changed

+71
-20
lines changed

libc-test/build.rs

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

857857
cfg.field_name(move |struct_, field| {
858858
match struct_ {
859-
// rust struct uses raw u64, rather than union
860-
"epoll_event" if field == "u64" => "data.u64".to_string(),
861859
// rust struct was committed with typo for Solaris
862860
"door_arg_t" if field == "dec_num" => "desc_num".to_string(),
863861
"stat" if field.ends_with("_nsec") => {
@@ -1114,7 +1112,6 @@ fn test_netbsd(target: &str) {
11141112
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
11151113
s.replace("e_nsec", ".tv_nsec")
11161114
}
1117-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
11181115
s => s.to_string(),
11191116
}
11201117
});
@@ -1323,7 +1320,6 @@ fn test_dragonflybsd(target: &str) {
13231320
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
13241321
s.replace("e_nsec", ".tv_nsec")
13251322
}
1326-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
13271323
// Field is named `type` in C but that is a Rust keyword,
13281324
// so these fields are translated to `type_` in the bindings.
13291325
"type_" if struct_ == "rtprio" => "type".to_string(),
@@ -1684,8 +1680,6 @@ fn test_android(target: &str) {
16841680
// Our stat *_nsec fields normally don't actually exist but are part
16851681
// of a timeval struct
16861682
s if s.ends_with("_nsec") && struct_.starts_with("stat") => s.to_string(),
1687-
// FIXME: appears that `epoll_event.data` is an union
1688-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
16891683
// The following structs have a field called `type` in C,
16901684
// but `type` is a Rust keyword, so these fields are translated
16911685
// to `type_` in Rust.
@@ -2756,8 +2750,6 @@ fn test_emscripten(target: &str) {
27562750
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
27572751
s.replace("e_nsec", ".tv_nsec")
27582752
}
2759-
// FIXME: appears that `epoll_event.data` is an union
2760-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
27612753
s => s.to_string(),
27622754
}
27632755
});
@@ -3508,10 +3500,6 @@ fn test_linux(target: &str) {
35083500
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
35093501
s.replace("e_nsec", ".tv_nsec")
35103502
}
3511-
// FIXME: epoll_event.data is actually a union in C, but in Rust
3512-
// it is only a u64 because we only expose one field
3513-
// http://man7.org/linux/man-pages/man2/epoll_wait.2.html
3514-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
35153503
// The following structs have a field called `type` in C,
35163504
// but `type` is a Rust keyword, so these fields are translated
35173505
// to `type_` in Rust.

src/fuchsia/mod.rs

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

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

src/unix/linux_like/mod.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ s_no_extra_traits! {
217217
repr(packed))]
218218
pub struct epoll_event {
219219
pub events: u32,
220+
pub data: epoll_data,
221+
}
222+
223+
pub union epoll_data {
224+
pub ptr: *mut ::c_void,
225+
pub fd: ::c_int,
226+
pub u32: u32,
220227
pub u64: u64,
221228
}
222229

@@ -267,25 +274,46 @@ cfg_if! {
267274
impl PartialEq for epoll_event {
268275
fn eq(&self, other: &epoll_event) -> bool {
269276
self.events == other.events
270-
&& self.u64 == other.u64
277+
&& unsafe { self.data.u64 == other.data.u64 }
271278
}
272279
}
273280
impl Eq for epoll_event {}
274281
impl ::fmt::Debug for epoll_event {
275282
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
276283
let events = self.events;
277-
let u64 = self.u64;
284+
let data = self.data;
278285
f.debug_struct("epoll_event")
279286
.field("events", &events)
280-
.field("u64", &u64)
287+
.field("data", &data)
281288
.finish()
282289
}
283290
}
284291
impl ::hash::Hash for epoll_event {
285292
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
286293
let events = self.events;
287-
let u64 = self.u64;
294+
let data = self.data;
288295
events.hash(state);
296+
data.hash(state);
297+
}
298+
}
299+
300+
impl PartialEq for epoll_data {
301+
fn eq(&self, other: &epoll_data) -> bool {
302+
unsafe { self.u64 == other.u64 }
303+
}
304+
}
305+
impl Eq for epoll_data {}
306+
impl ::fmt::Debug for epoll_data {
307+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
308+
let u64 = unsafe { self.u64 };
309+
f.debug_struct("epoll_data")
310+
.field("data", &u64)
311+
.finish()
312+
}
313+
}
314+
impl ::hash::Hash for epoll_data {
315+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
316+
let u64 = unsafe { self.u64 };
289317
u64.hash(state);
290318
}
291319
}

src/unix/solarish/mod.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,13 @@ s_no_extra_traits! {
493493
)]
494494
pub struct epoll_event {
495495
pub events: u32,
496+
pub data: epoll_data,
497+
}
498+
499+
pub union epoll_data {
500+
pub ptr: *mut ::c_void,
501+
pub fd: ::c_int,
502+
pub u32: u32,
496503
pub u64: u64,
497504
}
498505

@@ -641,25 +648,46 @@ cfg_if! {
641648
impl PartialEq for epoll_event {
642649
fn eq(&self, other: &epoll_event) -> bool {
643650
self.events == other.events
644-
&& self.u64 == other.u64
651+
&& unsafe { self.data.u64 == other.data.u64 }
645652
}
646653
}
647654
impl Eq for epoll_event {}
648655
impl ::fmt::Debug for epoll_event {
649656
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
650657
let events = self.events;
651-
let u64 = self.u64;
658+
let data = self.data;
652659
f.debug_struct("epoll_event")
653660
.field("events", &events)
654-
.field("u64", &u64)
661+
.field("data", &data)
655662
.finish()
656663
}
657664
}
658665
impl ::hash::Hash for epoll_event {
659666
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
660667
let events = self.events;
661-
let u64 = self.u64;
668+
let data = self.data;
662669
events.hash(state);
670+
data.hash(state);
671+
}
672+
}
673+
674+
impl PartialEq for epoll_data {
675+
fn eq(&self, other: &epoll_data) -> bool {
676+
unsafe { self.u64 == other.u64 }
677+
}
678+
}
679+
impl Eq for epoll_data {}
680+
impl ::fmt::Debug for epoll_data {
681+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
682+
let u64 = unsafe { self.u64 };
683+
f.debug_struct("epoll_data")
684+
.field("data", &u64)
685+
.finish()
686+
}
687+
}
688+
impl ::hash::Hash for epoll_data {
689+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
690+
let u64 = unsafe { self.u64 };
663691
u64.hash(state);
664692
}
665693
}

0 commit comments

Comments
 (0)