Skip to content

Commit ab66559

Browse files
committed
Handle unions in the s macro
1 parent 8f23067 commit ab66559

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

src/macros.rs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,70 @@ macro_rules! __cfg_if_apply {
3636

3737
macro_rules! s {
3838
($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($(
39+
s!(it: $(#[$attr])* pub $t $i { $($field)* });
40+
)*);
41+
(it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
42+
cfg_if! {
43+
if #[cfg(libc_union)] {
44+
__item! {
45+
#[repr(C)]
46+
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
47+
$(#[$attr])*
48+
pub union $i { $($field)* }
49+
}
50+
51+
impl ::dox::Copy for $i {}
52+
impl ::dox::Clone for $i {
53+
fn clone(&self) -> $i { *self }
54+
}
55+
}
56+
}
57+
);
58+
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
3959
__item! {
4060
#[repr(C)]
41-
$(#[$attr])*
4261
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
43-
pub $t $i { $($field)* }
62+
$(#[$attr])*
63+
pub struct $i { $($field)* }
4464
}
4565
impl ::dox::Copy for $i {}
4666
impl ::dox::Clone for $i {
4767
fn clone(&self) -> $i { *self }
4868
}
49-
)*)
69+
);
5070
}
5171

5272
macro_rules! s_no_extra_traits {
5373
($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($(
74+
s!(it: $(#[$attr])* pub $t $i { $($field)* });
75+
)*);
76+
(it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
77+
cfg_if! {
78+
if #[cfg(libc_union)] {
79+
__item! {
80+
#[repr(C)]
81+
$(#[$attr])*
82+
pub union $i { $($field)* }
83+
}
84+
85+
impl ::dox::Copy for $i {}
86+
impl ::dox::Clone for $i {
87+
fn clone(&self) -> $i { *self }
88+
}
89+
}
90+
}
91+
);
92+
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
5493
__item! {
5594
#[repr(C)]
5695
$(#[$attr])*
57-
pub $t $i { $($field)* }
96+
pub struct $i { $($field)* }
5897
}
5998
impl ::dox::Copy for $i {}
6099
impl ::dox::Clone for $i {
61100
fn clone(&self) -> $i { *self }
62101
}
63-
)*)
102+
);
64103
}
65104

66105
#[allow(unused_macros)]

src/unix/bsd/apple/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,12 @@ s! {
486486
pub sem_pad3: [::int32_t; 4],
487487
}
488488

489+
pub union semun {
490+
pub val: ::c_int,
491+
pub buf: *mut semid_ds,
492+
pub array: *mut ::c_ushort,
493+
}
494+
489495
// sys/shm.h
490496

491497
#[cfg_attr(feature = "rustc-dep-of-std", repr(packed(4)))]

0 commit comments

Comments
 (0)