Skip to content

Commit

Permalink
Default fourcc! to big-endian.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yuriks authored and dguenther committed Feb 9, 2014
1 parent 97078d4 commit 6381daa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/libfourcc/lib.rs
Expand Up @@ -76,10 +76,11 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) ->
let (expr, endian) = parse_tts(cx, tts);

let little = match endian {
None => target_endian_little(cx, sp),
None => false,
Some(Ident{ident, span}) => match token::get_ident(ident.name).get() {
"little" => true,
"big" => false,
"target" => target_endian_little(cx, sp),
_ => {
cx.span_err(span, "invalid endian directive in fourcc!");
target_endian_little(cx, sp)
Expand Down
17 changes: 10 additions & 7 deletions src/test/run-pass-fulldeps/syntax-extension-fourcc.rs
Expand Up @@ -19,22 +19,25 @@
extern mod fourcc;

static static_val: u32 = fourcc!("foo ");
static static_val_le: u32 = fourcc!("foo ", little);
static static_val_be: u32 = fourcc!("foo ", big);
static static_val_le: u32 = fourcc!("foo ", little);
static static_val_target: u32 = fourcc!("foo ", target);

fn main() {
let val = fourcc!("foo ");
let exp = if cfg!(target_endian = "big") { 0x666f6f20u32 } else { 0x206f6f66u32 };
assert_eq!(val, exp);

let val = fourcc!("foo ", big);
assert_eq!(val, 0x666f6f20u32);
assert_eq!(val, fourcc!("foo "));

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

let val = fourcc!("foo ", target);
let exp = if cfg!(target_endian = "big") { 0x666f6f20u32 } else { 0x206f6f66u32 };
assert_eq!(static_val, exp);
assert_eq!(static_val_le, 0x206f6f66u32);
assert_eq!(val, exp);

assert_eq!(static_val_be, 0x666f6f20u32);
assert_eq!(static_val, static_val_be);
assert_eq!(static_val_le, 0x206f6f66u32);
let exp = if cfg!(target_endian = "big") { 0x666f6f20u32 } else { 0x206f6f66u32 };
assert_eq!(static_val_target, exp);
}

0 comments on commit 6381daa

Please sign in to comment.