Skip to content

Commit d82763f

Browse files
author
Bryant Mairs
committed
Upgrade to Bitflags 1.0
The libc_bitflags! macro was replaced with a non-recursive one supporting only public structs. I could not figure out how to make the old macro work with the upgrade, so I reworked part of the bitflags! macro directly to suit our needs, much as the original recursive macro was made. There are no uses of this macro for non-public structs, so this is not a problem for internal code.
1 parent d374a1e commit d82763f

26 files changed

+186
-370
lines changed

.travis.yml

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,67 +18,67 @@ matrix:
1818
include:
1919
# Android
2020
- env: TARGET=aarch64-linux-android DISABLE_TESTS=1
21-
rust: 1.13.0
21+
rust: 1.20.0
2222
- env: TARGET=arm-linux-androideabi DISABLE_TESTS=1
23-
rust: 1.13.0
23+
rust: 1.20.0
2424
- env: TARGET=armv7-linux-androideabi DISABLE_TESTS=1
25-
rust: 1.13.0
25+
rust: 1.20.0
2626
- env: TARGET=aarch64-apple-ios DISABLE_TESTS=1
27-
rust: 1.13.0
27+
rust: 1.20.0
2828
os: osx
2929
- env: TARGET=i686-linux-android DISABLE_TESTS=1
30-
rust: 1.18.0
30+
rust: 1.20.0
3131
- env: TARGET=x86_64-linux-android DISABLE_TESTS=1
32-
rust: 1.18.0
32+
rust: 1.20.0
3333

3434
# Linux
3535
- env: TARGET=aarch64-unknown-linux-gnu
36-
rust: 1.13.0
36+
rust: 1.20.0
3737
- env: TARGET=armv7-apple-ios DISABLE_TESTS=1
38-
rust: 1.13.0
38+
rust: 1.20.0
3939
os: osx
4040
- env: TARGET=arm-unknown-linux-gnueabi
41-
rust: 1.13.0
41+
rust: 1.20.0
4242
- env: TARGET=arm-unknown-linux-musleabi DISABLE_TESTS=1
43-
rust: 1.14.0
43+
rust: 1.20.0
4444
- env: TARGET=armv7-unknown-linux-gnueabihf
45-
rust: 1.13.0
45+
rust: 1.20.0
4646
- env: TARGET=armv7s-apple-ios DISABLE_TESTS=1
47-
rust: 1.13.0
47+
rust: 1.20.0
4848
os: osx
4949
- env: TARGET=i686-unknown-linux-gnu
50-
rust: 1.13.0
50+
rust: 1.20.0
5151
- env: TARGET=i686-unknown-linux-musl
52-
rust: 1.13.0
52+
rust: 1.20.0
5353
- env: TARGET=mips-unknown-linux-gnu
54-
rust: 1.13.0
54+
rust: 1.20.0
5555
- env: TARGET=i386-apple-ios DISABLE_TESTS=1
56-
rust: 1.13.0
56+
rust: 1.20.0
5757
os: osx
5858
- env: TARGET=mips64-unknown-linux-gnuabi64
59-
rust: 1.13.0
59+
rust: 1.20.0
6060
- env: TARGET=mips64el-unknown-linux-gnuabi64
61-
rust: 1.13.0
61+
rust: 1.20.0
6262
- env: TARGET=mipsel-unknown-linux-gnu
63-
rust: 1.13.0
63+
rust: 1.20.0
6464
- env: TARGET=x86_64-apple-ios DISABLE_TESTS=1
65-
rust: 1.13.0
65+
rust: 1.20.0
6666
os: osx
6767
- env: TARGET=powerpc-unknown-linux-gnu DISABLE_TESTS=1
68-
rust: 1.13.0
68+
rust: 1.20.0
6969
- env: TARGET=powerpc64-unknown-linux-gnu
70-
rust: 1.13.0
70+
rust: 1.20.0
7171
- env: TARGET=powerpc64le-unknown-linux-gnu
72-
rust: 1.13.0
72+
rust: 1.20.0
7373
- env: TARGET=i686-apple-darwin
74-
rust: 1.13.0
74+
rust: 1.20.0
7575
os: osx
7676
- env: TARGET=s390x-unknown-linux-gnu DISABLE_TESTS=1
77-
rust: 1.13.0
77+
rust: 1.20.0
7878
- env: TARGET=x86_64-unknown-linux-gnu
79-
rust: 1.13.0
79+
rust: 1.20.0
8080
- env: TARGET=x86_64-unknown-linux-musl
81-
rust: 1.13.0
81+
rust: 1.20.0
8282

