Skip to content

Commit 753f372

Browse files
committed
Support cast expressions in array lengths
Happens typically to cast to a usize, let's just make it work. Closes rust-lang#15
1 parent a4b697d commit 753f372

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

ctest/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,6 @@ impl<'a> Generator<'a> {
873873
}
874874

875875
let cfield = self.rust2cfield(ty, &name);
876-
let rust_fieldty = self.ty2name(&field.node.ty, true);
877876

878877
t!(writeln!(self.c, r#"
879878
uint64_t __test_offset_{ty}_{rust_field}(void) {{
@@ -915,15 +914,15 @@ impl<'a> Generator<'a> {
915914
t!(writeln!(self.rust, r#"
916915
extern {{
917916
fn __test_field_type_{ty}_{field}(a: *mut {ty})
918-
-> *mut {field_ty};
917+
-> *mut u8;
919918
}}
920919
unsafe {{
921920
let foo = 0 as *mut {ty};
922921
same(&(*foo).{field} as *const _ as *mut _,
923922
__test_field_type_{ty}_{field}(foo),
924923
"field type {field} of {ty}");
925924
}}
926-
"#, ty = ty, field = name, field_ty = rust_fieldty));
925+
"#, ty = ty, field = name));
927926
}
928927
t!(writeln!(self.rust, r#"
929928
}}
@@ -1194,6 +1193,7 @@ impl<'a> Generator<'a> {
11941193
ast::ExprPath(_, ref path) => {
11951194
path.segments.last().unwrap().identifier.to_string()
11961195
}
1196+
ast::ExprCast(ref e, _) => self.expr2str(e),
11971197
_ => panic!("unknown expr: {:?}", e),
11981198
}
11991199
}

ctest/testcrate/src/t1.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
typedef int32_t T1Foo;
44

5+
#define T1N 5
6+
57
struct T1Bar {
68
int32_t a;
79
uint32_t b;
810
T1Foo c;
911
uint8_t d;
12+
int64_t e[T1N];
1013
};
1114

1215
struct T1Baz {
@@ -22,3 +25,4 @@ void T1e(unsigned, const struct T1Bar*);
2225
void T1f(void);
2326

2427
#define T1C 4
28+

ctest/testcrate/src/t1.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ use libc::*;
44

55
pub type T1Foo = i32;
66

7+
pub const T1N: i32 = 5;
8+
79
#[repr(C)]
810
pub struct T1Bar {
911
pub a: i32,
1012
pub b: u32,
1113
pub c: T1Foo,
1214
pub d: u8,
15+
pub e: [i64; T1N as usize],
1316
}
1417

1518
#[repr(C)]

0 commit comments

Comments
 (0)