Skip to content

Commit e6b5a23

Browse files
committed
Fix the build with Rust 1.14.0
1 parent dbca3cc commit e6b5a23

File tree

2 files changed

+151
-77
lines changed

2 files changed

+151
-77
lines changed

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 84 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -882,12 +882,6 @@ s! {
882882
pub profhz: ::c_int,
883883
}
884884

885-
#[cfg(libc_union)]
886-
pub struct __c_anonymous_sigev_thread {
887-
pub _function: *mut ::c_void, // Actually a function pointer
888-
pub _attribute: *mut ::pthread_attr_t,
889-
}
890-
891885
pub struct __c_anonymous_stailq_entry_devstat {
892886
pub stqe_next: *mut devstat,
893887
}
@@ -1325,25 +1319,6 @@ s! {
13251319
pub strchange_instrms: u16,
13261320
pub strchange_outstrms: u16,
13271321
}
1328-
1329-
// When sigevent was first added to libc, Rust still didn't support unions.
1330-
// So the definition only included one of the union's member. This
1331-
// structure exists for backwards-compatibility with consumers that still
1332-
// try to access that one member.
1333-
#[doc(hidden)]
1334-
#[deprecated(
1335-
since = "0.2.127",
1336-
note = "Use sigevent instead"
1337-
)]
1338-
pub struct sigevent_0_2_126 {
1339-
pub sigev_notify: ::c_int,
1340-
pub sigev_signo: ::c_int,
1341-
pub sigev_value: ::sigval,
1342-
pub sigev_notify_thread_id: ::lwpid_t,
1343-
#[cfg(target_pointer_width = "64")]
1344-
__unused1: ::c_int,
1345-
__unused2: [::c_long; 7]
1346-
}
13471322
}
13481323

