Skip to content

Commit d96d311

Browse files
committed
Implement epoll_data union
1 parent d3e4ca8 commit d96d311

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

libc-test/build.rs

-12
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,6 @@ fn test_solarish(target: &str) {
874874

875875
cfg.field_name(move |struct_, field| {
876876
match struct_ {
877-
// rust struct uses raw u64, rather than union
878-
"epoll_event" if field == "u64" => "data.u64".to_string(),
879877
// rust struct was committed with typo for Solaris
880878
"door_arg_t" if field == "dec_num" => "desc_num".to_string(),
881879
"stat" if field.ends_with("_nsec") => {
@@ -1144,7 +1142,6 @@ fn test_netbsd(target: &str) {
11441142
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
11451143
s.replace("e_nsec", ".tv_nsec")
11461144
}
1147-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
11481145
s => s.to_string(),
11491146
}
11501147
});
@@ -1354,7 +1351,6 @@ fn test_dragonflybsd(target: &str) {
13541351
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
13551352
s.replace("e_nsec", ".tv_nsec")
13561353
}
1357-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
13581354
// Field is named `type` in C but that is a Rust keyword,
13591355
// so these fields are translated to `type_` in the bindings.
13601356
"type_" if struct_ == "rtprio" => "type".to_string(),
@@ -1735,8 +1731,6 @@ fn test_android(target: &str) {
17351731
// Our stat *_nsec fields normally don't actually exist but are part
17361732
// of a timeval struct
17371733
s if s.ends_with("_nsec") && struct_.starts_with("stat") => s.to_string(),
1738-
// FIXME: appears that `epoll_event.data` is an union
1739-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
17401734
// The following structs have a field called `type` in C,
17411735
// but `type` is a Rust keyword, so these fields are translated
17421736
// to `type_` in Rust.
@@ -2813,8 +2807,6 @@ fn test_emscripten(target: &str) {
28132807
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
28142808
s.replace("e_nsec", ".tv_nsec")
28152809
}
2816-
// Rust struct uses raw u64, rather than union
2817-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
28182810
s => s.to_string(),
28192811
}
28202812
});
@@ -3555,10 +3547,6 @@ fn test_linux(target: &str) {
35553547
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
35563548
s.replace("e_nsec", ".tv_nsec")
35573549
}
3558-
// FIXME: epoll_event.data is actually a union in C, but in Rust
3559-
// it is only a u64 because we only expose one field
3560-
// http://man7.org/linux/man-pages/man2/epoll_wait.2.html
3561-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
35623550
// The following structs have a field called `type` in C,
35633551
// but `type` is a Rust keyword, so these fields are translated
35643552
// to `type_` in Rust.

src/fuchsia/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,13 @@ s! {
411411

412412
pub struct epoll_event {
413413
pub events: u32,
414+
pub data: epoll_data,
415+
}
416+
417+
pub union epoll_data {
418+
pub ptr: *mut ::c_void,
419+
pub fd: ::c_int,
420+
pub u32: u32,
414421
pub u64: u64,
415422
}
416423

src/unix/linux_like/mod.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ s_no_extra_traits! {
219219
)]
220220
pub struct epoll_event {
221221
pub events: u32,
222+
pub data: epoll_data,
223+
}
224+
225+
pub union epoll_data {
226+
pub ptr: *mut ::c_void,
227+
pub fd: ::c_int,
228+
pub u32: u32,
222229
pub u64: u64,
223230
}
224231

@@ -266,28 +273,20 @@ s_no_extra_traits! {
266273

267274
cfg_if! {
268275
if #[cfg(feature = "extra_traits")] {
269-
impl PartialEq for epoll_event {
270-
fn eq(&self, other: &epoll_event) -> bool {
271-
self.events == other.events && self.u64 == other.u64
272-
}
273-
}
274-
impl Eq for epoll_event {}
275276
impl ::fmt::Debug for epoll_event {
276277
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
277278
let events = self.events;
278-
let u64 = self.u64;
279+
let data = self.data;
279280
f.debug_struct("epoll_event")
280281
.field("events", &events)
281-
.field("u64", &u64)
282+
.field("data", &data)
282283
.finish()
283284
}
284285
}
285-
impl ::hash::Hash for epoll_event {
286-
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
287-
let events = self.events;
288-
let u64 = self.u64;
289-
events.hash(state);
290-
u64.hash(state);
286+
287+
impl ::fmt::Debug for epoll_data {
288+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
289+
f.debug_struct("epoll_data").finish_non_exhaustive()
291290
}
292291
}
293292

0 commit comments

Comments
 (0)