8383
# *BSD
8484
# FreeBSD i686 and x86_64 use BuildBot instead of Travis
@@ -87,10 +87,10 @@ matrix:
8787
# - env: TARGET=i686-unknown-freebsd DISABLE_TESTS=1
8888
# - env: TARGET=x86_64-unknown-freebsd DISABLE_TESTS=1
8989
- env: TARGET=x86_64-unknown-netbsd DISABLE_TESTS=1
90-
rust: 1.13.0
90+
rust: 1.20.0
9191

9292
- env: TARGET=x86_64-apple-darwin
93-
rust: 1.13.0
93+
rust: 1.20.0
9494
os: osx
9595

9696
# Make sure stable is always working too

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exclude = [
1414

1515
[dependencies]
1616
libc = { git = "https://github.com/rust-lang/libc" }
17-
bitflags = "0.9"
17+
bitflags = "1.0"
1818
cfg-if = "0.1.0"
1919
void = "1.0.2"
2020

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ limitations. Support for platforms is split into two tiers:
4646
*do not* block the inclusion of new code. Testing may be run, but
4747
failures in tests don't block the inclusion of new code.
4848

49-
The following targets are all supported by nix on Rust 1.13.0 or newer (unless
49+
The following targets are all supported by nix on Rust 1.20.0 or newer (unless
5050
otherwise noted):
5151

5252
Tier 1:
@@ -72,16 +72,16 @@ Tier 2:
7272
* aarch64-apple-ios
7373
* aarch64-linux-android
7474
* arm-linux-androideabi
75-
* arm-unknown-linux-musleabi (requires Rust >= 1.14)
75+
* arm-unknown-linux-musleabi
7676
* armv7-apple-ios
7777
* armv7-linux-androideabi
7878
* armv7s-apple-ios
7979
* i386-apple-ios
80-
* i686-linux-android (requires Rust >= 1.18)
80+
* i686-linux-android
8181
* powerpc-unknown-linux-gnu
8282
* s390x-unknown-linux-gnu
8383
* x86_64-apple-ios
84-
* x86_64-linux-android (requires Rust >= 1.18)
84+
* x86_64-linux-android
8585
* x86_64-unknown-netbsd
8686

8787
## Usage

src/macros.rs

Lines changed: 16 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/// The `libc_bitflags!` macro helps with a common use case of defining bitflags with values from
2-
/// the libc crate. It is used the same way as the `bitflags!` macro, except that only the name of
3-
/// the flag value has to be given.
1+
/// The `libc_bitflags!` macro helps with a common use case of defining a public bitflags type
2+
/// with values from the libc crate. It is used the same way as the `bitflags!` macro, except
3+
/// that only the name of the flag value has to be given.
44
///
55
/// The `libc` crate must be in scope with the name `libc`.
66
///
@@ -10,6 +10,7 @@
1010
/// pub struct ProtFlags: libc::c_int {
1111
/// PROT_NONE;
1212
/// PROT_READ;
13+
/// /// PROT_WRITE enables write protect
1314
/// PROT_WRITE;
1415
/// PROT_EXEC;
1516
/// #[cfg(any(target_os = "linux", target_os = "android"))]
@@ -38,205 +39,25 @@
3839
/// }
3940
/// ```
4041
macro_rules! libc_bitflags {
41-
// (non-pub) Exit rule.
42-
(@call_bitflags
43-
{
44-
name: $BitFlags:ident,
45-
type: $T:ty,
46-
attrs: [$($attrs:tt)*],
47-
flags: [$($flags:tt)*],
48-
}
49-
) => {
50-
bitflags! {
51-
$($attrs)*
52-
struct $BitFlags: $T {
53-
$($flags)*
54-
}
55-
}
56-
};
57-
58-
// (pub) Exit rule.
59-
(@call_bitflags
60-
{
61-
pub,
62-
name: $BitFlags:ident,
63-
type: $T:ty,
64-
attrs: [$($attrs:tt)*],
65-
flags: [$($flags:tt)*],
42+
(
43+
$(#[$outer:meta])*
44+
pub struct $BitFlags:ident: $T:ty {
45+
$(
46+
$(#[$inner:ident $($args:tt)*])*
47+
$Flag:ident $(as $cast:ty)*;
48+
)+
6649
}
6750
) => {
6851
bitflags! {
69-
$($attrs)*
52+
$(#[$outer])*
7053
pub struct $BitFlags: $T {
71-
$($flags)*
72-
}
73-
}
74-
};
75-
76-
// (non-pub) Done accumulating.
77-
(@accumulate_flags
78-
{
79-
name: $BitFlags:ident,
80-
type: $T:ty,
81-
attrs: $attrs:tt,
82-
},
83-
$flags:tt;
84-
) => {
85-
libc_bitflags! {
86-
@call_bitflags
87-
{
88-
name: $BitFlags,
89-
type: $T,
90-
attrs: $attrs,
91-
flags: $flags,
54+
$(
55+
$(#[$inner $($args)*])*
56+
const $Flag = libc::$Flag $(as $cast)*;
57+
)+
9258
}
9359
}
9460
};
95-
96-
// (pub) Done accumulating.
97-
(@accumulate_flags
98-
{
99-
pub,
100-
name: $BitFlags:ident,
101-
type: $T:ty,
102-
attrs: $attrs:tt,
103-
},
104-
$flags:tt;
105-
) => {
106-
libc_bitflags! {
107-
@call_bitflags
108-
{
109-
pub,
110-
name: $BitFlags,
111-
type: $T,
112-
attrs: $attrs,
113-
flags: $flags,
114-
}
115-
}
116-
};
117-
118-
// Munch an attr.
119-
(@accumulate_flags
120-
$prefix:tt,
121-
[$($flags:tt)*];
122-
#[$attr:meta] $($tail:tt)*
123-
) => {
124-
libc_bitflags! {
125-
@accumulate_flags
126-
$prefix,
127-
[
128-
$($flags)*
129-
#[$attr]
130-
];
131-
$($tail)*
132-
}
133-
};
134-
135-
// Munch last ident if not followed by a semicolon.
136-
(@accumulate_flags
137-
$prefix:tt,
138-
[$($flags:tt)*];
139-
$flag:ident
140-
) => {
141-
libc_bitflags! {
142-
@accumulate_flags
143-
$prefix,
144-
[
145-
$($flags)*
146-
const $flag = libc::$flag;
147-
];
148-
}
149-
};
150-
151-
// Munch last ident and cast it to the given type.
152-
(@accumulate_flags
153-
$prefix:tt,
154-
[$($flags:tt)*];
155-
$flag:ident as $ty:ty
156-
) => {
157-
libc_bitflags! {
158-
@accumulate_flags
159-
$prefix,
160-
[
161-
$($flags)*
162-
const $flag = libc::$flag as $ty;
163-
];
164-
}
165-
};
166-
167-
// Munch an ident; covers terminating semicolon case.
168-
(@accumulate_flags
169-
$prefix:tt,
170-
[$($flags:tt)*];
171-
$flag:ident; $($tail:tt)*
172-
) => {
173-
libc_bitflags! {
174-
@accumulate_flags
175-
$prefix,
176-
[
177-
$($flags)*
178-
const $flag = libc::$flag;
179-
];
180-
$($tail)*
181-
}
182-
};
183-
184-
// Munch an ident and cast it to the given type; covers terminating semicolon
185-
// case.
186-
(@accumulate_flags
187-
$prefix:tt,
188-
[$($flags:tt)*];
189-
$flag:ident as $ty:ty; $($tail:tt)*
190-
) => {
191-
libc_bitflags! {
192-
@accumulate_flags
193-
$prefix,
194-
[
195-
$($flags)*
196-
const $flag = libc::$flag as $ty;
197-
];
198-
$($tail)*
199-
}
200-
};
201-
202-
// (non-pub) Entry rule.
203-
(
204-
$(#[$attr:meta])*
205-
struct $BitFlags:ident: $T:ty {
206-
$($vals:tt)*
207-
}
208-
) => {
209-
libc_bitflags! {
210-
@accumulate_flags
211-
{
212-
name: $BitFlags,
213-
type: $T,
214-
attrs: [$(#[$attr])*],
215-
},
216-
[];
217-
$($vals)*
218-
}
219-
};
220-
221-
// (pub) Entry rule.
222-
(
223-
$(#[$attr:meta])*
224-
pub struct $BitFlags:ident: $T:ty {
225-
$($vals:tt)*
226-
}
227-
) => {
228-
libc_bitflags! {
229-
@accumulate_flags
230-
{
231-
pub,
232-
name: $BitFlags,
233-
type: $T,
234-
attrs: [$(#[$attr])*],
235-
},
236-
[];
237-
$($vals)*
238-
}
239-
};
24061
}
24162

24263
/// The `libc_enum!` macro helps with a common use case of defining an enum exclusively using

src/mqueue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub fn mq_setattr(mqd: mqd_t, newattr: &MqAttr) -> Result<MqAttr> {
151151
/// Returns the old attributes
152152
pub fn mq_set_nonblock(mqd: mqd_t) -> Result<(MqAttr)> {
153153
let oldattr = try!(mq_getattr(mqd));
154-
let newattr = MqAttr::new(O_NONBLOCK.bits() as c_long,
154+
let newattr = MqAttr::new(MQ_OFlag::O_NONBLOCK.bits() as c_long,
155155
oldattr.mq_attr.mq_maxmsg,
156156
oldattr.mq_attr.mq_msgsize,
157157
oldattr.mq_attr.mq_curmsgs);

0 commit comments

Comments
 (0)