13491324
s_no_extra_traits! {
@@ -1394,30 +1369,6 @@ s_no_extra_traits! {
13941369
__reserved: [::c_long; 4]
13951370
}
13961371

1397-
// Can't correctly impl Debug for unions
1398-
#[allow(missing_debug_implementations)]
1399-
#[cfg(libc_union)]
1400-
pub union __c_anonymous_sigev_un {
1401-
pub _threadid: ::__lwpid_t,
1402-
pub _sigev_thread: __c_anonymous_sigev_thread,
1403-
pub _kevent_flags: ::c_ushort,
1404-
__spare__: [::c_long; 8],
1405-
}
1406-
1407-
#[cfg(libc_union)]
1408-
pub struct sigevent {
1409-
pub sigev_notify: ::c_int,
1410-
pub sigev_signo: ::c_int,
1411-
pub sigev_value: ::sigval,
1412-
pub _sigev_un: __c_anonymous_sigev_un,
1413-
/// Exists just to prevent the struct from being safely constructed,
1414-
/// because the Debug, Hash, PartialImpl, and
1415-
/// Deref<Target=sigevent_0_2_0126> trait impls might read uninitialized
1416-
/// fields of _sigev_un. This field may be removed once those trait
1417-
/// impls are.
1418-
_private: ()
1419-
}
1420-
14211372
pub struct ptsstat {
14221373
#[cfg(any(freebsd12, freebsd13, freebsd14))]
14231374
pub dev: u64,
@@ -1650,7 +1601,79 @@ s_no_extra_traits! {
16501601
}
16511602
}
16521603

1604+
#[cfg(libc_union)]
1605+
s! {
1606+
pub struct __c_anonymous_sigev_thread {
1607+
pub _function: *mut ::c_void, // Actually a function pointer
1608+
pub _attribute: *mut ::pthread_attr_t,
1609+
}
1610+
1611+
// When sigevent was first added to libc, Rust still didn't support unions.
1612+
// So the definition only included one of the union's member. This
1613+
// structure exists for backwards-compatibility with consumers that still
1614+
// try to access that one member.
1615+
#[doc(hidden)]
1616+
#[deprecated(
1617+
since = "0.2.147",
1618+
note = "Use sigevent instead"
1619+
)]
1620+
pub struct sigevent_0_2_126 {
1621+
pub sigev_notify: ::c_int,
1622+
pub sigev_signo: ::c_int,
1623+
pub sigev_value: ::sigval,
1624+
pub sigev_notify_thread_id: ::lwpid_t,
1625+
#[cfg(target_pointer_width = "64")]
1626+
__unused1: ::c_int,
1627+
__unused2: [::c_long; 7]
1628+
}
1629+
}
1630+
1631+
#[cfg(libc_union)]
1632+
s_no_extra_traits! {
1633+
// Can't correctly impl Debug for unions
1634+
#[allow(missing_debug_implementations)]
1635+
pub union __c_anonymous_sigev_un {
1636+
pub _threadid: ::__lwpid_t,
1637+
pub _sigev_thread: __c_anonymous_sigev_thread,
1638+
pub _kevent_flags: ::c_ushort,
1639+
__spare__: [::c_long; 8],
1640+
}
1641+
1642+
pub struct sigevent {
1643+
pub sigev_notify: ::c_int,
1644+
pub sigev_signo: ::c_int,
1645+
pub sigev_value: ::sigval,
1646+
pub _sigev_un: __c_anonymous_sigev_un,
1647+
/// Exists just to prevent the struct from being safely constructed,
1648+
/// because the Debug, Hash, PartialImpl, and
1649+
/// Deref<Target=sigevent_0_2_126> trait impls might read uninitialized
1650+
/// fields of _sigev_un. This field may be removed once those trait
1651+
/// impls are.
1652+
_private: ()
1653+
}
1654+
}
1655+
1656+
#[cfg(not(libc_union))]
1657+
s_no_extra_traits! {
1658+
pub struct sigevent {
1659+
pub sigev_notify: ::c_int,
1660+
pub sigev_signo: ::c_int,
1661+
pub sigev_value: ::sigval,
1662+
pub _unused0: ::lwpid_t,
1663+
#[cfg(target_pointer_width = "64")]
1664+
__unused1: ::c_int,
1665+
__unused2: [::c_long; 7],
1666+
/// Exists just to prevent the struct from being safely constructed,
1667+
/// because the Debug, Hash, PartialImpl, and
1668+
/// Deref<Target=sigevent_0_2_126> trait impls might read uninitialized
1669+
/// fields of _sigev_un. This field may be removed once those trait
1670+
/// impls are.
1671+
_private: ()
1672+
}
1673+
}
1674+
16531675
#[allow(deprecated)]
1676+
#[cfg(libc_union)]
16541677
impl ::core::ops::Deref for sigevent {
16551678
type Target = sigevent_0_2_126;
16561679

@@ -1660,6 +1683,7 @@ impl ::core::ops::Deref for sigevent {
16601683
}
16611684

16621685
#[allow(deprecated)]
1686+
#[cfg(libc_union)]
16631687
impl ::core::ops::DerefMut for sigevent {
16641688
fn deref_mut(&mut self) -> &mut Self::Target {
16651689
unsafe { &mut *(self as *mut Self as *mut sigevent_0_2_126) }
@@ -1855,6 +1879,7 @@ cfg_if! {
18551879
}
18561880
}
18571881

1882+
#[cfg(libc_union)]
18581883
impl PartialEq for sigevent {
18591884
fn eq(&self, other: &sigevent) -> bool {
18601885
self.sigev_notify == other.sigev_notify
@@ -1880,13 +1905,22 @@ cfg_if! {
18801905
}
18811906
}
18821907
}
1908+
#[cfg(not(libc_union))]
1909+
impl PartialEq for sigevent {
1910+
fn eq(&self, other: &sigevent) -> bool {
1911+
self.sigev_notify == other.sigev_notify
1912+
&& self.sigev_signo == other.sigev_signo
1913+
&& self.sigev_value == other.sigev_value
1914+
}
1915+
}
18831916
impl Eq for sigevent {}
18841917
impl ::fmt::Debug for sigevent {
18851918
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
18861919
let mut ds = f.debug_struct("sigevent");
18871920
ds.field("sigev_notify", &self.sigev_notify);
18881921
ds.field("sigev_signo", &self.sigev_signo);
18891922
ds.field("sigev_value", &self.sigev_value);
1923+
#[cfg(libc_union)]
18901924
// The sigev_notify field indicates which union fields are valid
18911925
unsafe {
18921926
match self.sigev_notify {
@@ -1907,6 +1941,7 @@ cfg_if! {
19071941
self.sigev_notify.hash(state);
19081942
self.sigev_signo.hash(state);
19091943
self.sigev_value.hash(state);
1944+
#[cfg(libc_union)]
19101945
// The sigev_notify field indicates which union fields are valid
19111946
unsafe {
19121947
match self.sigev_notify {

src/unix/linux_like/mod.rs

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ impl ::Clone for timezone {
1616
}
1717

1818
s! {
19-
#[cfg(libc_union)]
20-
pub struct __c_anonymous_sigev_thread {
21-
pub _function: *mut ::c_void, // Actually a function pointer
22-
pub _attribute: *mut ::pthread_attr_t,
23-
}
24-
2519
pub struct in_addr {
2620
pub s_addr: ::in_addr_t,
2721
}
@@ -214,26 +208,6 @@ s! {
214208
pub msg_hdr: ::msghdr,
215209
pub msg_len: ::c_uint,
216210
}
217-
218-
// When sigevent was first added to libc, Rust still didn't support unions.
219-
// So the definition only included one of the union's member. This
220-
// structure exists for backwards-compatibility with consumers that still
221-
// try to access that one member.
222-
#[doc(hidden)]
223-
#[deprecated(
224-
since = "0.2.127",
225-
note = "Use sigevent instead"
226-
)]
227-
pub struct sigevent_0_2_126 {
228-
pub sigev_value: ::sigval,
229-
pub sigev_signo: ::c_int,
230-
pub sigev_notify: ::c_int,
231-
pub sigev_notify_thread_id: ::c_int,
232-
#[cfg(target_pointer_width = "64")]
233-
__unused1: [::c_int; 11],
234-
#[cfg(target_pointer_width = "32")]
235-
__unused1: [::c_int; 12]
236-
}
237211
}
238212

239213
s_no_extra_traits! {
@@ -273,6 +247,39 @@ s_no_extra_traits! {
273247
pub domainname: [::c_char; 65]
274248
}
275249

250+
}
251+
252+
#[cfg(libc_union)]
253+
s! {
254+
pub struct __c_anonymous_sigev_thread {
255+
pub _function: *mut ::c_void, // Actually a function pointer
256+
pub _attribute: *mut ::pthread_attr_t,
257+
}
258+
259+
// When sigevent was first added to libc, Rust still didn't support unions.
260+
// So the definition only included one of the union's member. This
261+
// structure exists for backwards-compatibility with consumers that still
262+
// try to access that one member.
263+
#[doc(hidden)]
264+
#[deprecated(
265+
since = "0.2.127",
266+
note = "Use sigevent instead"
267+
)]
268+
#[cfg(libc_union)]
269+
pub struct sigevent_0_2_126 {
270+
pub sigev_value: ::sigval,
271+
pub sigev_signo: ::c_int,
272+
pub sigev_notify: ::c_int,
273+
pub sigev_notify_thread_id: ::c_int,
274+
#[cfg(target_pointer_width = "64")]
275+
__unused1: [::c_int; 11],
276+
#[cfg(target_pointer_width = "32")]
277+
__unused1: [::c_int; 12]
278+
}
279+
}
280+
281+
#[cfg(libc_union)]
282+
s_no_extra_traits!{
276283
// Can't correctly impl Debug for unions
277284
#[allow(missing_debug_implementations)]
278285
#[cfg(libc_union)]
@@ -285,22 +292,42 @@ s_no_extra_traits! {
285292
pub _sigev_thread: __c_anonymous_sigev_thread,
286293
}
287294

288-
#[cfg(libc_union)]
289295
pub struct sigevent {
290296
pub sigev_value: ::sigval,
291297
pub sigev_signo: ::c_int,
292298
pub sigev_notify: ::c_int,
293299
pub _sigev_un: __c_anonymous_sigev_un,
294300
/// Exists just to prevent the struct from being safely constructed,
295301
/// because the Debug, Hash, PartialImpl, and
296-
/// Deref<Target=sigevent_0_2_0126> trait impls might read uninitialized
302+
/// Deref<Target=sigevent_0_2_126> trait impls might read uninitialized
303+
/// fields of _sigev_un. This field may be removed once those trait
304+
/// impls are.
305+
_private: ()
306+
}
307+
}
308+
309+
#[cfg(not(libc_union))]
310+
s_no_extra_traits!{
311+
pub struct sigevent {
312+
pub sigev_value: ::sigval,
313+
pub sigev_signo: ::c_int,
314+
pub sigev_notify: ::c_int,
315+
__unused0: ::c_int,
316+
#[cfg(target_pointer_width = "64")]
317+
__unused1: [::c_int; 11],
318+
#[cfg(target_pointer_width = "32")]
319+
__unused1: [::c_int; 12],
320+
/// Exists just to prevent the struct from being safely constructed,
321+
/// because the Debug, Hash, PartialImpl, and
322+
/// Deref<Target=sigevent_0_2_126> trait impls might read uninitialized
297323
/// fields of _sigev_un. This field may be removed once those trait
298324
/// impls are.
299325
_private: ()
300326
}
301327
}
302328

303329
#[allow(deprecated)]
330+
#[cfg(libc_union)]
304331
impl ::core::ops::Deref for sigevent {
305332
type Target = sigevent_0_2_126;
306333

@@ -310,6 +337,7 @@ impl ::core::ops::Deref for sigevent {
310337
}
311338

312339
#[allow(deprecated)]
340+
#[cfg(libc_union)]
313341
impl ::core::ops::DerefMut for sigevent {
314342
fn deref_mut(&mut self) -> &mut Self::Target {
315343
unsafe { &mut *(self as *mut Self as *mut sigevent_0_2_126) }
@@ -460,6 +488,7 @@ cfg_if! {
460488
}
461489
}
462490

491+
#[cfg(libc_union)]
463492
impl PartialEq for sigevent {
464493
fn eq(&self, other: &sigevent) -> bool {
465494
self.sigev_value == other.sigev_value
@@ -485,13 +514,22 @@ cfg_if! {
485514
}
486515
}
487516
}
517+
#[cfg(not(libc_union))]
518+
impl PartialEq for sigevent {
519+
fn eq(&self, other: &sigevent) -> bool {
520+
self.sigev_value == other.sigev_value
521+
&& self.sigev_signo == other.sigev_signo
522+
&& self.sigev_notify == other.sigev_notify
523+
}
524+
}
488525
impl Eq for sigevent {}
489526
impl ::fmt::Debug for sigevent {
490527
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
491528
let mut ds = f.debug_struct("sigevent");
492529
ds.field("sigev_value", &self.sigev_value);
493530
ds.field("sigev_signo", &self.sigev_signo);
494531
ds.field("sigev_notify", &self.sigev_notify);
532+
#[cfg(libc_union)]
495533
// The sigev_notify field indicates which union fields are valid
496534
unsafe {
497535
match self.sigev_notify {
@@ -515,6 +553,7 @@ cfg_if! {
515553
self.sigev_value.hash(state);
516554
self.sigev_signo.hash(state);
517555
self.sigev_notify.hash(state);
556+
#[cfg(libc_union)]
518557
// The sigev_notify field indicates which union fields are valid
519558
unsafe {
520559
match self.sigev_notify {

0 commit comments

Comments
 (0)