Skip to content

Commit 1d10a3f

Browse files
kelldatgross35
authored andcommitted
Implement epoll_data union
1 parent cbb9b0b commit 1d10a3f

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

libc-test/build.rs

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

10991099
cfg.field_name(move |struct_, field| {
11001100
match struct_ {
1101-
// rust struct uses raw u64, rather than union
1102-
"epoll_event" if field == "u64" => "data.u64".to_string(),
11031101
// rust struct was committed with typo for Solaris
11041102
"door_arg_t" if field == "dec_num" => "desc_num".to_string(),
11051103
"stat" if field.ends_with("_nsec") => {
@@ -1372,7 +1370,6 @@ fn test_netbsd(target: &str) {
13721370
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
13731371
s.replace("e_nsec", ".tv_nsec")
13741372
}
1375-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
13761373
s => s.to_string(),
13771374
}
13781375
});
@@ -1583,7 +1580,6 @@ fn test_dragonflybsd(target: &str) {
15831580
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
15841581
s.replace("e_nsec", ".tv_nsec")
15851582
}
1586-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
15871583
// Field is named `type` in C but that is a Rust keyword,
15881584
// so these fields are translated to `type_` in the bindings.
15891585
"type_" if struct_ == "rtprio" => "type".to_string(),
@@ -1965,8 +1961,6 @@ fn test_android(target: &str) {
19651961
// Our stat *_nsec fields normally don't actually exist but are part
19661962
// of a timeval struct
19671963
s if s.ends_with("_nsec") && struct_.starts_with("stat") => s.to_string(),
1968-
// FIXME(union): appears that `epoll_event.data` is an union
1969-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
19701964
// The following structs have a field called `type` in C,
19711965
// but `type` is a Rust keyword, so these fields are translated
19721966
// to `type_` in Rust.
@@ -3064,8 +3058,6 @@ fn test_emscripten(target: &str) {
30643058
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
30653059
s.replace("e_nsec", ".tv_nsec")
30663060
}
3067-
// Rust struct uses raw u64, rather than union
3068-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
30693061
s => s.to_string(),
30703062
}
30713063
});
@@ -3875,10 +3867,6 @@ fn test_linux(target: &str) {
38753867
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
38763868
s.replace("e_nsec", ".tv_nsec")
38773869
}
3878-
// FIXME(linux): epoll_event.data is actually a union in C, but in Rust
3879-
// it is only a u64 because we only expose one field
3880-
// http://man7.org/linux/man-pages/man2/epoll_wait.2.html
3881-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
38823870
// The following structs have a field called `type` in C,
38833871
// but `type` is a Rust keyword, so these fields are translated
38843872
// to `type_` in Rust.

src/fuchsia/mod.rs

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

409409
pub struct epoll_event {
410410
pub events: u32,
411-
pub u64: u64,
411+
pub data: epoll_data,
412412
}
413413

414414
pub struct lconv {
@@ -1044,6 +1044,13 @@ s_no_extra_traits! {
10441044
pub sival_ptr: *mut c_void,
10451045
}
10461046

1047+
pub union epoll_data {
1048+
pub ptr: *mut c_void,
1049+
pub fd: c_int,
1050+
pub u32: u32,
1051+
pub u64: u64,
1052+
}
1053+
10471054
pub union __c_anonymous_ifaddrs_ifa_ifu {
10481055
ifu_broadaddr: *mut sockaddr,
10491056
ifu_dstaddr: *mut sockaddr,
@@ -1312,13 +1319,25 @@ cfg_if! {
13121319
}
13131320

13141321
impl PartialEq for sigval {
1315-
fn eq(&self, other: &sigval) -> bool {
1322+
fn eq(&self, _other: &sigval) -> bool {
13161323
unimplemented!("traits")
13171324
}
13181325
}
13191326
impl Eq for sigval {}
13201327
impl hash::Hash for sigval {
1321-
fn hash<H: hash::Hasher>(&self, state: &mut H) {
1328+
fn hash<H: hash::Hasher>(&self, _state: &mut H) {
1329+
unimplemented!("traits")
1330+
}
1331+
}
1332+
1333+
impl PartialEq for epoll_data {
1334+
fn eq(&self, _other: &epoll_data) -> bool {
1335+
unimplemented!("traits")
1336+
}
1337+
}
1338+
impl Eq for epoll_data {}
1339+
impl hash::Hash for epoll_data {
1340+
fn hash<H: hash::Hasher>(&self, _state: &mut H) {
13221341
unimplemented!("traits")
13231342
}
13241343
}

src/unix/linux_like/mod.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,13 @@ s_no_extra_traits! {
297297
)]
298298
pub struct epoll_event {
299299
pub events: u32,
300+
pub data: epoll_data,
301+
}
302+
303+
pub union epoll_data {
304+
pub ptr: *mut c_void,
305+
pub fd: c_int,
306+
pub u32: u32,
300307
pub u64: u64,
301308
}
302309

@@ -345,17 +352,29 @@ s_no_extra_traits! {
345352
cfg_if! {
346353
if #[cfg(feature = "extra_traits")] {
347354
impl PartialEq for epoll_event {
348-
fn eq(&self, other: &epoll_event) -> bool {
349-
self.events == other.events && self.u64 == other.u64
355+
fn eq(&self, _other: &epoll_event) -> bool {
356+
unimplemented!("traits")
350357
}
351358
}
352359
impl Eq for epoll_event {}
353360
impl hash::Hash for epoll_event {
354361
fn hash<H: hash::Hasher>(&self, state: &mut H) {
355362
let events = self.events;
356-
let u64 = self.u64;
363+
let data = self.data;
357364
events.hash(state);
358-
u64.hash(state);
365+
data.hash(state);
366+
}
367+
}
368+
369+
impl PartialEq for epoll_data {
370+
fn eq(&self, _other: &epoll_data) -> bool {
371+
unimplemented!("traits")
372+
}
373+
}
374+
impl Eq for epoll_data {}
375+
impl hash::Hash for epoll_data {
376+
fn hash<H: hash::Hasher>(&self, _state: &mut H) {
377+
unimplemented!("traits")
359378
}
360379
}
361380

0 commit comments

Comments
 (0)