Skip to content

Commit 6381daa

Browse files
yuriksdguenther
authored andcommitted
Default fourcc! to big-endian.
It was decided that a consistent result across platforms would be the most useful and least surprising. A "target" option has been added to get the old behaviour of using the target platform's endianess.
1 parent 97078d4 commit 6381daa

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/libfourcc/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) ->
7676
let (expr, endian) = parse_tts(cx, tts);
7777

7878
let little = match endian {
79-
None => target_endian_little(cx, sp),
79+
None => false,
8080
Some(Ident{ident, span}) => match token::get_ident(ident.name).get() {
8181
"little" => true,
8282
"big" => false,
83+
"target" => target_endian_little(cx, sp),
8384
_ => {
8485
cx.span_err(span, "invalid endian directive in fourcc!");
8586
target_endian_little(cx, sp)

src/test/run-pass-fulldeps/syntax-extension-fourcc.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,25 @@
1919
extern mod fourcc;
2020

2121
static static_val: u32 = fourcc!("foo ");
22-
static static_val_le: u32 = fourcc!("foo ", little);
2322
static static_val_be: u32 = fourcc!("foo ", big);
23+
static static_val_le: u32 = fourcc!("foo ", little);
24+
static static_val_target: u32 = fourcc!("foo ", target);
2425

2526
fn main() {
26-
let val = fourcc!("foo ");
27-
let exp = if cfg!(target_endian = "big") { 0x666f6f20u32 } else { 0x206f6f66u32 };
28-
assert_eq!(val, exp);
29-
3027
let val = fourcc!("foo ", big);
3128
assert_eq!(val, 0x666f6f20u32);
29+
assert_eq!(val, fourcc!("foo "));
3230

3331
let val = fourcc!("foo ", little);
3432
assert_eq!(val, 0x206f6f66u32);
3533

34+
let val = fourcc!("foo ", target);
3635
let exp = if cfg!(target_endian = "big") { 0x666f6f20u32 } else { 0x206f6f66u32 };
37-
assert_eq!(static_val, exp);
38-
assert_eq!(static_val_le, 0x206f6f66u32);
36+
assert_eq!(val, exp);
37+
3938
assert_eq!(static_val_be, 0x666f6f20u32);
39+
assert_eq!(static_val, static_val_be);
40+
assert_eq!(static_val_le, 0x206f6f66u32);
41+
let exp = if cfg!(target_endian = "big") { 0x666f6f20u32 } else { 0x206f6f66u32 };
42+
assert_eq!(static_val_target, exp);
4043
}

0 commit comments

Comments
 (0)