diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2016-12-30 09:03:55 -0800 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2016-12-30 09:03:55 -0800 |
commit | 50b5845c239e2a9ae8b9594bcbedf91174460e84 (patch) | |
tree | a8479784edda36049f7f6adef6d0aecaf985ced0 /libbindgen/src | |
parent | 291174b20f1f8d2aa65a133bac0a2ba77148503e (diff) |
Relax opaque layout trait deriving and take alignment into account
Diffstat (limited to 'libbindgen/src')
-rw-r--r-- | libbindgen/src/ir/comp.rs | 9 | ||||
-rw-r--r-- | libbindgen/src/ir/layout.rs | 7 |
2 files changed, 9 insertions, 7 deletions
diff --git a/libbindgen/src/ir/comp.rs b/libbindgen/src/ir/comp.rs index 3a0f5872..0af8a99e 100644 --- a/libbindgen/src/ir/comp.rs +++ b/libbindgen/src/ir/comp.rs @@ -3,13 +3,12 @@ use clang; use parse::{ClangItemParser, ParseError}; use std::cell::Cell; -use std::cmp; use super::annotations::Annotations; use super::context::{BindgenContext, ItemId}; use super::derive::{CanDeriveCopy, CanDeriveDebug}; use super::item::Item; use super::layout::Layout; -use super::ty::{RUST_DERIVE_IN_ARRAY_LIMIT, Type}; +use super::ty::Type; use super::type_collector::{ItemSet, TypeCollector}; /// The kind of compound type. @@ -826,9 +825,9 @@ impl CanDeriveDebug for CompInfo { return false; } - let layout = layout.unwrap_or_else(Layout::zero); - let size_divisor = cmp::max(1, layout.align); - return layout.size / size_divisor <= RUST_DERIVE_IN_ARRAY_LIMIT; + return layout.unwrap_or_else(Layout::zero) + .opaque() + .can_derive_debug(ctx, ()); } self.detect_derive_debug_cycle.set(true); diff --git a/libbindgen/src/ir/layout.rs b/libbindgen/src/ir/layout.rs index 075f42c9..3a07f7e8 100644 --- a/libbindgen/src/ir/layout.rs +++ b/libbindgen/src/ir/layout.rs @@ -1,5 +1,6 @@ //! Intermediate representation for the physical layout of some type. +use std::cmp; use super::context::BindgenContext; use super::derive::{CanDeriveCopy, CanDeriveDebug}; use super::ty::RUST_DERIVE_IN_ARRAY_LIMIT; @@ -49,7 +50,8 @@ impl CanDeriveDebug for Opaque { type Extra = (); fn can_derive_debug(&self, _: &BindgenContext, _: ()) -> bool { - self.0.size < RUST_DERIVE_IN_ARRAY_LIMIT + let size_divisor = cmp::max(1, self.0.align); + self.0.size / size_divisor <= RUST_DERIVE_IN_ARRAY_LIMIT } } @@ -57,7 +59,8 @@ impl<'a> CanDeriveCopy<'a> for Opaque { type Extra = (); fn can_derive_copy(&self, _: &BindgenContext, _: ()) -> bool { - self.0.size < RUST_DERIVE_IN_ARRAY_LIMIT + let size_divisor = cmp::max(1, self.0.align); + self.0.size / size_divisor <= RUST_DERIVE_IN_ARRAY_LIMIT } fn can_derive_copy_in_array(&self, ctx: &BindgenContext, _: ()) -> bool { |