codegen: Make the cyclic typedef name detection catch more cases.

By looking through typedefs, we also catch more complex cases like the ones that
appear on Android's stdlib.

Fixes #946
This commit is contained in:
Emilio Cobos Álvarez 2018-01-29 15:13:53 +01:00
parent 8725aea78f
commit 450970dcc1
No known key found for this signature in database
GPG Key ID: 056B727BB9C1027C
3 changed files with 40 additions and 8 deletions

View File

@ -614,14 +614,20 @@ impl CodeGenerator for Type {
.resolve(ctx);
let name = item.canonical_name(ctx);
// Try to catch the common pattern:
//
// typedef struct foo { ... } foo;
//
// here.
//
if inner_item.canonical_name(ctx) == name {
return;
{
let through_type_aliases = inner.into_resolver()
.through_type_refs()
.through_type_aliases()
.resolve(ctx);
// Try to catch the common pattern:
//
// typedef struct foo { ... } foo;
//
// here, and also other more complex cases like #946.
if through_type_aliases.canonical_name(ctx) == name {
return;
}
}
// If this is a known named type, disallow generating anything

View File

@ -0,0 +1,21 @@
/* automatically generated by rust-bindgen */
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct foo {}
#[test]
fn bindgen_test_layout_foo() {
assert_eq!(
::std::mem::size_of::<foo>(),
0usize,
concat!("Size of: ", stringify!(foo))
);
assert_eq!(
::std::mem::align_of::<foo>(),
1usize,
concat!("Alignment of ", stringify!(foo))
);
}
pub type bar = foo;

View File

@ -0,0 +1,5 @@
struct foo { };
typedef struct foo bar;
typedef bar foo;