summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gen.rs9
-rw-r--r--src/types.rs24
-rw-r--r--tests/expectations/crtp.rs29
-rw-r--r--tests/headers/crtp.hpp14
4 files changed, 67 insertions, 9 deletions
diff --git a/src/gen.rs b/src/gen.rs
index e046ea12..83406eac 100644
--- a/src/gen.rs
+++ b/src/gen.rs
@@ -480,8 +480,7 @@ fn gen_globals(mut ctx: &mut GenCtx,
(Some(l), Some(lg)) if l.size == lg.size => {},
(None, None) => {},
_ => {
- // XXX real logger
- println!("warning: substituted type for {} does not match its size", g.name());
+ warn!("warning: substituted type for {} does not match its size", g.name());
}
}
g = substituted;
@@ -492,7 +491,7 @@ fn gen_globals(mut ctx: &mut GenCtx,
let mut pending_translations = std::mem::replace(&mut ctx.current_module_mut().translations, HashMap::new());
for (name, g) in pending_translations.drain() {
- println!("warning: generating definition for not found type: {}", name);
+ warn!("warning: generating definition for not found type: {}", name);
gen_global(ctx, g, &mut defs);
}
@@ -983,7 +982,7 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: &str, ci: CompInfo) -> Vec<P<ast::Item>
let is_translatable = cty_is_translatable(&f_ty);
if !is_translatable || f_ty.is_opaque() {
if !is_translatable {
- println!("{}::{} not translatable, void: {}", ci.name, f.name, f_ty == TVoid);
+ warn!("{}::{} not translatable, void: {}", ci.name, f.name, f_ty == TVoid);
}
if let Some(layout) = f_ty.layout() {
fields.push(mk_blob_field(ctx, &f_name, &layout));
@@ -1326,7 +1325,7 @@ fn enum_size_to_rust_type_name(signed: bool, size: usize) -> &'static str {
(true, 8) => "i64",
(false, 8) => "u64",
_ => {
- println!("invalid enum decl: signed: {}, size: {}", signed, size);
+ warn!("invalid enum decl: signed: {}, size: {}", signed, size);
"i32"
}
}
diff --git a/src/types.rs b/src/types.rs
index a1d574f2..8036a75f 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -440,9 +440,12 @@ pub struct CompInfo {
pub was_unnamed: bool,
/// Set of static vars declared inside this class.
pub vars: Vec<Global>,
- /// Used to detect if we've run in a can_derive_debug cycle while
- /// cycling around the template arguments.
+ /// Used to detect if we've run in a can_derive_debug cycle while cycling
+ /// around the template arguments.
detect_derive_debug_cycle: Cell<bool>,
+ /// Used to detect if we've run in a has_destructor cycle while cycling
+ /// around the template arguments.
+ detect_has_destructor_cycle: Cell<bool>,
}
static mut UNNAMED_COUNTER: u32 = 0;
@@ -490,6 +493,7 @@ impl CompInfo {
has_non_type_template_params: false,
was_unnamed: was_unnamed,
detect_derive_debug_cycle: Cell::new(false),
+ detect_has_destructor_cycle: Cell::new(false),
}
}
@@ -548,7 +552,15 @@ impl CompInfo {
}
pub fn has_destructor(&self) -> bool {
- self.has_destructor || match self.kind {
+ if self.detect_has_destructor_cycle.get() {
+ warn!("Cycle detected looking for destructors: {}!", self.name);
+ // Assume no destructor, since we don't have an explicit one.
+ return false;
+ }
+
+ self.detect_has_destructor_cycle.set(true);
+
+ let has_destructor = self.has_destructor || match self.kind {
CompKind::Union => false,
CompKind::Struct => {
// NB: We can't rely on a type with type parameters
@@ -570,7 +582,11 @@ impl CompInfo {
_ => false,
})
}
- }
+ };
+
+ self.detect_has_destructor_cycle.set(false);
+
+ has_destructor
}
pub fn can_derive_copy(&self) -> bool {
diff --git a/tests/expectations/crtp.rs b/tests/expectations/crtp.rs
new file mode 100644
index 00000000..c6964524
--- /dev/null
+++ b/tests/expectations/crtp.rs
@@ -0,0 +1,29 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct Base<T> {
+ pub _phantom0: ::std::marker::PhantomData<T>,
+}
+#[repr(C)]
+#[derive(Debug, Copy)]
+pub struct Derived {
+ pub _base: Base<Derived>,
+}
+impl ::std::clone::Clone for Derived {
+ fn clone(&self) -> Self { *self }
+}
+#[repr(C)]
+#[derive(Debug)]
+pub struct BaseWithDestructor<T> {
+ pub _phantom0: ::std::marker::PhantomData<T>,
+}
+#[repr(C)]
+#[derive(Debug)]
+pub struct DerivedFromBaseWithDestructor {
+ pub _base: BaseWithDestructor<DerivedFromBaseWithDestructor>,
+}
diff --git a/tests/headers/crtp.hpp b/tests/headers/crtp.hpp
new file mode 100644
index 00000000..3a3eeb60
--- /dev/null
+++ b/tests/headers/crtp.hpp
@@ -0,0 +1,14 @@
+// bindgen-flags: -no-type-renaming
+
+template<class T>
+class Base {};
+
+class Derived : public Base<Derived> {};
+
+template<class T>
+class BaseWithDestructor {
+ ~BaseWithDestructor();
+};
+
+class DerivedFromBaseWithDestructor :
+ public BaseWithDestructor<DerivedFromBaseWithDestructor> {};