Skip to content

Commit ce727ac

Browse files
yuriksdguenther
authored andcommitted
---
yaml --- r: 149028 b: refs/heads/try2 c: 337e62e h: refs/heads/master v: v3
1 parent f636595 commit ce727ac

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 6381daab773ca97ef6553d4d244cc9a8f49475a4
8+
refs/heads/try2: 337e62e4d65e24682ba323b65283a59715a0c8af
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libfourcc/lib.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ pub fn macro_registrar(register: |Name, SyntaxExtension|) {
7070
None));
7171
}
7272

73-
use std::ascii::AsciiCast;
74-
7573
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult {
7674
let (expr, endian) = parse_tts(cx, tts);
7775

@@ -93,9 +91,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) ->
9391
ast::ExprLit(lit) => match lit.node {
9492
// string literal
9593
ast::LitStr(ref s, _) => {
96-
if !s.get().is_ascii() {
97-
cx.span_err(expr.span, "non-ascii string literal in fourcc!");
98-
} else if s.get().len() != 4 {
94+
if s.get().char_len() != 4 {
9995
cx.span_err(expr.span, "string literal with len != 4 in fourcc!");
10096
}
10197
s
@@ -112,14 +108,19 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) ->
112108
};
113109

114110
let mut val = 0u32;
115-
if little {
116-
for byte in s.get().bytes_rev().take(4) {
117-
val = (val << 8) | (byte as u32);
118-
}
119-
} else {
120-
for byte in s.get().bytes().take(4) {
121-
val = (val << 8) | (byte as u32);
122-
}
111+
for codepoint in s.get().chars().take(4) {
112+
let byte = if codepoint as u32 > 0xFF {
113+
cx.span_err(expr.span, "fourcc! literal character out of range 0-255");
114+
0u8
115+
} else {
116+
codepoint as u8
117+
};
118+
119+
val = if little {
120+
(val >> 8) | ((byte as u32) << 24)
121+
} else {
122+
(val << 8) | (byte as u32)
123+
};
123124
}
124125
let e = cx.expr_lit(sp, ast::LitUint(val as u64, ast::TyU32));
125126
MRExpr(e)

branches/try2/src/test/compile-fail/syntax-extension-fourcc-non-ascii-str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
extern mod fourcc;
1919

2020
fn main() {
21-
let v = fourcc!("fooλ"); //~ ERROR non-ascii string literal in fourcc!
21+
let v = fourcc!("fooλ"); //~ ERROR fourcc! literal character out of range 0-255
2222
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ fn main() {
4040
assert_eq!(static_val_le, 0x206f6f66u32);
4141
let exp = if cfg!(target_endian = "big") { 0x666f6f20u32 } else { 0x206f6f66u32 };
4242
assert_eq!(static_val_target, exp);
43+
44+
assert_eq!(fourcc!("\xC0\xFF\xEE!"), 0xC0FFEE21);
4345
}

0 commit comments

Comments
 (0)