Skip to content

Commit 22623e1

Browse files
committed
Implement epoll_data union
1 parent 3aeb292 commit 22623e1

File tree

3 files changed

+49
-23
lines changed

3 files changed

+49
-23
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.
@@ -3063,8 +3057,6 @@ fn test_emscripten(target: &str) {
30633057
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
30643058
s.replace("e_nsec", ".tv_nsec")
30653059
}
3066-
// Rust struct uses raw u64, rather than union
3067-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
30683060
s => s.to_string(),
30693061
}
30703062
});
@@ -3873,10 +3865,6 @@ fn test_linux(target: &str) {
38733865
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
38743866
s.replace("e_nsec", ".tv_nsec")
38753867
}
3876-
// FIXME(linux): epoll_event.data is actually a union in C, but in Rust
3877-
// it is only a u64 because we only expose one field
3878-
// http://man7.org/linux/man-pages/man2/epoll_wait.2.html
3879-
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
38803868
// The following structs have a field called `type` in C,
38813869
// but `type` is a Rust keyword, so these fields are translated
38823870
// to `type_` in Rust.

src/fuchsia/mod.rs

Lines changed: 24 additions & 5 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_ifa_ifu {
10481055
ifu_broadaddr: *mut sockaddr,
10491056
ifu_dstaddr: *mut sockaddr,
@@ -1312,25 +1319,37 @@ 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: &sigval) -> 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
}
13251344

13261345
impl PartialEq for __c_anonymous_ifa_ifu {
1327-
fn eq(&self, other: &__c_anonymous_ifa_ifu) -> bool {
1346+
fn eq(&self, _other: &__c_anonymous_ifa_ifu) -> bool {
13281347
unimplemented!("traits")
13291348
}
13301349
}
13311350
impl Eq for __c_anonymous_ifa_ifu {}
13321351
impl hash::Hash for __c_anonymous_ifa_ifu {
1333-
fn hash<H: hash::Hasher>(&self, state: &mut H) {
1352+
fn hash<H: hash::Hasher>(&self, _state: &mut H) {
13341353
unimplemented!("traits")
13351354
}
13361355
}

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
}

0 commit comments

Comments
 (0)