about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuri Kunde Schlesner <yuriks@yuriks.net>2014-02-06 17:41:49 -0200
committerDerek Guenther <dguenther9@gmail.com>2014-02-08 23:40:17 -0600
commit6381daab773ca97ef6553d4d244cc9a8f49475a4 (patch)
tree9649aa6e4964251261ed133bdc5f6f75b3ac867d
parent97078d43b20abc7510fde2e400500fed4c8b1eb3 (diff)
downloadrust-6381daab773ca97ef6553d4d244cc9a8f49475a4.tar.gz
rust-6381daab773ca97ef6553d4d244cc9a8f49475a4.zip
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.
-rw-r--r--src/libfourcc/lib.rs3
-rw-r--r--src/test/run-pass-fulldeps/syntax-extension-fourcc.rs17
2 files changed, 12 insertions, 8 deletions
diff --git a/src/libfourcc/lib.rs b/src/libfourcc/lib.rs
index aae47b87f07..2b017b501c9 100644
--- a/src/libfourcc/lib.rs
+++ b/src/libfourcc/lib.rs
@@ -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)
diff --git a/src/test/run-pass-fulldeps/syntax-extension-fourcc.rs b/src/test/run-pass-fulldeps/syntax-extension-fourcc.rs
index 0d46c28431d..be5e24d09d5 100644
--- a/src/test/run-pass-fulldeps/syntax-extension-fourcc.rs
+++ b/src/test/run-pass-fulldeps/syntax-extension-fourcc.rs
@@ -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);
 }