diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2017-07-04 18:39:33 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2017-07-04 18:39:33 +0000 |
commit | 3912a202255d9fee797703966998babbc79fc49b (patch) | |
tree | c90eda445af8f832db5225ae8de9a474dd98e782 /src/macros.rs | |
parent | 9e51647095af4612870c0e4582b739c8147784dc (diff) | |
parent | 552fccf1e02ee2b075ae0528ee5f22b0f1791db3 (diff) | |
download | nix-3912a202255d9fee797703966998babbc79fc49b.zip |
Merge #631
631: Allow nix to compile on android r=Susurrus
Fixes #313
Diffstat (limited to 'src/macros.rs')
-rw-r--r-- | src/macros.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/macros.rs b/src/macros.rs index 046077f9..b8707d0b 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -19,6 +19,24 @@ /// } /// } /// ``` +/// +/// Example with casting, due to a mistake in libc. In this example, the +/// various flags have different types, so we cast the broken ones to the right +/// type. +/// +/// ``` +/// libc_bitflags!{ +/// pub flags SaFlags: libc::c_ulong { +/// SA_NOCLDSTOP as libc::c_ulong, +/// SA_NOCLDWAIT, +/// SA_NODEFER as libc::c_ulong, +/// SA_ONSTACK, +/// SA_RESETHAND as libc::c_ulong, +/// SA_RESTART as libc::c_ulong, +/// SA_SIGINFO, +/// } +/// } +/// ``` macro_rules! libc_bitflags { // (non-pub) Exit rule. (@call_bitflags @@ -130,6 +148,22 @@ macro_rules! libc_bitflags { } }; + // Munch last ident and cast it to the given type. + (@accumulate_flags + $prefix:tt, + [$($flags:tt)*]; + $flag:ident as $ty:ty + ) => { + libc_bitflags! { + @accumulate_flags + $prefix, + [ + $($flags)* + const $flag = libc::$flag as $ty; + ]; + } + }; + // Munch an ident; covers terminating comma case. (@accumulate_flags $prefix:tt, @@ -147,6 +181,24 @@ macro_rules! libc_bitflags { } }; + // Munch an ident and cast it to the given type; covers terminating comma + // case. + (@accumulate_flags + $prefix:tt, + [$($flags:tt)*]; + $flag:ident as $ty:ty, $($tail:tt)* + ) => { + libc_bitflags! { + @accumulate_flags + $prefix, + [ + $($flags)* + const $flag = libc::$flag as $ty; + ]; + $($tail)* + } + }; + // (non-pub) Entry rule. ( $(#[$attr:meta])* |