Skip to content

Commit 1129431

Browse files
committed
ir: Don't parse constructors twice.
1 parent 59987f1 commit 1129431

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

libbindgen/src/ir/function.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,13 @@ impl FunctionSig {
186186
};
187187

188188
let is_method = cursor.kind() == CXCursor_CXXMethod;
189+
let is_constructor = cursor.kind() == CXCursor_Constructor;
190+
if is_constructor && cursor.lexical_parent() != cursor.semantic_parent() {
191+
// Only parse constructors once.
192+
return Err(ParseError::Continue);
193+
}
189194

190-
if is_method || cursor.kind() == CXCursor_Constructor {
195+
if is_method || is_constructor {
191196
let is_const = is_method && cursor.method_is_const();
192197
let is_virtual = is_method && cursor.method_is_virtual();
193198
let is_static = is_method && cursor.method_is_static();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Copy, Clone)]
9+
pub struct Foo<T> {
10+
pub _address: u8,
11+
pub _phantom_0: ::std::marker::PhantomData<T>,
12+
}
13+
#[repr(C)]
14+
#[derive(Debug, Copy)]
15+
pub struct Bar {
16+
pub _address: u8,
17+
}
18+
#[test]
19+
fn bindgen_test_layout_Bar() {
20+
assert_eq!(::std::mem::size_of::<Bar>() , 1usize);
21+
assert_eq!(::std::mem::align_of::<Bar>() , 1usize);
22+
}
23+
extern "C" {
24+
#[link_name = "_ZN3BarC1Ev"]
25+
pub fn Bar_Bar(this: *mut Bar);
26+
}
27+
impl Clone for Bar {
28+
fn clone(&self) -> Self { *self }
29+
}
30+
impl Bar {
31+
#[inline]
32+
pub unsafe fn new() -> Self {
33+
let mut __bindgen_tmp = ::std::mem::uninitialized();
34+
Bar_Bar(&mut __bindgen_tmp);
35+
__bindgen_tmp
36+
}
37+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
template<typename T>
3+
class Foo {
4+
public:
5+
Foo();
6+
};
7+
8+
class Bar {
9+
public:
10+
Bar();
11+
};
12+
13+
template<typename T>
14+
Foo<T>::Foo() {
15+
}
16+
17+
inline
18+
Bar::Bar() {
19+
}

0 commit comments

Comments
 (0)