Skip to content

Commit cc44c00

Browse files
committed
Handle unions in the s macro
1 parent 385504e commit cc44c00

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

src/macros.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,33 @@ 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 struct $i:ident { $($field:tt)* }) => (
3942
__item! {
4043
#[repr(C)]
4144
$(#[$attr])*
42-
pub $t $i { $($field)* }
45+
pub struct $i { $($field)* }
4346
}
4447
impl ::dox::Copy for $i {}
4548
impl ::dox::Clone for $i {
4649
fn clone(&self) -> $i { *self }
4750
}
48-
)*)
51+
);
52+
(it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
53+
__item! {
54+
#[cfg(libc_union)]
55+
#[repr(C)]
56+
$(#[$attr])*
57+
pub struct $i { $($field)* }
58+
}
59+
#[cfg(libc_union)]
60+
impl ::dox::Copy for $i {}
61+
#[cfg(libc_union)]
62+
impl ::dox::Clone for $i {
63+
fn clone(&self) -> $i { *self }
64+
}
65+
);
4966
}
5067

5168
#[allow(unused_macros)]

src/unix/bsd/apple/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,12 @@ s! {
557557
pub sem_pad3: [::int32_t; 4],
558558
}
559559

560+
pub union semun {
561+
pub val: ::c_int,
562+
pub buf: *mut semid_ds,
563+
pub array: *mut ::c_ushort,
564+
}
565+
560566
// sys/shm.h
561567

562568
#[cfg_attr(feature = "rustc-dep-of-std", repr(packed(4)))]
@@ -583,15 +589,6 @@ s! {
583589
}
584590
}
585591

586-
#[cfg(libc_union)]
587-
s! {
588-
pub union semun {
589-
pub val: ::c_int,
590-
pub buf: *mut semid_ds,
591-
pub array: *mut ::c_ushort,
592-
}
593-
}
594-
595592
pub const _UTX_USERSIZE: usize = 256;
596593
pub const _UTX_LINESIZE: usize = 32;
597594
pub const _UTX_IDSIZE: usize = 4;

0 commit comments

Comments
 (0)