Skip to content

Commit

Permalink
Fix generates tests with C function conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Nov 25, 2018
1 parent 07176ac commit 96ca3fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ impl<'a> Generator<'a> {
uint64_t __test_offset_{ty}_{rust_field}(void) {{
return offsetof({cstructty}, {c_field});
}}
uint64_t __test_size_{ty}_{rust_field}(void) {{
uint64_t __test_fsize_{ty}_{rust_field}(void) {{
{cstructty}* foo = NULL;
return sizeof(foo->{c_field});
}}
Expand All @@ -1040,15 +1040,15 @@ impl<'a> Generator<'a> {
r#"
extern {{
fn __test_offset_{ty}_{field}() -> u64;
fn __test_size_{ty}_{field}() -> u64;
fn __test_fsize_{ty}_{field}() -> u64;
}}
unsafe {{
let foo = 0 as *mut {ty};
same(offset_of!({ty}, {field}),
__test_offset_{ty}_{field}(),
"field offset {field} of {ty}");
same(mem::size_of_val(&(*foo).{field}) as u64,
__test_size_{ty}_{field}(),
__test_fsize_{ty}_{field}(),
"field size {field} of {ty}");
}}
"#,
Expand Down
8 changes: 8 additions & 0 deletions testcrate/src/t1.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,11 @@ struct Q {
uint8_t** q1;
uint8_t q2;
};

struct T1_conflict_foo {
int a;
};

struct T1_conflict{
int foo;
};
10 changes: 10 additions & 0 deletions testcrate/src/t1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,13 @@ pub struct Q {
pub q1: *mut *mut u8,
pub q2: u8,
}

#[repr(C)]
pub struct T1_conflict_foo {
a: i32,
}

#[repr(C)]
pub struct T1_conflict {
pub foo: i32,
}

0 comments on commit 96ca3fa

Please sign in to comment.