diff options
156 files changed, 7319 insertions, 848 deletions
diff --git a/.travis.yml b/.travis.yml index 47af4eeb..4dd55c86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,17 +25,9 @@ cache: before_install: . ./ci/before_install.sh script: - - cargo test --features "$BINDGEN_FEATURES assert_no_dangling_items" - - cargo test --release --features "$BINDGEN_FEATURES assert_no_dangling_items" - - git add -A - - git diff @ - - git diff-index --quiet HEAD - - cargo build --features "$BINDGEN_FEATURES docs_" - - cd tests/expectations - - cargo test - - cd ../../bindgen-integration - - cargo test --features "$BINDGEN_FEATURES" - - cargo test --release --features "$BINDGEN_FEATURES" + - ./ci/assert-rustfmt.sh + - BINDGEN_FEATURES="$BINDGEN_FEATURES" ./ci/assert-docs.sh + - BINDGEN_FEATURES="$BINDGEN_FEATURES" ./ci/test.sh notifications: webhooks: http://build.servo.org:54856/travis diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cfcee653..9ee1b4ac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -114,24 +114,26 @@ $ cargo test -p tests_expectations ## Automatic code formatting -There's a `rustfmt.toml` file in the repo. Ideally changes should be consistent -with the style, though that's not enforced right now. +We use [`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) to enforce a +consistent code style across the whole `bindgen` code base. This is enforced in +CI, and your pull requests will get automatically rejected if you don't +re-format with the latest `rustfmt` before pushing. -[`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) can catch and fix -automatically all the coding style issues it finds. In order to use it it -suffices to do: +You can install the latest version of `rustfmt` with this command: ``` -$ cargo fmt +$ cargo install -f rustfmt ``` -For it to work, you need to have `rustfmt` installed. To do so: +Ensure that `~/.cargo/bin` is on your path. + +Once that is taken care of, you can (re)format all code by running this command: ``` -$ cargo install rustfmt +$ cargo fmt ``` -And ensure `~/.cargo/bin` is on your path. +The code style is described in the `rustfmt.toml` file in top level of the repo. ## Debug Logging @@ -1,6 +1,6 @@ [root] name = "bindgen" -version = "0.20.5" +version = "0.21.2" dependencies = [ "aster 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -13,9 +13,11 @@ name = "bindgen" readme = "README.md" repository = "https://github.com/servo/rust-bindgen" documentation = "https://docs.rs/bindgen" -version = "0.20.5" +version = "0.21.2" build = "build.rs" +exclude = ["tests/headers", "tests/expectations", "bindgen-integration", "ci"] + [badges] travis-ci = { repository = "servo/rust-bindgen" } diff --git a/ci/assert-docs.sh b/ci/assert-docs.sh new file mode 100755 index 00000000..aa4b90ac --- /dev/null +++ b/ci/assert-docs.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -xeu +cd "$(dirname "$0")/.." + +cargo build --features "$BINDGEN_FEATURES docs_" diff --git a/ci/assert-no-diff.sh b/ci/assert-no-diff.sh new file mode 100755 index 00000000..14f2aa21 --- /dev/null +++ b/ci/assert-no-diff.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -xeu +cd "$(dirname "$0")/.." + +git add -u +git diff @ +git diff-index --quiet HEAD diff --git a/ci/assert-rustfmt.sh b/ci/assert-rustfmt.sh new file mode 100755 index 00000000..bd268600 --- /dev/null +++ b/ci/assert-rustfmt.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -xeu +cd "$(dirname "$0")/.." + +# Ensure we have the most up-to-date `rustfmt`. +cargo install -f rustfmt + +# Run `rustfmt` on the crate! If `rustfmt` can't make a long line shorter, it +# prints an error and exits non-zero, so tell it to kindly shut its yapper and +# make sure it doesn't cause us to exit this whole script non-zero. +cargo fmt --quiet || true + +# Exit non-zero if this resulted in any diffs. +./ci/assert-no-diff.sh + diff --git a/ci/test.sh b/ci/test.sh new file mode 100755 index 00000000..9bfccfd8 --- /dev/null +++ b/ci/test.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -xeu +cd "$(dirname "$0")/.." + +# Regenerate the test headers' bindings in debug and release modes, and assert +# that we always get the expected generated bindings. + +cargo test --features "$BINDGEN_FEATURES assert_no_dangling_items" +./ci/assert-no-diff.sh + +cargo test --release --features "$BINDGEN_FEATURES assert_no_dangling_items" +./ci/assert-no-diff.sh + +# Now test the expectations' size and alignment tests. + +pushd tests/expectations +cargo test +cargo test --release +popd + +# And finally, test our example bindgen + build.rs integration template project. + +cd bindgen-integration +cargo test --features "$BINDGEN_FEATURES" +cargo test --release --features "$BINDGEN_FEATURES" diff --git a/src/chooser.rs b/src/chooser.rs index d7a20771..29090a42 100644 --- a/src/chooser.rs +++ b/src/chooser.rs @@ -1,7 +1,7 @@ //! A public API for more fine-grained customization of bindgen behavior. +pub use ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue}; pub use ir::int::IntKind; -pub use ir::enum_ty::{EnumVariantValue, EnumVariantCustomBehavior}; use std::fmt; use std::panic::UnwindSafe; diff --git a/src/clang.rs b/src/clang.rs index a40abfca..ffe9d5d0 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -122,20 +122,37 @@ impl Cursor { } /// Return the number of template arguments used by this cursor's referent, - /// if the referent is either a template specialization or - /// declaration. Returns -1 otherwise. + /// if the referent is either a template specialization or declaration. + /// Returns `None` otherwise. /// /// NOTE: This may not return `Some` for some non-fully specialized /// templates, see #193 and #194. pub fn num_template_args(&self) -> Option<u32> { - let n: c_int = unsafe { clang_Cursor_getNumTemplateArguments(self.x) }; + // XXX: `clang_Type_getNumTemplateArguments` is sort of reliable, while + // `clang_Cursor_getNumTemplateArguments` is totally unreliable. + // Therefore, try former first, and only fallback to the latter if we + // have to. + self.cur_type().num_template_args() + .or_else(|| { + let n: c_int = unsafe { + clang_Cursor_getNumTemplateArguments(self.x) + }; - if n >= 0 { - Some(n as u32) - } else { - debug_assert_eq!(n, -1); - None - } + if n >= 0 { + Some(n as u32) + } else { + debug_assert_eq!(n, -1); + None + } + }) + .or_else(|| { + let canonical = self.canonical(); + if canonical != *self { + canonical.num_template_args() + } else { + None + } + }) } /// Get a cursor pointing to this referent's containing translation unit. @@ -208,7 +225,8 @@ impl Cursor { /// Is the referent a fully specialized template specialization without any /// remaining free template arguments? pub fn is_fully_specialized_template(&self) -> bool { - self.is_template_specialization() && self.num_template_args().unwrap_or(0) > 0 + self.is_template_specialization() && + self.num_template_args().unwrap_or(0) > 0 } /// Is the referent a template specialization that still has remaining free @@ -349,13 +367,11 @@ impl Cursor { pub fn contains_cursor(&self, kind: CXCursorKind) -> bool { let mut found = false; - self.visit(|c| { - if c.kind() == kind { - found = true; - CXChildVisit_Break - } else { - CXChildVisit_Continue - } + self.visit(|c| if c.kind() == kind { + found = true; + CXChildVisit_Break + } else { + CXChildVisit_Continue }); found @@ -483,6 +499,17 @@ impl Cursor { unsafe { clang_CXXField_isMutable(self.x) != 0 } } + /// Get the offset of the field represented by the Cursor. + pub fn offset_of_field(&self) -> Result<usize, LayoutError> { + let offset = unsafe { clang_Cursor_getOffsetOfField(self.x) }; + + if offset < 0 { + Err(LayoutError::from(offset as i32)) + } else { + Ok(offset as usize) + } + } + /// Is this cursor's referent a member function that is declared `static`? pub fn method_is_static(&self) -> bool { unsafe { clang_CXXMethod_isStatic(self.x) != 0 } @@ -507,6 +534,14 @@ impl Cursor { pub fn evaluate(&self) -> Option<EvalResult> { EvalResult::new(*self) } + + /// Return the result type for this cursor + pub fn ret_type(&self) -> Option<Type> { + let rt = Type { + x: unsafe { clang_getCursorResultType(self.x) }, + }; + if rt.is_valid() { Some(rt) } else { None } + } } extern "C" fn visit_children<Visitor>(cur: CXCursor, @@ -673,22 +708,28 @@ impl Type { Ok(Layout::new(size, align)) } - /// If this type is a class template specialization, return its - /// template arguments. Otherwise, return None. - pub fn template_args(&self) -> Option<TypeTemplateArgIterator> { + /// Get the number of template arguments this type has, or `None` if it is + /// not some kind of template. + pub fn num_template_args(&self) -> Option<u32> { let n = unsafe { clang_Type_getNumTemplateArguments(self.x) }; if n >= 0 { - Some(TypeTemplateArgIterator { - x: self.x, - length: n as u32, - index: 0, - }) + Some(n as u32) } else { debug_assert_eq!(n, -1); None } } + /// If this type is a class template specialization, return its + /// template arguments. Otherwise, return None. + pub fn template_args(&self) -> Option<TypeTemplateArgIterator> { + self.num_template_args().map(|n| TypeTemplateArgIterator { + x: self.x, + length: n, + index: 0, + }) + } + /// Given that this type is a pointer type, return the type that it points /// to. pub fn pointee_type(&self) -> Option<Type> { @@ -787,12 +828,14 @@ impl Type { // Yep, the spelling of this containing type-parameter is extremely // nasty... But can happen in <type_traits>. Unfortunately I couldn't // reduce it enough :( - !self.spelling().contains("type-parameter") && - self.template_args() - .map_or(false, |mut args| { - args.len() > 0 && - !args.any(|t| t.spelling().contains("type-parameter")) - }) + self.template_args().map_or(false, |args| { + args.len() > 0 + }) && match self.declaration().kind() { + CXCursor_ClassTemplatePartialSpecialization | + CXCursor_TypeAliasTemplateDecl | + CXCursor_TemplateTemplateParameter => false, + _ => true, + } } } @@ -846,8 +889,8 @@ impl SourceLocation { &mut col, &mut off); (File { - x: file, - }, + x: file, + }, line as usize, col as usize, off as usize) @@ -1273,21 +1316,188 @@ pub fn type_to_str(x: CXTypeKind) -> String { /// Dump the Clang AST to stdout for debugging purposes. pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { - fn print_indent(depth: isize, s: &str) { + fn print_indent<S: AsRef<str>>(depth: isize, s: S) { for _ in 0..depth { - print!("\t"); + print!(" "); + } + println!("{}", s.as_ref()); + } + + fn print_cursor<S: AsRef<str>>(depth: isize, prefix: S, c: &Cursor) { + let prefix = prefix.as_ref(); + print_indent(depth, + format!(" {}kind = {}", prefix, kind_to_str(c.kind()))); + print_indent(depth, + format!(" {}spelling = \"{}\"", prefix, c.spelling())); + print_indent(depth, format!(" {}location = {}", prefix, c.location())); + print_indent(depth, + format!(" {}is-definition? {}", + prefix, + c.is_definition())); + print_indent(depth, + format!(" {}is-declaration? {}", + prefix, + c.is_declaration())); + print_indent(depth, + format!(" {}is-anonymous? {}", prefix, c.is_anonymous())); + print_indent(depth, + format!(" {}is-inlined-function? {}", + prefix, + c.is_inlined_function())); + + let templ_kind = c.template_kind(); + if templ_kind != CXCursor_NoDeclFound { + print_indent(depth, + format!(" {}template-kind = {}", + prefix, + kind_to_str(templ_kind))); + } + if let Some(usr) = c.usr() { + print_indent(depth, format!(" {}usr = \"{}\"", prefix, usr)); + } + if let Ok(num) = c.num_args() { + print_indent(depth, format!(" {}number-of-args = {}", prefix, num)); + } + if let Some(num) = c.num_template_args() { + print_indent(depth, + format!(" {}number-of-template-args = {}", + prefix, + num)); + } + if let Some(width) = c.bit_width() { + print_indent(depth, format!(" {}bit-width = {}", prefix, width)); + } + if let Some(ty) = c.enum_type() { + print_indent(depth, + format!(" {}enum-type = {}", + prefix, + type_to_str(ty.kind()))); + } + if let Some(val) = c.enum_val_signed() { + print_indent(depth, format!(" {}enum-val = {}", prefix, val)); + } + if let Some(ty) = c.typedef_type() { + print_indent(depth, + format!(" {}typedef-type = {}", + prefix, + type_to_str(ty.kind()))); + } + if let Some(ty) = c.ret_type() { + print_indent(depth, format!(" {}ret-type = {}", prefix, type_to_str(ty.kind()))); + } + + if let Some(refd) = c.referenced() { + if refd != *c { + println!(""); + print_cursor(depth, + String::from(prefix) + "referenced.", + &refd); + print_cursor(depth, String::from(prefix) + "referenced.", &refd); + } + } + + let canonical = c.canonical(); + if canonical != *c { + println!(""); + print_cursor(depth, + String::from(prefix) + "canonical.", + &canonical); + print_cursor(depth, String::from(prefix) + "canonical.", &canonical); + } + + if let Some(specialized) = c.specialized() { + if specialized != *c { + println!(""); + print_cursor(depth, + String::from(prefix) + "specialized.", + &specialized); + print_cursor(depth, String::from(prefix) + "specialized.", &specialized); + } } - println!("{}", s); } - print_indent(depth, - &format!("(kind: {}, spelling: {}, type: {}", - kind_to_str(c.kind()), - c.spelling(), - type_to_str(c.cur_type().kind()))); + fn print_type<S: AsRef<str>>(depth: isize, prefix: S, ty: &Type) { + let prefix = prefix.as_ref(); + + let kind = ty.kind(); + print_indent(depth, format!(" {}kind = {}", prefix, type_to_str(kind))); + if kind == CXType_Invalid { + return; + } + + print_indent(depth, + format!(" {}spelling = \"{}\"", prefix, ty.spelling())); + let num_template_args = + unsafe { clang_Type_getNumTemplateArguments(ty.x) }; + if num_template_args >= 0 { + print_indent(depth, + format!(" {}number-of-template-args = {}", + prefix, + num_template_args)); + } + if let Some(num) = ty.num_elements() { + print_indent(depth, + format!(" {}number-of-elements = {}", prefix, num)); + } + print_indent(depth, + format!(" {}is-variadic? {}", prefix, ty.is_variadic())); + + let canonical = ty.canonical_type(); + if canonical != *ty { + println!(""); + print_type(depth, String::from(prefix) + "canonical.", &canonical); + } + + if let Some(pointee) = ty.pointee_type() { + if pointee != *ty { + println!(""); + print_type(depth, String::from(prefix) + "pointee.", &pointee); + } + } + + if let Some(elem) = ty.elem_type() { + if elem != *ty { + println!(""); + print_type(depth, String::from(prefix) + "elements.", &elem); + } + } + + if let Some(ret) = ty.ret_type() { + if ret != *ty { + println!(""); + print_type(depth, String::from(prefix) + "return.", &ret); + } + } + + let named = ty.named(); + if named != *ty && named.is_valid() { + println!(""); + print_type(depth, String::from(prefix) + "named.", &named); + } + } + + print_indent(depth, "("); + print_cursor(depth, "", c); + + println!(""); + let ty = c.cur_type(); + print_type(depth, "type.", &ty); + + let declaration = ty.declaration(); + if declaration != *c && declaration.kind() != CXCursor_NoDeclFound { + println!(""); + print_cursor(depth, "type.declaration.", &declaration); + } // Recurse. - c.visit(|s| ast_dump(&s, depth + 1)); + let mut found_children = false; + c.visit(|s| { + if !found_children { + println!(""); + found_children = true; + } + ast_dump(&s, depth + 1) + }); print_indent(depth, ")"); @@ -1321,14 +1531,12 @@ impl EvalResult { // unexposed type. Our solution is to just flat out ban all // `CXType_Unexposed` from evaluation. let mut found_cant_eval = false; - cursor.visit(|c| { - if c.kind() == CXCursor_TypeRef && - c.cur_type().kind() == CXType_Unexposed { - found_cant_eval = true; - CXChildVisit_Break - } else { - CXChildVisit_Recurse - } + cursor.visit(|c| if c.kind() == CXCursor_TypeRef && + c.cur_type().kind() == CXType_Unexposed { + found_cant_eval = true; + CXChildVisit_Break + } else { + CXChildVisit_Recurse }); if found_cant_eval { return None; diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 9dd3b6b9..0fdfaad0 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1,5 +1,8 @@ mod helpers; +mod struct_layout; +use self::helpers::{BlobTyBuilder, attributes}; +use self::struct_layout::StructLayoutTracker; use aster; use ir::annotations::FieldAccessorKind; @@ -17,10 +20,10 @@ use ir::objc::ObjCInterface; use ir::ty::{Type, TypeKind}; use ir::type_collector::ItemSet; use ir::var::Var; -use self::helpers::{BlobTyBuilder, attributes}; use std::borrow::Cow; use std::cell::Cell; +use std::cmp; use std::collections::{HashSet, VecDeque}; use std::collections::hash_map::{Entry, HashMap}; use std::fmt::Write; @@ -301,7 +304,8 @@ impl CodeGenerator for Item { _extra: &()) { if self.is_hidden(ctx) || result.seen(self.id()) { debug!("<Item as CodeGenerator>::codegen: Ignoring hidden or seen: \ - self = {:?}", self); + self = {:?}", + self); return; } @@ -376,7 +380,7 @@ impl CodeGenerator for Module { }; if !ctx.options().enable_cxx_namespaces || - (self.is_inline() && !ctx.options().conservative_inline_namespaces) { + (self.is_inline() && !ctx.options().conservative_inline_namespaces) { codegen_self(result, &mut false); return; } @@ -574,11 +578,13 @@ impl CodeGenerator for Type { // with invalid template parameters, and at least this way // they can be replaced, instead of generating plain invalid // code. - let inner_canon_type = - inner_item.expect_type().canonical_type(ctx); + let inner_canon_type = inner_item.expect_type() + .canonical_type(ctx); if inner_canon_type.is_invalid_named_type() { warn!("Item contained invalid named type, skipping: \ - {:?}, {:?}", item, inner_item); + {:?}, {:?}", + item, + inner_item); return; } } @@ -597,22 +603,25 @@ impl CodeGenerator for Type { let simple_enum_path = match inner_rust_type.node { ast::TyKind::Path(None, ref p) => { if applicable_template_args.is_empty() && - inner_item.expect_type().canonical_type(ctx).is_enum() && - p.segments.iter().all(|p| p.parameters.is_none()) { + inner_item.expect_type() + .canonical_type(ctx) + .is_enum() && + p.segments.iter().all(|p| p.parameters.is_none()) { Some(p.clone()) } else { None } - }, + } _ => None, }; let typedef = if let Some(mut p) = simple_enum_path { for ident in top_level_path(ctx, item).into_iter().rev() { - p.segments.insert(0, ast::PathSegment { - identifier: ident, - parameters: None, - }); + p.segments.insert(0, + ast::PathSegment { + identifier: ident, + parameters: None, + }); } typedef.use_().build(p).as_(rust_name) } else { @@ -622,7 +631,8 @@ impl CodeGenerator for Type { if template_arg.is_named() { if template_arg.is_invalid_named_type() { warn!("Item contained invalid template \ - parameter: {:?}", item); + parameter: {:?}", + item); return; } generics = @@ -716,9 +726,9 @@ impl<'a> Bitfield<'a> { fn codegen_fields(self, ctx: &BindgenContext, fields: &mut Vec<ast::StructField>, - methods: &mut Vec<ast::ImplItem>) { + methods: &mut Vec<ast::ImplItem>) + -> Layout { use aster::struct_field::StructFieldBuilder; - use std::cmp; let mut total_width = self.fields .iter() .fold(0u32, |acc, f| acc + f.bitfield().unwrap()); @@ -729,10 +739,9 @@ impl<'a> Bitfield<'a> { debug_assert_eq!(total_width % 8, 0); let total_width_in_bytes = total_width as usize / 8; - let bitfield_type = - BlobTyBuilder::new(Layout::new(total_width_in_bytes, - total_width_in_bytes)) - .build(); + let bitfield_layout = Layout::new(total_width_in_bytes, + total_width_in_bytes); + let bitfield_type = BlobTyBuilder::new(bitfield_layout).build(); let field_name = format!("_bitfield_{}", self.index); let field_ident = ctx.ext_cx().ident_of(&field_name); let field = StructFieldBuilder::named(&field_name) @@ -798,6 +807,8 @@ impl<'a> Bitfield<'a> { methods.extend(items.into_iter()); offset += width; } + + bitfield_layout } } @@ -823,7 +834,8 @@ impl CodeGenerator for CompInfo { // generate tuple struct if struct or union is a forward declaration, // skip for now if template parameters are needed. - if self.is_forward_declaration() && applicable_template_args.is_empty(){ + if self.is_forward_declaration() && + applicable_template_args.is_empty() { let struct_name = item.canonical_name(ctx); let struct_name = ctx.rust_ident_raw(&struct_name); let tuple_struct = quote_item!(ctx.ext_cx(), @@ -854,8 +866,10 @@ impl CodeGenerator for CompInfo { let item = quote_item!(ctx.ext_cx(), #[test] fn $fn_name() { - assert_eq!($size_of_expr, $size); - assert_eq!($align_of_expr, $align); + assert_eq!($size_of_expr, $size, + concat!("Size of template specialization: ", stringify!($ident))); + assert_eq!($align_of_expr, $align, + concat!("Alignment of template specialization: ", stringify!($ident))); }) .unwrap(); result.push(item); @@ -932,6 +946,7 @@ impl CodeGenerator for CompInfo { // Also, we need to generate the vtable in such a way it "inherits" from // the parent too. let mut fields = vec![]; + let mut struct_layout = StructLayoutTracker::new(ctx, self); if self.needs_explicit_vtable(ctx) { let vtable = Vtable::new(item.id(), self.methods(), self.base_members()); @@ -943,6 +958,8 @@ impl CodeGenerator for CompInfo { .pub_() .build_ty(vtable_type); + struct_layout.saw_vtable(); + fields.push(vtable_field); } @@ -977,6 +994,8 @@ impl CodeGenerator for CompInfo { format!("_base_{}", i) }; + struct_layout.saw_base(base_ty); + let field = StructFieldBuilder::named(field_name) .pub_() .build_ty(inner); @@ -1012,10 +1031,12 @@ impl CodeGenerator for CompInfo { // Try to catch a bitfield contination early. if let (Some(ref mut bitfield_width), Some(width)) = - (current_bitfield_width, field.bitfield()) { + (current_bitfield_width, field.bitfield()) { let layout = current_bitfield_layout.unwrap(); debug!("Testing bitfield continuation {} {} {:?}", - *bitfield_width, width, layout); + *bitfield_width, + width, + layout); if *bitfield_width + width <= (layout.size * 8) as u32 { *bitfield_width += width; current_bitfield_fields.push(field); @@ -1029,8 +1050,12 @@ impl CodeGenerator for CompInfo { let bitfield_fields = mem::replace(&mut current_bitfield_fields, vec![]); bitfield_count += 1; - Bitfield::new(bitfield_count, bitfield_fields) + let bitfield_layout = Bitfield::new(bitfield_count, + bitfield_fields) .codegen_fields(ctx, &mut fields, &mut methods); + + struct_layout.saw_bitfield(bitfield_layout); + current_bitfield_width = None; current_bitfield_layout = None; } @@ -1061,7 +1086,8 @@ impl CodeGenerator for CompInfo { } else { quote_ty!(ctx.ext_cx(), __BindgenUnionField<$ty>) } - } else if let Some(item) = field_ty.is_incomplete_array(ctx) { + } else if let Some(item) = + field_ty.is_incomplete_array(ctx) { result.saw_incomplete_array(); let inner = item.to_rust_ty(ctx); @@ -1089,6 +1115,11 @@ impl CodeGenerator for CompInfo { } }; + if let Some(padding_field) = + struct_layout.pad_field(&field_name, field_ty, field.offset()) { + fields.push(padding_field); + } + let is_private = field.annotations() .private_fields() .unwrap_or(fields_should_be_private); @@ -1181,8 +1212,11 @@ impl CodeGenerator for CompInfo { let bitfield_fields = mem::replace(&mut current_bitfield_fields, vec![]); bitfield_count += 1; - Bitfield::new(bitfield_count, bitfield_fields) + let bitfield_layout = Bitfield::new(bitfield_count, + bitfield_fields) .codegen_fields(ctx, &mut fields, &mut methods); + + struct_layout.saw_bitfield(bitfield_layout); } debug_assert!(current_bitfield_fields.is_empty()); @@ -1192,6 +1226,9 @@ impl CodeGenerator for CompInfo { let field = StructFieldBuilder::named("bindgen_union_field") .pub_() .build_ty(ty); + + struct_layout.saw_union(layout); + fields.push(field); } @@ -1216,6 +1253,16 @@ impl CodeGenerator for CompInfo { warn!("Opaque type without layout! Expect dragons!"); } } + } else if !is_union && !self.is_unsized(ctx) { + if let Some(padding_field) = + layout.and_then(|layout| struct_layout.pad_struct(layout)) { + fields.push(padding_field); + } + + if let Some(align_field) = + layout.and_then(|layout| struct_layout.align_struct(layout)) { + fields.push(align_field); + } } // C requires every struct to be addressable, so what C compilers do is @@ -1239,10 +1286,10 @@ impl CodeGenerator for CompInfo { let prefix = ctx.trait_prefix(); let phantom = quote_ty!(ctx.ext_cx(), ::$prefix::marker::PhantomData<$ident>); - let field = - StructFieldBuilder::named(format!("_phantom_{}", i)) - .pub_() - .build_ty(phantom); + let field = StructFieldBuilder::named(format!("_phantom_{}", + i)) + .pub_() + .build_ty(phantom); fields.push(field) } } @@ -1285,7 +1332,7 @@ impl CodeGenerator for CompInfo { canonical_name); } - if applicable_template_args.is_empty() && !self.found_unknown_attr() { + if applicable_template_args.is_empty() { for var in self.inner_vars() { ctx.resolve_item(*var) .codegen(ctx, result, whitelisted_items, &()); @@ -1294,19 +1341,69 @@ impl CodeGenerator for CompInfo { if let Some(layout) = layout { let fn_name = format!("bindgen_test_layout_{}", canonical_name); let fn_name = ctx.rust_ident_raw(&fn_name); - let ident = ctx.rust_ident_raw(&canonical_name); + let type_name = ctx.rust_ident_raw(&canonical_name); let prefix = ctx.trait_prefix(); let size_of_expr = quote_expr!(ctx.ext_cx(), - ::$prefix::mem::size_of::<$ident>()); + ::$prefix::mem::size_of::<$type_name>()); let align_of_expr = quote_expr!(ctx.ext_cx(), - ::$prefix::mem::align_of::<$ident>()); + ::$prefix::mem::align_of::<$type_name>()); let size = layout.size; let align = layout.align; + + let check_struct_align = if align > mem::size_of::<*mut ()>() { + // FIXME when [RFC 1358](https://github.com/rust-lang/rust/issues/33626) ready + None + } else { + quote_item!(ctx.ext_cx(), + assert_eq!($align_of_expr, + $align, + concat!("Alignment of ", stringify!($type_name))); + ) + }; + + // FIXME when [issue #465](https://github.com/servo/rust-bindgen/issues/465) ready + let too_many_base_vtables = self.base_members() + .iter() + .filter(|base| ctx.resolve_type(base.ty).has_vtable(ctx)) + .count() > + 1; + + let should_skip_field_offset_checks = item.is_opaque(ctx) || + too_many_base_vtables; + + let check_field_offset = if should_skip_field_offset_checks { + None + } else { + let asserts = self.fields() + .iter() + .filter(|field| field.bitfield().is_none()) + .flat_map(|field| { + field.name().and_then(|name| { + field.offset().and_then(|offset| { + let field_offset = offset / 8; + let field_name = ctx.rust_ident(name); + + quote_item!(ctx.ext_cx(), + assert_eq!(unsafe { &(*(0 as *const $type_name)).$field_name as *const _ as usize }, + $field_offset, + concat!("Alignment of field: ", stringify!($type_name), "::", stringify!($field_name))); + ) + }) + }) + }).collect::<Vec<P<ast::Item>>>(); + + Some(asserts) + }; + let item = quote_item!(ctx.ext_cx(), #[test] fn $fn_name() { - assert_eq!($size_of_expr, $size); - assert_eq!($align_of_expr, $align); + assert_eq!($size_of_expr, + $size, + concat!("Size of: ", stringify!($type_name))); + + $check_struct_align + $check_field_offset }) .unwrap(); result.push(item); @@ -1482,8 +1579,8 @@ impl MethodCodegen for Method { // return-type = void. if self.is_constructor() { fndecl.inputs.remove(0); - fndecl.output = - ast::FunctionRetTy::Ty(quote_ty!(ctx.ext_cx(), Self)); + fndecl.output = ast::FunctionRetTy::Ty(quote_ty!(ctx.ext_cx(), + Self)); } let sig = ast::MethodSig { @@ -1564,7 +1661,7 @@ enum EnumBuilder<'a> { canonical_name: &'a str, aster: P<ast::Item>, }, - Consts { aster: P<ast::Item>, } + Consts { aster: P<ast::Item> }, } impl<'a> EnumBuilder<'a> { @@ -1825,12 +1922,11 @@ impl CodeGenerator for Enum { .map(|repr| repr.to_rust_ty(ctx)) .unwrap_or_else(|| helpers::ast_ty::raw_type(ctx, repr_name)); - let mut builder = - EnumBuilder::new(builder, - &name, - repr, - is_bitfield, - is_constified_enum); + let mut builder = EnumBuilder::new(builder, + &name, + repr, + is_bitfield, + is_constified_enum); // A map where we keep a value -> variant relation. let mut seen_values = HashMap::<_, String>::new(); @@ -1856,7 +1952,8 @@ impl CodeGenerator for Enum { let mut constified_variants = VecDeque::new(); let mut iter = self.variants().iter().peekable(); - while let Some(variant) = iter.next().or_else(|| constified_variants.pop_front()) { + while let Some(variant) = iter.next() + .or_else(|| constified_variants.pop_front()) { if variant.hidden() { continue; } @@ -1877,8 +1974,9 @@ impl CodeGenerator for Enum { let parent_name = parent_canonical_name.as_ref() .unwrap(); - Cow::Owned( - format!("{}_{}", parent_name, variant_name)) + Cow::Owned(format!("{}_{}", + parent_name, + variant_name)) }; let existing_variant_name = entry.get(); @@ -1909,15 +2007,16 @@ impl CodeGenerator for Enum { // we also generate a constant so it can be properly // accessed. if (is_rust_enum && enum_ty.name().is_none()) || - variant.force_constification() { + variant.force_constification() { let mangled_name = if is_toplevel { variant_name.clone() } else { let parent_name = parent_canonical_name.as_ref() .unwrap(); - Cow::Owned( - format!("{}_{}", parent_name, variant_name)) + Cow::Owned(format!("{}_{}", + parent_name, + variant_name)) }; add_constant(enum_ty, @@ -2044,7 +2143,8 @@ impl ToRustTy for Type { .map(|arg| arg.to_rust_ty(ctx)) .collect::<Vec<_>>(); - path.segments.last_mut().unwrap().parameters = if template_args.is_empty() { + path.segments.last_mut().unwrap().parameters = if + template_args.is_empty() { None } else { Some(P(ast::PathParameters::AngleBracketed( @@ -2062,11 +2162,10 @@ impl ToRustTy for Type { TypeKind::ResolvedTypeRef(inner) => inner.to_rust_ty(ctx), TypeKind::TemplateAlias(inner, _) | TypeKind::Alias(inner) => { - let applicable_named_args = - item.applicable_template_args(ctx) - .into_iter() - .filter(|arg| ctx.resolve_type(*arg).is_named()) - .collect::<Vec<_>>(); + let applicable_named_args = item.applicable_template_args(ctx) + .into_iter() + .filter(|arg| ctx.resolve_type(*arg).is_named()) + .collect::<Vec<_>>(); let spelling = self.name().expect("Unnamed alias?"); if item.is_opaque(ctx) && !applicable_named_args.is_empty() { @@ -2086,7 +2185,7 @@ impl ToRustTy for Type { TypeKind::Comp(ref info) => { let template_args = item.applicable_template_args(ctx); if info.has_non_type_template_params() || - (item.is_opaque(ctx) && !template_args.is_empty()) { + (item.is_opaque(ctx) && !template_args.is_empty()) { return match self.layout(ctx) { Some(layout) => BlobTyBuilder::new(layout).build(), None => { @@ -2127,9 +2226,7 @@ impl ToRustTy for Type { let ident = ctx.rust_ident(&name); quote_ty!(ctx.ext_cx(), $ident) } - TypeKind::ObjCInterface(..) => { - quote_ty!(ctx.ext_cx(), id) - }, + TypeKind::ObjCInterface(..) => quote_ty!(ctx.ext_cx(), id), ref u @ TypeKind::UnresolvedTypeRef(..) => { unreachable!("Should have been resolved after parsing {:?}!", u) } @@ -2142,61 +2239,8 @@ impl ToRustTy for FunctionSig { fn to_rust_ty(&self, ctx: &BindgenContext, _item: &Item) -> P<ast::Ty> { // TODO: we might want to consider ignoring the reference return value. - let return_item = ctx.resolve_item(self.return_type()); - let ret = - if let TypeKind::Void = *return_item.kind().expect_type().kind() { - ast::FunctionRetTy::Default(ctx.span()) - } else { - ast::FunctionRetTy::Ty(return_item.to_rust_ty(ctx)) - }; - - let mut unnamed_arguments = 0; - let arguments = self.argument_types().iter().map(|&(ref name, ty)| { - let arg_item = ctx.resolve_item(ty); - let arg_ty = arg_item.kind().expect_type(); - - // From the C90 standard[1]: - // - // A declaration of a parameter as "array of type" shall be - // adjusted to "qualified pointer to type", where the type - // qualifiers (if any) are those specified within the [ and ] of - // the array type derivation. - // - // [1]: http://c0x.coding-guidelines.com/6.7.5.3.html - let arg_ty = match *arg_ty.canonical_type(ctx).kind() { - TypeKind::Array(t, _) => { - t.to_rust_ty(ctx).to_ptr(arg_ty.is_const(), ctx.span()) - }, - TypeKind::Pointer(inner) => { - let inner = ctx.resolve_item(inner); - let inner_ty = inner.expect_type(); - if let TypeKind::ObjCInterface(_) = *inner_ty.canonical_type(ctx).kind() { - quote_ty!(ctx.ext_cx(), id) - } else { - arg_item.to_rust_ty(ctx) - } - }, - _ => { - arg_item.to_rust_ty(ctx) - } - }; - - let arg_name = match *name { - Some(ref name) => ctx.rust_mangle(name).into_owned(), - None => { - unnamed_arguments += 1; - format!("arg{}", unnamed_arguments) - } - }; - - assert!(!arg_name.is_empty()); - - ast::Arg { - ty: arg_ty, - pat: aster::AstBuilder::new().pat().id(arg_name), - id: ast::DUMMY_NODE_ID, - } - }).collect::<Vec<_>>(); + let ret = utils::fnsig_return_ty(ctx, &self); + let arguments = utils::fnsig_arguments(ctx, &self); let decl = P(ast::FnDecl { inputs: arguments, @@ -2206,7 +2250,7 @@ impl ToRustTy for FunctionSig { let fnty = ast::TyKind::BareFn(P(ast::BareFnTy { unsafety: ast::Unsafety::Unsafe, - abi: self.abi(), + abi: self.abi().expect("Invalid abi for function!"), lifetimes: vec![], decl: decl, })); @@ -2286,7 +2330,8 @@ impl CodeGenerator for Function { vis: ast::Visibility::Public, }; - let item = ForeignModBuilder::new(signature.abi()) + let item = ForeignModBuilder::new(signature.abi() + .expect("Invalid abi for function!")) .with_foreign_item(foreign_item) .build(ctx); @@ -2305,9 +2350,34 @@ impl CodeGenerator for ObjCInterface { let mut trait_items = vec![]; for method in self.methods() { - let method_name = ctx.rust_ident(method.name()); + let signature = method.signature(); + let fn_args = utils::fnsig_arguments(ctx, signature); + let fn_ret = utils::fnsig_return_ty(ctx, signature); + let sig = aster::AstBuilder::new() + .method_sig() + .unsafe_() + .fn_decl() + .self_() + .build(ast::SelfKind::Value(ast::Mutability::Immutable)) + .with_args(fn_args.clone()) + .build(fn_ret); + + // Collect the actual used argument names + let arg_names: Vec<_> = fn_args.iter() + .map(|ref arg| match arg.pat.node { + ast::PatKind::Ident(_, ref spanning, _) => { + spanning.node.name.as_str().to_string() + } + _ => { + panic!("odd argument!"); + } + }) + .collect(); - let body = quote_stmt!(ctx.ext_cx(), msg_send![self, $method_name]) + let methods_and_args = + ctx.rust_ident(&method.format_method_call(&arg_names)); + let body = quote_stmt!(ctx.ext_cx(), + msg_send![self, $methods_and_args]) .unwrap(); let block = ast::Block { stmts: vec![body], @@ -2316,13 +2386,6 @@ impl CodeGenerator for ObjCInterface { span: ctx.span(), }; - let sig = aster::AstBuilder::new() - .method_sig() - .unsafe_() - .fn_decl() - .self_() - .build(ast::SelfKind::Value(ast::Mutability::Immutable)) - .build(ast::FunctionRetTy::Default(ctx.span())); let attrs = vec![]; let impl_item = ast::ImplItem { @@ -2397,27 +2460,29 @@ pub fn codegen(context: &mut BindgenContext) -> Vec<P<ast::Item>> { } mod utils { + use super::ItemToRustTy; use aster; use ir::context::{BindgenContext, ItemId}; use ir::item::{Item, ItemCanonicalPath}; + use ir::function::FunctionSig; use ir::ty::TypeKind; use std::mem; - use super::ItemToRustTy; use syntax::ast; use syntax::ptr::P; - pub fn prepend_objc_header(ctx: &BindgenContext, result: &mut Vec<P<ast::Item>>) { let use_objc = if ctx.options().objc_extern_crate { quote_item!(ctx.ext_cx(), use objc; - ).unwrap() + ) + .unwrap() } else { quote_item!(ctx.ext_cx(), #[macro_use] extern crate objc; - ).unwrap() + ) + .unwrap() }; @@ -2500,13 +2565,12 @@ mod utils { ) .unwrap(); - let items = vec![ - union_field_decl, union_field_impl, - union_field_default_impl, - union_field_clone_impl, - union_field_copy_impl, - union_field_debug_impl, - ]; + let items = vec![union_field_decl, + union_field_impl, + union_field_default_impl, + union_field_clone_impl, + union_field_copy_impl, + union_field_debug_impl]; let old_items = mem::replace(result, items); result.extend(old_items.into_iter()); @@ -2578,13 +2642,11 @@ mod utils { ) .unwrap(); - let items = vec![ - incomplete_array_decl, - incomplete_array_impl, - incomplete_array_debug_impl, - incomplete_array_clone_impl, - incomplete_array_copy_impl, - ]; + let items = vec![incomplete_array_decl, + incomplete_array_impl, + incomplete_array_debug_impl, + incomplete_array_clone_impl, + incomplete_array_copy_impl]; let old_items = mem::replace(result, items); result.extend(old_items.into_iter()); @@ -2614,8 +2676,7 @@ mod utils { let path = item.namespace_aware_canonical_path(ctx); let builder = aster::AstBuilder::new().ty().path(); - let template_args = template_args - .iter() + let template_args = template_args.iter() .map(|arg| arg.to_rust_ty(ctx)) .collect::<Vec<_>>(); @@ -2688,4 +2749,68 @@ mod utils { _ => panic!("How did this happen exactly?"), } } + + pub fn fnsig_return_ty(ctx: &BindgenContext, + sig: &FunctionSig) + -> ast::FunctionRetTy { + let return_item = ctx.resolve_item(sig.return_type()); + if let TypeKind::Void = *return_item.kind().expect_type().kind() { + ast::FunctionRetTy::Default(ctx.span()) + } else { + ast::FunctionRetTy::Ty(return_item.to_rust_ty(ctx)) + } + } + + pub fn fnsig_arguments(ctx: &BindgenContext, + sig: &FunctionSig) + -> Vec<ast::Arg> { + use super::ToPtr; + let mut unnamed_arguments = 0; + sig.argument_types().iter().map(|&(ref name, ty)| { + let arg_item = ctx.resolve_item(ty); + let arg_ty = arg_item.kind().expect_type(); + + // From the C90 standard[1]: + // + // A declaration of a parameter as "array of type" shall be + // adjusted to "qualified pointer to type", where the type + // qualifiers (if any) are those specified within the [ and ] of + // the array type derivation. + // + // [1]: http://c0x.coding-guidelines.com/6.7.5.3.html + let arg_ty = match *arg_ty.canonical_type(ctx).kind() { + TypeKind::Array(t, _) => { + t.to_rust_ty(ctx).to_ptr(arg_ty.is_const(), ctx.span()) + }, + TypeKind::Pointer(inner) => { + let inner = ctx.resolve_item(inner); + let inner_ty = inner.expect_type(); + if let TypeKind::ObjCInterface(_) = *inner_ty.canonical_type(ctx).kind() { + quote_ty!(ctx.ext_cx(), id) + } else { + arg_item.to_rust_ty(ctx) + } + }, + _ => { + arg_item.to_rust_ty(ctx) + } + }; + + let arg_name = match *name { + Some(ref name) => ctx.rust_mangle(name).into_owned(), + None => { + unnamed_arguments += 1; + format!("arg{}", unnamed_arguments) + } + }; + + assert!(!arg_name.is_empty()); + + ast::Arg { + ty: arg_ty, + pat: aster::AstBuilder::new().pat().id(arg_name), + id: ast::DUMMY_NODE_ID, + } + }).collect::<Vec<_>>() + } } diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs new file mode 100644 index 00000000..3006a31a --- /dev/null +++ b/src/codegen/struct_layout.rs @@ -0,0 +1,193 @@ +//! Helpers for code generation that need struct layout + +use super::helpers::BlobTyBuilder; + +use aster::struct_field::StructFieldBuilder; + +use ir::comp::CompInfo; +use ir::context::BindgenContext; +use ir::layout::Layout; +use ir::ty::Type; +use std::cmp; +use std::mem; + +use syntax::ast; + +/// Trace the layout of struct. +pub struct StructLayoutTracker<'a, 'ctx: 'a> { + ctx: &'a BindgenContext<'ctx>, + comp: &'a CompInfo, + latest_offset: usize, + padding_count: usize, + latest_field_layout: Option<Layout>, + max_field_align: usize, +} + +impl<'a, 'ctx> StructLayoutTracker<'a, 'ctx> { + pub fn new(ctx: &'a BindgenContext<'ctx>, comp: &'a CompInfo) -> Self { + StructLayoutTracker { + ctx: ctx, + comp: comp, + latest_offset: 0, + padding_count: 0, + latest_field_layout: None, + max_field_align: 0, + } + } + + pub fn saw_vtable(&mut self) { + let ptr_size = mem::size_of::<*mut ()>(); + self.latest_offset += ptr_size; + self.latest_field_layout = Some(Layout::new(ptr_size, ptr_size)); + self.max_field_align = ptr_size; + } + + pub fn saw_base(&mut self, base_ty: &Type) { + self.align_to_latest_field(); + + if let Some(layout) = base_ty.layout(self.ctx) { + self.latest_offset += self.padding_bytes(layout) + layout.size; + self.latest_field_layout = Some(layout); + self.max_field_align = cmp::max(self.max_field_align, layout.align); + } + } + + pub fn saw_bitfield(&mut self, layout: Layout) { + self.align_to_latest_field(); + + self.latest_offset += self.padding_bytes(layout) + layout.size; + self.latest_field_layout = Some(layout); + self.max_field_align = cmp::max(self.max_field_align, layout.align); + } + + pub fn saw_union(&mut self, layout: Layout) { + self.align_to_latest_field(); + + self.latest_offset += self.padding_bytes(layout) + layout.size; + self.latest_field_layout = Some(layout); + self.max_field_align = cmp::max(self.max_field_align, layout.align); + } + + pub fn pad_field(&mut self, + field_name: &str, + field_ty: &Type, + field_offset: Option<usize>) + -> Option<ast::StructField> { + field_ty.layout(self.ctx).and_then(|field_layout| { + self.align_to_latest_field(); + + let padding_layout = if self.comp.packed() { + None + } else { + let calculated_layout = field_ty.as_comp() + .and_then(|comp| comp.calc_layout(self.ctx)) + .unwrap_or(field_layout); + + let align = cmp::min(calculated_layout.align, mem::size_of::<*mut ()>()); + + let (padding_bytes, need_padding) = match field_offset { + Some(offset) if offset / 8 > self.latest_offset => { + (offset / 8 - self.latest_offset, true) + } + _ => { + (self.padding_bytes(field_layout), (self.latest_offset % field_layout.align) != 0) + } + }; + + self.latest_offset += padding_bytes; + + debug!("align field {} to {}/{} with {} padding bytes {:?}, calculated {:?}", + field_name, + self.latest_offset, + field_offset.unwrap_or(0) / 8, + padding_bytes, + field_layout, + calculated_layout); + + if need_padding && + (padding_bytes > calculated_layout.align || + field_layout.align > mem::size_of::<*mut ()>()) { + Some(Layout::new(padding_bytes, align)) + } else { + None + } + }; + + self.latest_offset += field_ty.calc_size(self.ctx).unwrap_or(field_layout.size); + + self.latest_field_layout = Some(field_layout); + self.max_field_align = cmp::max(self.max_field_align, field_layout.align); + + padding_layout.map(|layout| self.padding_field(layout)) + }) + } + + pub fn pad_struct(&mut self, layout: Layout) -> Option<ast::StructField> { + if layout.size < self.latest_offset { + warn!("calculate struct layout incorrect, too more {} bytes", + self.latest_offset - layout.size); + + None + } else { + let padding_bytes = layout.size - self.latest_offset; + let struct_align = cmp::min(layout.align, + mem::size_of::<*mut ()>()); + + if padding_bytes > struct_align || + (layout.align > mem::size_of::<*mut ()>() && padding_bytes > 0) { + let padding_align = if self.comp.packed() { + 1 + } else { + cmp::min(1 << padding_bytes.trailing_zeros(), + mem::size_of::<*mut ()>()) + }; + + Some(self.padding_field(Layout::new(padding_bytes, padding_align))) + } else { + None + } + } + } + + pub fn align_struct(&self, layout: Layout) -> Option<ast::StructField> { + if self.max_field_align < layout.align && + layout.align <= mem::size_of::<*mut ()>() { + let ty = BlobTyBuilder::new(Layout::new(0, layout.align)).build(); + + Some(StructFieldBuilder::named("__bindgen_align") + .pub_() + .build_ty(ty)) + } else { + None + } + } + + fn padding_bytes(&self, layout: Layout) -> usize { + if self.latest_offset % layout.align == 0 { + 0 + } else { + layout.align - (self.latest_offset % layout.align) + } + } + + fn padding_field(&mut self, layout: Layout) -> ast::StructField { + let ty = BlobTyBuilder::new(layout).build(); + let padding_count = self.padding_count; + + self.padding_count += 1; + + let padding_field_name = format!("__bindgen_padding_{}", padding_count); + + self.max_field_align = cmp::max(self.max_field_align, layout.align); + + StructFieldBuilder::named(padding_field_name).pub_().build_ty(ty) + } + + fn align_to_latest_field(&mut self) { + if self.comp.packed() { + // skip to align field when packed + } else if let Some(layout) = self.latest_field_layout { + self.latest_offset += self.padding_bytes(layout); + } + } +} diff --git a/src/ir/comp.rs b/src/ir/comp.rs index bad661da..53efd278 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1,8 +1,5 @@ //! Compound types (unions and structs) in our intermediate representation. -use clang; -use parse::{ClangItemParser, ParseError}; -use std::cell::Cell; use super::annotations::Annotations; use super::context::{BindgenContext, ItemId}; use super::derive::{CanDeriveCopy, CanDeriveDebug}; @@ -10,6 +7,9 @@ use super::item::Item; use super::layout::Layout; use super::ty::Type; use super::type_collector::{ItemSet, TypeCollector}; +use clang; +use parse::{ClangItemParser, ParseError}; +use std::cell::Cell; /// The kind of compound type. #[derive(Debug, Copy, Clone, PartialEq)] @@ -102,6 +102,8 @@ pub struct Field { bitfield: Option<u32>, /// If the C++ field is marked as `mutable` mutable: bool, + /// The offset of the field (in bits) + offset: Option<usize>, } impl Field { @@ -111,7 +113,8 @@ impl Field { comment: Option<String>, annotations: Option<Annotations>, bitfield: Option<u32>, - mutable: bool) + mutable: bool, + offset: Option<usize>) -> Field { Field { name: name, @@ -120,6 +123,7 @@ impl Field { annotations: annotations.unwrap_or_default(), bitfield: bitfield, mutable: mutable, + offset: offset, } } @@ -152,6 +156,11 @@ impl Field { pub fn annotations(&self) -> &Annotations { &self.annotations } + + /// The offset of the field (in bits) + pub fn offset(&self) -> Option<usize> { + self.offset + } } impl CanDeriveDebug for Field { @@ -390,26 +399,73 @@ impl CompInfo { /// members. This is not ideal, but clang fails to report the size for these /// kind of unions, see test/headers/template_union.hpp pub fn layout(&self, ctx: &BindgenContext) -> Option<Layout> { - use std::cmp; - // We can't do better than clang here, sorry. if self.kind == CompKind::Struct { - return None; + None + } else { + self.calc_layout(ctx) } + } - let mut max_size = 0; - let mut max_align = 0; - for field in &self.fields { - let field_layout = ctx.resolve_type(field.ty) - .layout(ctx); + /// Compute the layout of this type. + pub fn calc_layout(&self, ctx: &BindgenContext) -> Option<Layout> { + use std::cmp; + use std::mem; + + if self.kind == CompKind::Struct { + let mut latest_offset_in_bits = 0; + let mut max_align = 0; - if let Some(layout) = field_layout { - max_size = cmp::max(max_size, layout.size); - max_align = cmp::max(max_align, layout.align); + if self.needs_explicit_vtable(ctx) { + latest_offset_in_bits += mem::size_of::<*mut ()>() * 8; + max_align = mem::size_of::<*mut ()>(); } - } - Some(Layout::new(max_size, max_align)) + for field in &self.fields { + if let Some(bits) = field.bitfield() { + latest_offset_in_bits += bits as usize; + } else { + let field_ty = ctx.resolve_type(field.ty); + + if let Some(field_layout) = + field_ty.as_comp() + .and_then(|comp| comp.calc_layout(ctx)) + .or_else(|| field_ty.layout(ctx)) { + + let n = (latest_offset_in_bits / 8) % + field_layout.align; + + if !self.packed && n != 0 { + latest_offset_in_bits += (field_layout.align - n) * + 8; + } + + latest_offset_in_bits += field_layout.size * 8; + max_align = cmp::max(max_align, field_layout.align); + } + } + } + + if latest_offset_in_bits == 0 && max_align == 0 { + None + } else { + Some(Layout::new((latest_offset_in_bits + 7) / 8, max_align)) + } + } else { + let mut max_size = 0; + let mut max_align = 0; + for field in &self.fields { + let field_layout = ctx.resolve_type(field.ty) + .layout(ctx); + + if let Some(layout) = field_layout { + max_size = cmp::max(max_size, layout.size); + max_align = cmp::max(max_align, layout.align); + } + } + + Some(Layout::new(max_size, max_align)) + } } /// Get this type's set of fields. @@ -486,14 +542,13 @@ impl CompInfo { debug!("CompInfo::from_ty({:?}, {:?})", kind, cursor); let mut ci = CompInfo::new(kind); - ci.is_forward_declaration = location.map_or(true, |cur| { - match cur.kind() { + ci.is_forward_declaration = + location.map_or(true, |cur| match cur.kind() { CXCursor_StructDecl | CXCursor_UnionDecl | CXCursor_ClassDecl => !cur.is_definition(), _ => false, - } - }); + }); ci.is_anonymous = cursor.is_anonymous(); ci.template_args = match ty.template_args() { // In forward declarations and not specializations, @@ -506,13 +561,12 @@ impl CompInfo { let mut specialization = true; let args = arg_types.filter(|t| t.kind() != CXType_Invalid) - .filter_map(|t| { - if t.spelling().starts_with("type-parameter") { - specialization = false; - None - } else { - Some(Item::from_ty_or_ref(t, None, None, ctx)) - } + .filter_map(|t| if t.spelling() + .starts_with("type-parameter") { + specialization = false; + None + } else { + Some(Item::from_ty_or_ref(t, None, None, ctx)) }) .collect::<Vec<_>>(); @@ -531,35 +585,35 @@ impl CompInfo { let mut maybe_anonymous_struct_field = None; cursor.visit(|cur| { if cur.kind() != CXCursor_FieldDecl { - if let Some((ty, _)) = maybe_anonymous_struct_field { - let field = Field::new(None, ty, None, None, None, false); + if let Some((ty, _, offset)) = + maybe_anonymous_struct_field.take() { + let field = + Field::new(None, ty, None, None, None, false, offset); ci.fields.push(field); } - maybe_anonymous_struct_field = None; } match cur.kind() { CXCursor_FieldDecl => { - match maybe_anonymous_struct_field.take() { - Some((ty, clang_ty)) => { - let mut used = false; - cur.visit(|child| { - if child.cur_type() == clang_ty { - used = true; - } - CXChildVisit_Continue - }); - if !used { - let field = Field::new(None, - ty, - None, - None, - None, - false); - ci.fields.push(field); + if let Some((ty, clang_ty, offset)) = + maybe_anonymous_struct_field.take() { + let mut used = false; + cur.visit(|child| { + if child.cur_type() == clang_ty { + used = true; } + CXChildVisit_Continue + }); + if !used { + let field = Field::new(None, + ty, + None, + None, + None, + false, + offset); + ci.fields.push(field); } - None => {} } let bit_width = cur.bit_width(); @@ -572,6 +626,7 @@ impl CompInfo { let annotations = Annotations::new(&cur); let name = cur.spelling(); let is_mutable = cursor.is_mutable_field(); + let offset = cur.offset_of_field().ok(); // Name can be empty if there are bitfields, for example, // see tests/headers/struct_with_bitfields.h @@ -585,7 +640,8 @@ impl CompInfo { comment, annotations, bit_width, - is_mutable); + is_mutable, + offset); ci.fields.push(field); // No we look for things like attributes and stuff. @@ -617,7 +673,9 @@ impl CompInfo { if cur.spelling().is_empty() && cur.kind() != CXCursor_EnumDecl { let ty = cur.cur_type(); - maybe_anonymous_struct_field = Some((inner, ty)); + let offset = cur.offset_of_field().ok(); + maybe_anonymous_struct_field = + Some((inner, ty, offset)); } } CXCursor_PackedAttr => { @@ -681,10 +739,13 @@ impl CompInfo { // NB: This gets us an owned `Function`, not a // `FunctionSig`. - let signature = match Item::parse(cur, Some(potential_id), ctx) { - Ok(item) if ctx.resolve_item(item).kind().is_function() => item, - _ => return CXChildVisit_Continue, - }; + let signature = + match Item::parse(cur, Some(potential_id), ctx) { + Ok(item) if ctx.resolve_item(item) + .kind() + .is_function() => item, + _ => return CXChildVisit_Continue, + }; match cur.kind() { CXCursor_Constructor => { @@ -747,8 +808,8 @@ impl CompInfo { CXChildVisit_Continue }); - if let Some((ty, _)) = maybe_anonymous_struct_field { - let field = Field::new(None, ty, None, None, None, false); + if let Some((ty, _, offset)) = maybe_anonymous_struct_field { + let field = Field::new(None, ty, None, None, None, false, offset); ci.fields.push(field); } diff --git a/src/ir/context.rs b/src/ir/context.rs index 50774a43..38ecdf17 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -1,5 +1,12 @@ //! Common context that is passed around during parsing and codegen. +use super::derive::{CanDeriveCopy, CanDeriveDebug}; +use super::int::IntKind; +use super::item::{Item, ItemCanonicalPath}; +use super::item_kind::ItemKind; +use super::module::{Module, ModuleKind}; +use super::ty::{FloatKind, Type, TypeKind}; +use super::type_collector::{ItemSet, TypeCollector}; use BindgenOptions; use cexpr; use chooser::TypeChooser; @@ -10,13 +17,6 @@ use std::cell::Cell; use std::collections::{HashMap, VecDeque, hash_map}; use std::collections::btree_map::{self, BTreeMap}; use std::fmt; -use super::derive::{CanDeriveCopy, CanDeriveDebug}; -use super::int::IntKind; -use super::item::{Item, ItemCanonicalPath}; -use super::item_kind::ItemKind; -use super::module::{Module, ModuleKind}; -use super::ty::{FloatKind, Type, TypeKind}; -use super::type_collector::{ItemSet, TypeCollector}; use syntax::ast::Ident; use syntax::codemap::{DUMMY_SP, Span}; use syntax::ext::base::ExtCtxt; @@ -254,8 +254,8 @@ impl<'ctx> BindgenContext<'ctx> { TypeKey::USR(usr) } else { warn!("Valid declaration with no USR: {:?}, {:?}", - declaration, - location); + declaration, + location); TypeKey::Declaration(declaration) }; @@ -961,7 +961,8 @@ impl<'ctx> BindgenContext<'ctx> { fn tokenize_namespace(&self, cursor: &clang::Cursor) -> (Option<String>, ModuleKind) { - assert_eq!(cursor.kind(), ::clang_sys::CXCursor_Namespace, + assert_eq!(cursor.kind(), + ::clang_sys::CXCursor_Namespace, "Be a nice person"); let tokens = match self.translation_unit.tokens(&cursor) { Some(tokens) => tokens, @@ -995,7 +996,7 @@ impl<'ctx> BindgenContext<'ctx> { token); } } - }; + } (module_name, kind) } diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index ca4e77db..0a85577e 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -1,11 +1,13 @@ //! Intermediate representation for C/C++ enumerations. -use clang; -use ir::annotations::Annotations; -use parse::{ClangItemParser, ParseError}; use super::context::{BindgenContext, ItemId}; use super::item::Item; use super::ty::TypeKind; +use clang; +use ir::annotations::Annotations; +use ir::int::IntKind; +use ir::layout::Layout; +use parse::{ClangItemParser, ParseError}; /// An enum representing custom handling that can be given to a variant. #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -49,6 +51,19 @@ impl Enum { &self.variants } + /// Compute the layout of this type. + pub fn calc_layout(&self, ctx: &BindgenContext) -> Option<Layout> { + self.repr + .map(|repr| ctx.resolve_type(repr)) + .and_then(|repr| match *repr.canonical_type(ctx).kind() { + TypeKind::Int(int_kind) => Some(int_kind), + _ => None, + }) + .unwrap_or(IntKind::Int) + .known_size() + .map(|size| Layout::new(size, size)) + } + /// Construct an enumeration from the given Clang type. pub fn from_ty(ty: &clang::Type, ctx: &mut BindgenContext) @@ -66,18 +81,20 @@ impl Enum { // Assume signedness since the default type by the C standard is an int. let is_signed = repr.and_then(|r| ctx.resolve_type(r).safe_canonical_type(ctx)) - .map_or(true, |ty| { - match *ty.kind() { - TypeKind::Int(ref int_kind) => int_kind.is_signed(), - ref other => { - panic!("Since when enums can be non-integers? {:?}", + .map_or(true, |ty| match *ty.kind() { + TypeKind::Int(ref int_kind) => int_kind.is_signed(), + ref other => { + panic!("Since when enums can be non-integers? {:?}", other) - } } }); let type_name = ty.spelling(); - let type_name = if type_name.is_empty() { None } else { Some(type_name) }; + let type_name = if type_name.is_empty() { + None + } else { + Some(type_name) + }; let type_name = type_name.as_ref().map(String::as_str); declaration.visit(|cursor| { @@ -94,20 +111,22 @@ impl Enum { t.enum_variant_behavior(type_name, &name, val) }) .or_else(|| { - Annotations::new(&cursor).and_then(|anno| { - if anno.hide() { + Annotations::new(&cursor) + .and_then(|anno| if anno.hide() { Some(EnumVariantCustomBehavior::Hide) - } else if anno.constify_enum_variant() { + } else if + anno.constify_enum_variant() { Some(EnumVariantCustomBehavior::Constify) } else { None - } - }) + }) }); let comment = cursor.raw_comment(); - variants.push( - EnumVariant::new(name, comment, val, custom_behavior)); + variants.push(EnumVariant::new(name, + comment, + val, + custom_behavior)); } } CXChildVisit_Continue diff --git a/src/ir/function.rs b/src/ir/function.rs index a50edfde..9ef9c3a7 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -1,12 +1,12 @@ //! Intermediate representation for C/C++ functions and methods. -use clang; -use clang_sys::CXCallingConv; -use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult}; use super::context::{BindgenContext, ItemId}; use super::item::Item; use super::ty::TypeKind; use super::type_collector::{ItemSet, TypeCollector}; +use clang; +use clang_sys::CXCallingConv; +use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult}; use syntax::abi; /// A function declaration, with a signature, arguments, and argument names. @@ -73,18 +73,19 @@ pub struct FunctionSig { is_variadic: bool, /// The ABI of this function. - abi: abi::Abi, + abi: Option<abi::Abi>, } -fn get_abi(cc: CXCallingConv) -> abi::Abi { +fn get_abi(cc: CXCallingConv) -> Option<abi::Abi> { use clang_sys::*; match cc { - CXCallingConv_Default => abi::Abi::C, - CXCallingConv_C => abi::Abi::C, - CXCallingConv_X86StdCall => abi::Abi::Stdcall, - CXCallingConv_X86FastCall => abi::Abi::Fastcall, - CXCallingConv_AAPCS => abi::Abi::Aapcs, - CXCallingConv_X86_64Win64 => abi::Abi::Win64, + CXCallingConv_Default => Some(abi::Abi::C), + CXCallingConv_C => Some(abi::Abi::C), + CXCallingConv_X86StdCall => Some(abi::Abi::Stdcall), + CXCallingConv_X86FastCall => Some(abi::Abi::Fastcall), + CXCallingConv_AAPCS => Some(abi::Abi::Aapcs), + CXCallingConv_X86_64Win64 => Some(abi::Abi::Win64), + CXCallingConv_Invalid => None, other => panic!("unsupported calling convention: {:?}", other), } } @@ -116,7 +117,7 @@ impl FunctionSig { pub fn new(return_type: ItemId, arguments: Vec<(Option<String>, ItemId)>, is_variadic: bool, - abi: abi::Abi) + abi: Option<abi::Abi>) -> Self { FunctionSig { return_type: return_type, @@ -154,7 +155,8 @@ impl FunctionSig { let mut args: Vec<_> = match cursor.kind() { CXCursor_FunctionDecl | CXCursor_Constructor | - CXCursor_CXXMethod => { + CXCursor_CXXMethod | + CXCursor_ObjCInstanceMethodDecl => { // For CXCursor_FunctionDecl, cursor.args() is the reliable way // to get parameter names and types. cursor.args() @@ -165,7 +167,8 @@ impl FunctionSig { let name = arg.spelling(); let name = if name.is_empty() { None } else { Some(name) }; - let ty = Item::from_ty_or_ref(arg_ty, Some(*arg), None, ctx); + let ty = + Item::from_ty_or_ref(arg_ty, Some(*arg), None, ctx); (name, ty) }) .collect() @@ -176,8 +179,10 @@ impl FunctionSig { let mut args = vec![]; cursor.visit(|c| { if c.kind() == CXCursor_ParmDecl { - let ty = - Item::from_ty_or_ref(c.cur_type(), Some(c), None, ctx); + let ty = Item::from_ty_or_ref(c.cur_type(), + Some(c), + None, + ctx); let name = c.spelling(); let name = if name.is_empty() { None } else { Some(name) }; @@ -215,10 +220,19 @@ impl FunctionSig { } } - let ty_ret_type = try!(ty.ret_type().ok_or(ParseError::Continue)); + let ty_ret_type = if cursor.kind() == CXCursor_ObjCInstanceMethodDecl { + try!(cursor.ret_type().ok_or(ParseError::Continue)) + } else { + try!(ty.ret_type().ok_or(ParseError::Continue)) + }; let ret = Item::from_ty_or_ref(ty_ret_type, None, None, ctx); let abi = get_abi(ty.call_conv()); + if abi.is_none() { + assert_eq!(cursor.kind(), CXCursor_ObjCInstanceMethodDecl, + "Invalid ABI for function signature") + } + Ok(Self::new(ret, args, ty.is_variadic(), abi)) } @@ -233,7 +247,7 @@ impl FunctionSig { } /// Get this function signature's ABI. - pub fn abi(&self) -> abi::Abi { + pub fn abi(&self) -> Option<abi::Abi> { self.abi } @@ -275,7 +289,8 @@ impl ClangSubItemParser for Function { } let linkage = cursor.linkage(); - if linkage != CXLinkage_External && linkage != CXLinkage_UniqueExternal { + if linkage != CXLinkage_External && + linkage != CXLinkage_UniqueExternal { return Err(ParseError::Continue); } diff --git a/src/ir/item.rs b/src/ir/item.rs index aef35d0b..a5d10e41 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -1,11 +1,5 @@ //! Bindgen's core intermediate representation type. -use clang; -use clang_sys; -use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult}; -use std::cell::{Cell, RefCell}; -use std::fmt::Write; -use std::iter; use super::annotations::Annotations; use super::context::{BindgenContext, ItemId}; use super::derive::{CanDeriveCopy, CanDeriveDebug}; @@ -14,6 +8,12 @@ use super::item_kind::ItemKind; use super::module::Module; use super::ty::{Type, TypeKind}; use super::type_collector::{ItemSet, TypeCollector}; +use clang; +use clang_sys; +use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult}; +use std::cell::{Cell, RefCell}; +use std::fmt::Write; +use std::iter; /// A trait to get the canonical name from an item. /// @@ -193,7 +193,8 @@ impl TypeCollector for Item { // There are some types, like resolved type references, where we // don't want to stop collecting types even though they may be // opaque. - if ty.should_be_traced_unconditionally() || !self.is_opaque(ctx) { + if ty.should_be_traced_unconditionally() || + !self.is_opaque(ctx) { ty.collect_types(ctx, types, self); } } @@ -219,7 +220,8 @@ impl CanDeriveDebug for Item { type Extra = (); fn can_derive_debug(&self, ctx: &BindgenContext, _: ()) -> bool { - ctx.options().derive_debug && match self.kind { + ctx.options().derive_debug && + match self.kind { ItemKind::Type(ref ty) => { if self.is_opaque(ctx) { ty.layout(ctx) @@ -255,7 +257,9 @@ impl<'a> CanDeriveCopy<'a> for Item { ItemKind::Type(ref ty) => { if self.is_opaque(ctx) { ty.layout(ctx) - .map_or(true, |l| l.opaque().can_derive_copy_in_array(ctx, ())) + .map_or(true, |l| { + l.opaque().can_derive_copy_in_array(ctx, ()) + }) } else { ty.can_derive_copy_in_array(ctx, self) } @@ -759,9 +763,7 @@ impl Item { } ItemKind::Type(ref ty) => { let name = match *ty.kind() { - TypeKind::ResolvedTypeRef(..) => { - panic!("should have resolved this in name_target()") - } + TypeKind::ResolvedTypeRef(..) => panic!("should have resolved this in name_target()"), _ => ty.name(), }; name.map(ToOwned::to_owned) @@ -1136,7 +1138,7 @@ impl ClangItemParser for Item { } if let Some(ty) = - ctx.builtin_or_resolved_ty(id, parent_id, ty, location) { + ctx.builtin_or_resolved_ty(id, parent_id, ty, location) { return Ok(ty); } @@ -1154,9 +1156,10 @@ impl ClangItemParser for Item { }; if valid_decl { - if let Some(&(_, item_id)) = ctx.currently_parsed_types - .iter() - .find(|&&(d, _)| d == declaration_to_look_for) { + if let Some(&(_, item_id)) = + ctx.currently_parsed_types + .iter() + .find(|&&(d, _)| d == declaration_to_look_for) { debug!("Avoiding recursion parsing type: {:?}", ty); return Ok(item_id); } @@ -1325,7 +1328,7 @@ impl ItemCanonicalPath for Item { item.id() == target.id() || item.as_module().map_or(false, |module| { !module.is_inline() || - ctx.options().conservative_inline_namespaces + ctx.options().conservative_inline_namespaces }) }) .map(|item| { diff --git a/src/ir/layout.rs b/src/ir/layout.rs index 033fff62..e8c6c32b 100644 --- a/src/ir/layout.rs +++ b/src/ir/layout.rs @@ -1,9 +1,9 @@ //! 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; +use std::cmp; /// A type that represents the struct layout of a type. #[derive(Debug, Clone, Copy)] @@ -74,7 +74,8 @@ impl CanDeriveDebug for Opaque { type Extra = (); fn can_derive_debug(&self, _: &BindgenContext, _: ()) -> bool { - self.array_size().map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT) + self.array_size() + .map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT) } } @@ -82,7 +83,8 @@ impl<'a> CanDeriveCopy<'a> for Opaque { type Extra = (); fn can_derive_copy(&self, _: &BindgenContext, _: ()) -> bool { - self.array_size().map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT) + self.array_size() + .map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT) } fn can_derive_copy_in_array(&self, ctx: &BindgenContext, _: ()) -> bool { diff --git a/src/ir/module.rs b/src/ir/module.rs index 002fe36e..6b6c535b 100644 --- a/src/ir/module.rs +++ b/src/ir/module.rs @@ -1,9 +1,9 @@ //! Intermediate representation for modules (AKA C++ namespaces). +use super::context::{BindgenContext, ItemId}; use clang; use parse::{ClangSubItemParser, ParseError, ParseResult}; use parse_one; -use super::context::{BindgenContext, ItemId}; /// Whether this module is inline or not. #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/src/ir/objc.rs b/src/ir/objc.rs index b9fe280b..ea2cc0c8 100644 --- a/src/ir/objc.rs +++ b/src/ir/objc.rs @@ -3,8 +3,8 @@ use clang; use clang_sys::CXChildVisit_Continue; use clang_sys::CXCursor_ObjCInstanceMethodDecl; -// use clang_sys::CXCursor_ObjCSuperClassRef; use super::context::BindgenContext; +use super::function::FunctionSig; /// Objective C interface as used in TypeKind /// @@ -29,6 +29,8 @@ pub struct ObjCInstanceMethod { /// Method name as converted to rust /// like, dataWithBytes_length_ rust_name: String, + + signature: FunctionSig, } impl ObjCInterface { @@ -52,7 +54,7 @@ impl ObjCInterface { /// Parses the Objective C interface from the cursor pub fn from_ty(cursor: &clang::Cursor, - _ctx: &mut BindgenContext) + ctx: &mut BindgenContext) -> Option<Self> { let name = cursor.spelling(); let mut interface = Self::new(&name); @@ -61,7 +63,10 @@ impl ObjCInterface { match cursor.kind() { CXCursor_ObjCInstanceMethodDecl => { let name = cursor.spelling(); - let method = ObjCInstanceMethod::new(&name); + let signature = + FunctionSig::from_ty(&cursor.cur_type(), &cursor, ctx) + .expect("Invalid function sig"); + let method = ObjCInstanceMethod::new(&name, signature); interface.methods.push(method); } @@ -74,7 +79,7 @@ impl ObjCInterface { } impl ObjCInstanceMethod { - fn new(name: &str) -> ObjCInstanceMethod { + fn new(name: &str, signature: FunctionSig) -> ObjCInstanceMethod { let split_name: Vec<&str> = name.split(':').collect(); let rust_name = split_name.join("_"); @@ -82,6 +87,7 @@ impl ObjCInstanceMethod { ObjCInstanceMethod { name: name.to_owned(), rust_name: rust_name.to_owned(), + signature: signature, } } @@ -96,4 +102,33 @@ impl ObjCInstanceMethod { pub fn rust_name(&self) -> &str { self.rust_name.as_ref() } + + /// Returns the methods signature as FunctionSig + pub fn signature(&self) -> &FunctionSig { + &self.signature + } + + /// Formats the method call + pub fn format_method_call(&self, args: &[String]) -> String { + let split_name: Vec<&str> = + self.name.split(':').filter(|p| !p.is_empty()).collect(); + + // No arguments + if args.len() == 0 && split_name.len() == 1 { + return split_name[0].to_string(); + } + + // Check right amount of arguments + if args.len() != split_name.len() { + panic!("Incorrect method name or arguments for objc method, {:?} vs {:?}", + args, + split_name); + } + + split_name.iter() + .zip(args.iter()) + .map(|parts| format!("{}:{} ", parts.0, parts.1)) + .collect::<Vec<_>>() + .join("") + } } diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 8d01d905..f1e43983 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -1,7 +1,5 @@ //! Everything related to types in our intermediate representation. -use clang::{self, Cursor}; -use parse::{ClangItemParser, ParseError, ParseResult}; use super::comp::CompInfo; use super::context::{BindgenContext, ItemId}; use super::derive::{CanDeriveCopy, CanDeriveDebug}; @@ -12,6 +10,9 @@ use super::item::Item; use super::layout::Layout; use super::objc::ObjCInterface; use super::type_collector::{ItemSet, TypeCollector}; +use clang::{self, Cursor}; +use parse::{ClangItemParser, ParseError, ParseResult}; +use std::mem; /// The base representation of a type in bindgen. /// @@ -356,8 +357,87 @@ impl Type { _ => false, } } + + /// If this type has a known size, return it (in bytes). + pub fn calc_size(&self, ctx: &BindgenContext) -> Option<usize> { + match self.kind { + TypeKind::Comp(ref ci) => { + ci.calc_layout(ctx).map(|layout| layout.size) + } + TypeKind::Enum(ref enum_ty) => { + enum_ty.calc_layout(ctx).map(|layout| layout.size) + } + TypeKind::Int(int_kind) => int_kind.known_size(), + TypeKind::Float(float_kind) => Some(float_kind.known_size()), + TypeKind::Complex(float_kind) => Some(float_kind.known_size() * 2), + TypeKind::Reference(..) | + TypeKind::NullPtr | + TypeKind::Pointer(..) | + TypeKind::BlockPointer | + TypeKind::Function(..) | + TypeKind::ObjCInterface(..) => Some(mem::size_of::<*mut ()>()), + TypeKind::ResolvedTypeRef(inner) | + TypeKind::Alias(inner) | + TypeKind::TemplateAlias(inner, _) | + TypeKind::TemplateRef(inner, _) => { + ctx.resolve_type(inner).calc_size(ctx) + } + TypeKind::Array(inner, len) => { + ctx.resolve_type(inner) + .layout(ctx) + .map(|layout| layout.size * len) + } + TypeKind::Void | TypeKind::Named => None, + TypeKind::UnresolvedTypeRef(..) => unreachable!(), + } + } +} +#[test] +fn is_invalid_named_type_valid() { + let ty = Type::new(Some("foo".into()), None, TypeKind::Named, false); + assert!(!ty.is_invalid_named_type()) +} + +#[test] +fn is_invalid_named_type_valid_underscore_and_numbers() { + let ty = + Type::new(Some("_foo123456789_".into()), None, TypeKind::Named, false); + assert!(!ty.is_invalid_named_type()) +} + +#[test] +fn is_invalid_named_type_valid_unnamed_kind() { + let ty = Type::new(Some("foo".into()), None, TypeKind::Void, false); + assert!(!ty.is_invalid_named_type()) +} + +#[test] +fn is_invalid_named_type_invalid_start() { + let ty = Type::new(Some("1foo".into()), None, TypeKind::Named, false); + assert!(ty.is_invalid_named_type()) +} + +#[test] +fn is_invalid_named_type_invalid_remaing() { + let ty = Type::new(Some("foo-".into()), None, TypeKind::Named, false); + assert!(ty.is_invalid_named_type()) +} + +#[test] +#[should_panic] +fn is_invalid_named_type_unnamed() { + let ty = Type::new(None, None, TypeKind::Named, false); + assert!(ty.is_invalid_named_type()) } +#[test] +#[should_panic] +fn is_invalid_named_type_empty_name() { + let ty = Type::new(Some("".into()), None, TypeKind::Named, false); + assert!(ty.is_invalid_named_type()) +} + + impl CanDeriveDebug for Type { type Extra = (); @@ -425,6 +505,17 @@ pub enum FloatKind { Float128, } +impl FloatKind { + /// If this type has a known size, return it (in bytes). + pub fn known_size(&self) -> usize { + match *self { + FloatKind::Float => mem::size_of::<f32>(), + FloatKind::Double | FloatKind::LongDouble => mem::size_of::<f64>(), + FloatKind::Float128 => mem::size_of::<f64>() * 2, + } + } +} + /// The different kinds of types that we can parse. #[derive(Debug)] pub enum TypeKind { @@ -588,7 +679,20 @@ impl Type { let kind = match ty_kind { CXType_Unexposed if *ty != canonical_ty && - canonical_ty.kind() != CXType_Invalid => { + canonical_ty.kind() != CXType_Invalid && + // Sometime clang desugars some types more than + // what we need, specially with function + // pointers. + // + // We should also try the solution of inverting + // those checks instead of doing this, that is, + // something like: + // + // CXType_Unexposed if ty.ret_type().is_some() + // => { ... } + // + // etc. + !canonical_ty.spelling().contains("type-parameter") => { debug!("Looking for canonical type: {:?}", canonical_ty); return Self::from_clang_ty(potential_id, &canonical_ty, @@ -609,7 +713,10 @@ impl Type { // Same here, with template specialisations we can safely // assume this is a Comp(..) } else if ty.is_fully_specialized_template() { - debug!("Template specialization: {:?}", ty); + debug!("Template specialization: {:?}, {:?} {:?}", + ty, + location, + canonical_ty); let complex = CompInfo::from_ty(potential_id, ty, location, ctx) .expect("C'mon"); diff --git a/src/ir/type_collector.rs b/src/ir/type_collector.rs index 0f10152d..25285b23 100644 --- a/src/ir/type_collector.rs +++ b/src/ir/type_collector.rs @@ -1,7 +1,7 @@ //! Collecting type items. -use std::collections::BTreeSet; use super::context::{BindgenContext, ItemId}; +use std::collections::BTreeSet; /// A set of items. pub type ItemSet = BTreeSet<ItemId>; diff --git a/src/ir/var.rs b/src/ir/var.rs index 329393fa..6cfcdae7 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -1,14 +1,14 @@ //! Intermediate representation of variables. -use cexpr; -use clang; -use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult}; -use std::num::Wrapping; use super::context::{BindgenContext, ItemId}; use super::function::cursor_mangling; use super::int::IntKind; use super::item::Item; use super::ty::{FloatKind, TypeKind}; +use cexpr; +use clang; +use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult}; +use std::num::Wrapping; /// The type for a constant variable. #[derive(Debug)] @@ -149,18 +149,18 @@ impl ClangSubItemParser for Var { EvalResult::Int(Wrapping(value)) => { let kind = ctx.type_chooser() .and_then(|c| c.int_macro(&name, value)) - .unwrap_or_else(|| { - if value < 0 { - if value < i32::min_value() as i64 { - IntKind::LongLong - } else { - IntKind::Int - } - } else if value > u32::max_value() as i64 { - IntKind::ULongLong + .unwrap_or_else(|| if value < 0 { + if value < i32::min_value() as i64 { + IntKind::LongLong } else { - IntKind::UInt + IntKind::Int } + } else if value > + u32::max_value() as + i64 { + IntKind::ULongLong + } else { + IntKind::UInt }); (TypeKind::Int(kind), VarType::Int(value)) @@ -187,7 +187,8 @@ impl ClangSubItemParser for Var { let ty = match Item::from_ty(&ty, Some(cursor), None, ctx) { Ok(ty) => ty, Err(e) => { - assert_eq!(ty.kind(), CXType_Auto, + assert_eq!(ty.kind(), + CXType_Auto, "Couldn't resolve constant type, and it \ wasn't an nondeductible auto type!"); return Err(e); @@ -222,12 +223,10 @@ impl ClangSubItemParser for Var { val = get_integer_literal_from_cursor(&cursor, tu); } - val.map(|val| { - if kind == IntKind::Bool { - VarType::Bool(val != 0) - } else { - VarType::Int(val) - } + val.map(|val| if kind == IntKind::Bool { + VarType::Bool(val != 0) + } else { + VarType::Int(val) }) } else if is_float { cursor.evaluate() @@ -525,7 +525,6 @@ pub struct BindgenOptions { /// The input header file. pub input_header: Option<String>, - /// Generate a dummy C/C++ file that includes the header and has dummy uses /// of all types defined therein. See the `uses` module for more. pub dummy_uses: Option<String>, @@ -759,16 +758,16 @@ impl<'ctx> Bindings<'ctx> { /// /// See the `uses` module for more information. pub fn write_dummy_uses(&mut self) -> io::Result<()> { - let file = - if let Some(ref dummy_path) = self.context.options().dummy_uses { - Some(try!(OpenOptions::new() + let file = if let Some(ref dummy_path) = + self.context.options().dummy_uses { + Some(try!(OpenOptions::new() .write(true) .truncate(true) .create(true) .open(dummy_path))) - } else { - None - }; + } else { + None + }; if let Some(file) = file { try!(uses::generate_dummy_uses(&mut self.context, file)); diff --git a/src/main.rs b/src/main.rs index 7f424318..68f3d0a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,9 +36,7 @@ pub fn main() { match version.parsed { None => warn!("Couldn't parse libclang version"), Some(version) if version != expected_version => { - warn!("Using clang {:?}, expected {:?}", - version, - expected_version); + warn!("Using clang {:?}, expected {:?}", version, expected_version); } _ => {} } diff --git a/src/options.rs b/src/options.rs index 63df8b2a..5231ad24 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,5 +1,5 @@ -use clap::{App, Arg}; use bindgen::{Builder, CodegenConfig, builder}; +use clap::{App, Arg}; use std::fs::File; use std::io::{self, Error, ErrorKind}; diff --git a/src/regex_set.rs b/src/regex_set.rs index dbdb6565..2eff740b 100644 --- a/src/regex_set.rs +++ b/src/regex_set.rs @@ -21,7 +21,7 @@ impl RegexSet { /// Extend this set with every regex in the iterator. pub fn extend<I, S>(&mut self, iter: I) where I: IntoIterator<Item = S>, - S: AsRef<str> + S: AsRef<str>, { for s in iter.into_iter() { self.insert(s) @@ -30,7 +30,7 @@ impl RegexSet { /// Insert a new regex into this set. pub fn insert<S>(&mut self, string: S) - where S: AsRef<str> + where S: AsRef<str>, { self.items.push(format!("^{}$", string.as_ref())); self.set = None; @@ -46,13 +46,13 @@ impl RegexSet { Err(e) => { error!("Invalid regex in {:?}: {:?}", self.items, e); None - }, + } } } /// Does the given `string` match any of the regexes in this set? pub fn matches<S>(&self, string: S) -> bool - where S: AsRef<str> + where S: AsRef<str>, { let s = string.as_ref(); self.set.as_ref().map(|set| set.is_match(s)).unwrap_or(false) diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index b28c0537..b9dd74e3 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -51,27 +51,66 @@ pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { assert_eq!(::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>() - , 4usize); - assert_eq!(::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>() - , 2usize); + , 4usize , concat ! ( + "Size of: " , stringify ! ( + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>() + , 2usize , concat ! ( + "Alignment of " , stringify ! ( + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( + * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) + ) . dport as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" , + stringify ! ( dport ) )); + assert_eq! (unsafe { + & ( + * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) + ) . sport as * const _ as usize } , 2usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" , + stringify ! ( sport ) )); } impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1>() , - 4usize); - assert_eq!(::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1>() , - 4usize); + assert_eq!(::std::mem::size_of::<rte_ipv4_tuple__bindgen_ty_1>() , 4usize + , concat ! ( + "Size of: " , stringify ! ( rte_ipv4_tuple__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<rte_ipv4_tuple__bindgen_ty_1>() , + 4usize , concat ! ( + "Alignment of " , stringify ! ( rte_ipv4_tuple__bindgen_ty_1 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_ipv4_tuple__bindgen_ty_1 ) ) . + sctp_tag as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_ipv4_tuple__bindgen_ty_1 ) , "::" , stringify ! ( sctp_tag + ) )); } impl Clone for rte_ipv4_tuple__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_rte_ipv4_tuple() { - assert_eq!(::std::mem::size_of::<rte_ipv4_tuple>() , 12usize); - assert_eq!(::std::mem::align_of::<rte_ipv4_tuple>() , 4usize); + assert_eq!(::std::mem::size_of::<rte_ipv4_tuple>() , 12usize , concat ! ( + "Size of: " , stringify ! ( rte_ipv4_tuple ) )); + assert_eq! (::std::mem::align_of::<rte_ipv4_tuple>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( rte_ipv4_tuple ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_ipv4_tuple ) ) . src_addr as * const + _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_ipv4_tuple ) , "::" + , stringify ! ( src_addr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_ipv4_tuple ) ) . dst_addr as * const + _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_ipv4_tuple ) , "::" + , stringify ! ( dst_addr ) )); } impl Clone for rte_ipv4_tuple { fn clone(&self) -> Self { *self } @@ -99,27 +138,66 @@ pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { assert_eq!(::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>() - , 4usize); - assert_eq!(::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>() - , 2usize); + , 4usize , concat ! ( + "Size of: " , stringify ! ( + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>() + , 2usize , concat ! ( + "Alignment of " , stringify ! ( + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( + * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) + ) . dport as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" , + stringify ! ( dport ) )); + assert_eq! (unsafe { + & ( + * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) + ) . sport as * const _ as usize } , 2usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 ) , "::" , + stringify ! ( sport ) )); } impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1>() , - 4usize); - assert_eq!(::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1>() , - 4usize); + assert_eq!(::std::mem::size_of::<rte_ipv6_tuple__bindgen_ty_1>() , 4usize + , concat ! ( + "Size of: " , stringify ! ( rte_ipv6_tuple__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<rte_ipv6_tuple__bindgen_ty_1>() , + 4usize , concat ! ( + "Alignment of " , stringify ! ( rte_ipv6_tuple__bindgen_ty_1 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_ipv6_tuple__bindgen_ty_1 ) ) . + sctp_tag as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_ipv6_tuple__bindgen_ty_1 ) , "::" , stringify ! ( sctp_tag + ) )); } impl Clone for rte_ipv6_tuple__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_rte_ipv6_tuple() { - assert_eq!(::std::mem::size_of::<rte_ipv6_tuple>() , 36usize); - assert_eq!(::std::mem::align_of::<rte_ipv6_tuple>() , 4usize); + assert_eq!(::std::mem::size_of::<rte_ipv6_tuple>() , 36usize , concat ! ( + "Size of: " , stringify ! ( rte_ipv6_tuple ) )); + assert_eq! (::std::mem::align_of::<rte_ipv6_tuple>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( rte_ipv6_tuple ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_ipv6_tuple ) ) . src_addr as * const + _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_ipv6_tuple ) , "::" + , stringify ! ( src_addr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_ipv6_tuple ) ) . dst_addr as * const + _ as usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_ipv6_tuple ) , "::" + , stringify ! ( dst_addr ) )); } impl Clone for rte_ipv6_tuple { fn clone(&self) -> Self { *self } @@ -131,6 +209,21 @@ pub struct rte_thash_tuple { pub v6: __BindgenUnionField<rte_ipv6_tuple>, pub bindgen_union_field: [u8; 48usize], } +#[test] +fn bindgen_test_layout_rte_thash_tuple() { + assert_eq!(::std::mem::size_of::<rte_thash_tuple>() , 48usize , concat ! ( + "Size of: " , stringify ! ( rte_thash_tuple ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_thash_tuple ) ) . v4 as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_thash_tuple ) , + "::" , stringify ! ( v4 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_thash_tuple ) ) . v6 as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_thash_tuple ) , + "::" , stringify ! ( v6 ) )); +} impl Clone for rte_thash_tuple { fn clone(&self) -> Self { *self } } diff --git a/tests/expectations/tests/accessors.rs b/tests/expectations/tests/accessors.rs index b721980c..c0d95bfb 100644 --- a/tests/expectations/tests/accessors.rs +++ b/tests/expectations/tests/accessors.rs @@ -17,8 +17,30 @@ pub struct SomeAccessors { } #[test] fn bindgen_test_layout_SomeAccessors() { - assert_eq!(::std::mem::size_of::<SomeAccessors>() , 16usize); - assert_eq!(::std::mem::align_of::<SomeAccessors>() , 4usize); + assert_eq!(::std::mem::size_of::<SomeAccessors>() , 16usize , concat ! ( + "Size of: " , stringify ! ( SomeAccessors ) )); + assert_eq! (::std::mem::align_of::<SomeAccessors>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( SomeAccessors ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const SomeAccessors ) ) . mNoAccessor as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( SomeAccessors ) , "::" + , stringify ! ( mNoAccessor ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const SomeAccessors ) ) . mBothAccessors as * + const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( SomeAccessors ) , "::" + , stringify ! ( mBothAccessors ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const SomeAccessors ) ) . mUnsafeAccessors as * + const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( SomeAccessors ) , "::" + , stringify ! ( mUnsafeAccessors ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const SomeAccessors ) ) . mImmutableAccessor as + * const _ as usize } , 12usize , concat ! ( + "Alignment of field: " , stringify ! ( SomeAccessors ) , "::" + , stringify ! ( mImmutableAccessor ) )); } impl Clone for SomeAccessors { fn clone(&self) -> Self { *self } @@ -55,8 +77,20 @@ pub struct AllAccessors { } #[test] fn bindgen_test_layout_AllAccessors() { - assert_eq!(::std::mem::size_of::<AllAccessors>() , 8usize); - assert_eq!(::std::mem::align_of::<AllAccessors>() , 4usize); + assert_eq!(::std::mem::size_of::<AllAccessors>() , 8usize , concat ! ( + "Size of: " , stringify ! ( AllAccessors ) )); + assert_eq! (::std::mem::align_of::<AllAccessors>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( AllAccessors ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const AllAccessors ) ) . mBothAccessors as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( AllAccessors ) , "::" , + stringify ! ( mBothAccessors ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const AllAccessors ) ) . mAlsoBothAccessors as + * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( AllAccessors ) , "::" , + stringify ! ( mAlsoBothAccessors ) )); } impl Clone for AllAccessors { fn clone(&self) -> Self { *self } @@ -89,8 +123,21 @@ pub struct AllUnsafeAccessors { } #[test] fn bindgen_test_layout_AllUnsafeAccessors() { - assert_eq!(::std::mem::size_of::<AllUnsafeAccessors>() , 8usize); - assert_eq!(::std::mem::align_of::<AllUnsafeAccessors>() , 4usize); + assert_eq!(::std::mem::size_of::<AllUnsafeAccessors>() , 8usize , concat ! + ( "Size of: " , stringify ! ( AllUnsafeAccessors ) )); + assert_eq! (::std::mem::align_of::<AllUnsafeAccessors>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( AllUnsafeAccessors ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const AllUnsafeAccessors ) ) . mBothAccessors + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( AllUnsafeAccessors ) , + "::" , stringify ! ( mBothAccessors ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const AllUnsafeAccessors ) ) . + mAlsoBothAccessors as * const _ as usize } , 4usize , concat ! + ( + "Alignment of field: " , stringify ! ( AllUnsafeAccessors ) , + "::" , stringify ! ( mAlsoBothAccessors ) )); } impl Clone for AllUnsafeAccessors { fn clone(&self) -> Self { *self } @@ -129,8 +176,32 @@ pub struct ContradictAccessors { } #[test] fn bindgen_test_layout_ContradictAccessors() { - assert_eq!(::std::mem::size_of::<ContradictAccessors>() , 16usize); - assert_eq!(::std::mem::align_of::<ContradictAccessors>() , 4usize); + assert_eq!(::std::mem::size_of::<ContradictAccessors>() , 16usize , concat + ! ( "Size of: " , stringify ! ( ContradictAccessors ) )); + assert_eq! (::std::mem::align_of::<ContradictAccessors>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( ContradictAccessors ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ContradictAccessors ) ) . mBothAccessors + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( ContradictAccessors ) , + "::" , stringify ! ( mBothAccessors ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ContradictAccessors ) ) . mNoAccessors as + * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( ContradictAccessors ) , + "::" , stringify ! ( mNoAccessors ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ContradictAccessors ) ) . + mUnsafeAccessors as * const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( ContradictAccessors ) , + "::" , stringify ! ( mUnsafeAccessors ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ContradictAccessors ) ) . + mImmutableAccessor as * const _ as usize } , 12usize , concat + ! ( + "Alignment of field: " , stringify ! ( ContradictAccessors ) , + "::" , stringify ! ( mImmutableAccessor ) )); } impl Clone for ContradictAccessors { fn clone(&self) -> Self { *self } @@ -166,8 +237,15 @@ pub struct Replaced { } #[test] fn bindgen_test_layout_Replaced() { - assert_eq!(::std::mem::size_of::<Replaced>() , 4usize); - assert_eq!(::std::mem::align_of::<Replaced>() , 4usize); + assert_eq!(::std::mem::size_of::<Replaced>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Replaced ) )); + assert_eq! (::std::mem::align_of::<Replaced>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Replaced ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Replaced ) ) . mAccessor as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Replaced ) , "::" , + stringify ! ( mAccessor ) )); } impl Clone for Replaced { fn clone(&self) -> Self { *self } @@ -188,8 +266,15 @@ pub struct Wrapper { } #[test] fn bindgen_test_layout_Wrapper() { - assert_eq!(::std::mem::size_of::<Wrapper>() , 4usize); - assert_eq!(::std::mem::align_of::<Wrapper>() , 4usize); + assert_eq!(::std::mem::size_of::<Wrapper>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Wrapper ) )); + assert_eq! (::std::mem::align_of::<Wrapper>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Wrapper ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Wrapper ) ) . mReplaced as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Wrapper ) , "::" , + stringify ! ( mReplaced ) )); } impl Clone for Wrapper { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs index dcaf7997..62840b13 100644 --- a/tests/expectations/tests/annotation_hide.rs +++ b/tests/expectations/tests/annotation_hide.rs @@ -14,8 +14,10 @@ pub struct D { } #[test] fn bindgen_test_layout_D() { - assert_eq!(::std::mem::size_of::<D>() , 4usize); - assert_eq!(::std::mem::align_of::<D>() , 4usize); + assert_eq!(::std::mem::size_of::<D>() , 4usize , concat ! ( + "Size of: " , stringify ! ( D ) )); + assert_eq! (::std::mem::align_of::<D>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( D ) )); } impl Clone for D { fn clone(&self) -> Self { *self } @@ -27,8 +29,15 @@ pub struct NotAnnotated { } #[test] fn bindgen_test_layout_NotAnnotated() { - assert_eq!(::std::mem::size_of::<NotAnnotated>() , 4usize); - assert_eq!(::std::mem::align_of::<NotAnnotated>() , 4usize); + assert_eq!(::std::mem::size_of::<NotAnnotated>() , 4usize , concat ! ( + "Size of: " , stringify ! ( NotAnnotated ) )); + assert_eq! (::std::mem::align_of::<NotAnnotated>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( NotAnnotated ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const NotAnnotated ) ) . f as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( NotAnnotated ) , "::" , + stringify ! ( f ) )); } impl Clone for NotAnnotated { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs index 3b05eab8..b2c7f5fc 100644 --- a/tests/expectations/tests/anon_enum.rs +++ b/tests/expectations/tests/anon_enum.rs @@ -16,8 +16,20 @@ pub const Test_T_NONE: Test__bindgen_ty_1 = Test__bindgen_ty_1::T_NONE; pub enum Test__bindgen_ty_1 { T_NONE = 0, } #[test] fn bindgen_test_layout_Test() { - assert_eq!(::std::mem::size_of::<Test>() , 8usize); - assert_eq!(::std::mem::align_of::<Test>() , 4usize); + assert_eq!(::std::mem::size_of::<Test>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Test ) )); + assert_eq! (::std::mem::align_of::<Test>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Test ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . foo as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . bar as * const _ as usize } , + 4usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( bar ) )); } impl Clone for Test { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/anon_enum_trait.rs b/tests/expectations/tests/anon_enum_trait.rs index 8198bc15..c258f7d6 100644 --- a/tests/expectations/tests/anon_enum_trait.rs +++ b/tests/expectations/tests/anon_enum_trait.rs @@ -39,8 +39,10 @@ pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; pub enum Foo__bindgen_ty_1 { Bar = 0, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::<Foo>() , 1usize); - assert_eq!(::std::mem::align_of::<Foo>() , 1usize); + assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); } impl Clone for Foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index f8559ca9..6ded1e57 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -69,8 +69,10 @@ pub struct ErrorResult { } #[test] fn bindgen_test_layout_ErrorResult() { - assert_eq!(::std::mem::size_of::<ErrorResult>() , 24usize); - assert_eq!(::std::mem::align_of::<ErrorResult>() , 8usize); + assert_eq!(::std::mem::size_of::<ErrorResult>() , 24usize , concat ! ( + "Size of: " , stringify ! ( ErrorResult ) )); + assert_eq! (::std::mem::align_of::<ErrorResult>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( ErrorResult ) )); } impl Clone for ErrorResult { fn clone(&self) -> Self { *self } @@ -78,7 +80,11 @@ impl Clone for ErrorResult { #[test] fn __bindgen_test_layout_template_1() { assert_eq!(::std::mem::size_of::<TErrorResult<::std::os::raw::c_int>>() , - 24usize); + 24usize , concat ! ( + "Size of template specialization: " , stringify ! ( + TErrorResult<::std::os::raw::c_int> ) )); assert_eq!(::std::mem::align_of::<TErrorResult<::std::os::raw::c_int>>() , - 8usize); + 8usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + TErrorResult<::std::os::raw::c_int> ) )); } diff --git a/tests/expectations/tests/auto.rs b/tests/expectations/tests/auto.rs index 6224e807..554546af 100644 --- a/tests/expectations/tests/auto.rs +++ b/tests/expectations/tests/auto.rs @@ -12,8 +12,10 @@ pub struct Foo { pub const Foo_kFoo: bool = true; #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::<Foo>() , 1usize); - assert_eq!(::std::mem::align_of::<Foo>() , 1usize); + assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); } impl Clone for Foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/base-to-derived.rs b/tests/expectations/tests/base-to-derived.rs index c2af2c43..4749096b 100644 --- a/tests/expectations/tests/base-to-derived.rs +++ b/tests/expectations/tests/base-to-derived.rs @@ -11,8 +11,10 @@ pub struct false_type { } #[test] fn bindgen_test_layout_false_type() { - assert_eq!(::std::mem::size_of::<false_type>() , 1usize); - assert_eq!(::std::mem::align_of::<false_type>() , 1usize); + assert_eq!(::std::mem::size_of::<false_type>() , 1usize , concat ! ( + "Size of: " , stringify ! ( false_type ) )); + assert_eq! (::std::mem::align_of::<false_type>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( false_type ) )); } impl Clone for false_type { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/bitfield-enum-basic.rs b/tests/expectations/tests/bitfield-enum-basic.rs index 7674af8b..a8d3ecc5 100644 --- a/tests/expectations/tests/bitfield-enum-basic.rs +++ b/tests/expectations/tests/bitfield-enum-basic.rs @@ -69,8 +69,10 @@ impl ::std::ops::BitOr<Dummy__bindgen_ty_1> for Dummy__bindgen_ty_1 { pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint); #[test] fn bindgen_test_layout_Dummy() { - assert_eq!(::std::mem::size_of::<Dummy>() , 1usize); - assert_eq!(::std::mem::align_of::<Dummy>() , 1usize); + assert_eq!(::std::mem::size_of::<Dummy>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Dummy ) )); + assert_eq! (::std::mem::align_of::<Dummy>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Dummy ) )); } impl Clone for Dummy { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/bitfield_method_mangling.rs b/tests/expectations/tests/bitfield_method_mangling.rs index 5aba8abb..94f0aa8e 100644 --- a/tests/expectations/tests/bitfield_method_mangling.rs +++ b/tests/expectations/tests/bitfield_method_mangling.rs @@ -11,8 +11,10 @@ pub struct _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<_bindgen_ty_1>() , 4usize); - assert_eq!(::std::mem::align_of::<_bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<_bindgen_ty_1>() , 4usize , concat ! ( + "Size of: " , stringify ! ( _bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<_bindgen_ty_1>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( _bindgen_ty_1 ) )); } impl Clone for _bindgen_ty_1 { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/canonical_path_without_namespacing.rs b/tests/expectations/tests/canonical_path_without_namespacing.rs index 0b1f561c..dff6b707 100644 --- a/tests/expectations/tests/canonical_path_without_namespacing.rs +++ b/tests/expectations/tests/canonical_path_without_namespacing.rs @@ -11,8 +11,10 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 1usize); - assert_eq!(::std::mem::align_of::<Bar>() , 1usize); + assert_eq!(::std::mem::size_of::<Bar>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); } impl Clone for Bar { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index e55a9fe3..46adbc29 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -67,8 +67,19 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::<C>() , 40usize); - assert_eq!(::std::mem::align_of::<C>() , 4usize); + assert_eq!(::std::mem::size_of::<C>() , 40usize , concat ! ( + "Size of: " , stringify ! ( C ) )); + assert_eq! (::std::mem::align_of::<C>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( C ) )); + assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . a as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C ) ) . big_array as * const _ as usize } + , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( big_array ) )); } #[repr(C)] pub struct C_with_zero_length_array { @@ -78,8 +89,30 @@ pub struct C_with_zero_length_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array() { - assert_eq!(::std::mem::size_of::<C_with_zero_length_array>() , 40usize); - assert_eq!(::std::mem::align_of::<C_with_zero_length_array>() , 4usize); + assert_eq!(::std::mem::size_of::<C_with_zero_length_array>() , 40usize , + concat ! ( + "Size of: " , stringify ! ( C_with_zero_length_array ) )); + assert_eq! (::std::mem::align_of::<C_with_zero_length_array>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( C_with_zero_length_array ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C_with_zero_length_array ) ) . a as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + C_with_zero_length_array ) , "::" , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C_with_zero_length_array ) ) . big_array + as * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( + C_with_zero_length_array ) , "::" , stringify ! ( big_array ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const C_with_zero_length_array ) ) . + zero_length_array as * const _ as usize } , 37usize , concat ! + ( + "Alignment of field: " , stringify ! ( + C_with_zero_length_array ) , "::" , stringify ! ( + zero_length_array ) )); } #[repr(C)] pub struct C_with_incomplete_array { @@ -89,8 +122,12 @@ pub struct C_with_incomplete_array { } #[test] fn bindgen_test_layout_C_with_incomplete_array() { - assert_eq!(::std::mem::size_of::<C_with_incomplete_array>() , 40usize); - assert_eq!(::std::mem::align_of::<C_with_incomplete_array>() , 4usize); + assert_eq!(::std::mem::size_of::<C_with_incomplete_array>() , 40usize , + concat ! ( + "Size of: " , stringify ! ( C_with_incomplete_array ) )); + assert_eq! (::std::mem::align_of::<C_with_incomplete_array>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( C_with_incomplete_array ) )); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -102,9 +139,13 @@ pub struct C_with_zero_length_array_and_incomplete_array { #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { assert_eq!(::std::mem::size_of::<C_with_zero_length_array_and_incomplete_array>() - , 40usize); - assert_eq!(::std::mem::align_of::<C_with_zero_length_array_and_incomplete_array>() - , 4usize); + , 40usize , concat ! ( + "Size of: " , stringify ! ( + C_with_zero_length_array_and_incomplete_array ) )); + assert_eq! (::std::mem::align_of::<C_with_zero_length_array_and_incomplete_array>() + , 4usize , concat ! ( + "Alignment of " , stringify ! ( + C_with_zero_length_array_and_incomplete_array ) )); } #[repr(C)] #[derive(Debug)] @@ -113,8 +154,15 @@ pub struct WithDtor { } #[test] fn bindgen_test_layout_WithDtor() { - assert_eq!(::std::mem::size_of::<WithDtor>() , 4usize); - assert_eq!(::std::mem::align_of::<WithDtor>() , 4usize); + assert_eq!(::std::mem::size_of::<WithDtor>() , 4usize , concat ! ( + "Size of: " , stringify ! ( WithDtor ) )); + assert_eq! (::std::mem::align_of::<WithDtor>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( WithDtor ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithDtor ) ) . b as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WithDtor ) , "::" , + stringify ! ( b ) )); } #[repr(C)] pub struct IncompleteArrayNonCopiable { @@ -123,8 +171,13 @@ pub struct IncompleteArrayNonCopiable { } #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { - assert_eq!(::std::mem::size_of::<IncompleteArrayNonCopiable>() , 8usize); - assert_eq!(::std::mem::align_of::<IncompleteArrayNonCopiable>() , 8usize); + assert_eq!(::std::mem::size_of::<IncompleteArrayNonCopiable>() , 8usize , + concat ! ( + "Size of: " , stringify ! ( IncompleteArrayNonCopiable ) )); + assert_eq! (::std::mem::align_of::<IncompleteArrayNonCopiable>() , 8usize + , concat ! ( + "Alignment of " , stringify ! ( IncompleteArrayNonCopiable ) + )); } #[repr(C)] #[derive(Debug, Copy)] @@ -135,8 +188,20 @@ pub struct Union { } #[test] fn bindgen_test_layout_Union() { - assert_eq!(::std::mem::size_of::<Union>() , 4usize); - assert_eq!(::std::mem::align_of::<Union>() , 4usize); + assert_eq!(::std::mem::size_of::<Union>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Union ) )); + assert_eq! (::std::mem::align_of::<Union>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Union ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Union ) ) . d as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Union ) , "::" , + stringify ! ( d ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Union ) ) . i as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Union ) , "::" , + stringify ! ( i ) )); } impl Clone for Union { fn clone(&self) -> Self { *self } @@ -148,8 +213,15 @@ pub struct WithUnion { } #[test] fn bindgen_test_layout_WithUnion() { - assert_eq!(::std::mem::size_of::<WithUnion>() , 4usize); - assert_eq!(::std::mem::align_of::<WithUnion>() , 4usize); + assert_eq!(::std::mem::size_of::<WithUnion>() , 4usize , concat ! ( + "Size of: " , stringify ! ( WithUnion ) )); + assert_eq! (::std::mem::align_of::<WithUnion>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( WithUnion ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithUnion ) ) . data as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WithUnion ) , "::" , + stringify ! ( data ) )); } impl Clone for WithUnion { fn clone(&self) -> Self { *self } @@ -162,9 +234,13 @@ pub struct RealAbstractionWithTonsOfMethods { #[test] fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!(::std::mem::size_of::<RealAbstractionWithTonsOfMethods>() , - 1usize); - assert_eq!(::std::mem::align_of::<RealAbstractionWithTonsOfMethods>() , - 1usize); + 1usize , concat ! ( + "Size of: " , stringify ! ( RealAbstractionWithTonsOfMethods ) + )); + assert_eq! (::std::mem::align_of::<RealAbstractionWithTonsOfMethods>() , + 1usize , concat ! ( + "Alignment of " , stringify ! ( + RealAbstractionWithTonsOfMethods ) )); } extern "C" { #[link_name = "_ZNK32RealAbstractionWithTonsOfMethods3barEv"] diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index 593e156d..8a4125c9 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -16,16 +16,30 @@ pub struct A_B { } #[test] fn bindgen_test_layout_A_B() { - assert_eq!(::std::mem::size_of::<A_B>() , 4usize); - assert_eq!(::std::mem::align_of::<A_B>() , 4usize); + assert_eq!(::std::mem::size_of::<A_B>() , 4usize , concat ! ( + "Size of: " , stringify ! ( A_B ) )); + assert_eq! (::std::mem::align_of::<A_B>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( A_B ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const A_B ) ) . member_b as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( A_B ) , "::" , + stringify ! ( member_b ) )); } impl Clone for A_B { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::<A>() , 4usize); - assert_eq!(::std::mem::align_of::<A>() , 4usize); + assert_eq!(::std::mem::size_of::<A>() , 4usize , concat ! ( + "Size of: " , stringify ! ( A ) )); + assert_eq! (::std::mem::align_of::<A>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( A ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const A ) ) . member_a as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( A ) , "::" , stringify + ! ( member_a ) )); } impl Clone for A { fn clone(&self) -> Self { *self } @@ -41,8 +55,15 @@ pub struct D { } #[test] fn bindgen_test_layout_D() { - assert_eq!(::std::mem::size_of::<D>() , 4usize); - assert_eq!(::std::mem::align_of::<D>() , 4usize); + assert_eq!(::std::mem::size_of::<D>() , 4usize , concat ! ( + "Size of: " , stringify ! ( D ) )); + assert_eq! (::std::mem::align_of::<D>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( D ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const D ) ) . member as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( D ) , "::" , stringify + ! ( member ) )); } impl Clone for D { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/class_no_members.rs b/tests/expectations/tests/class_no_members.rs index 017f7c22..e41e3ffc 100644 --- a/tests/expectations/tests/class_no_members.rs +++ b/tests/expectations/tests/class_no_members.rs @@ -11,8 +11,10 @@ pub struct whatever { } #[test] fn bindgen_test_layout_whatever() { - assert_eq!(::std::mem::size_of::<whatever>() , 1usize); - assert_eq!(::std::mem::align_of::<whatever>() , 1usize); + assert_eq!(::std::mem::size_of::<whatever>() , 1usize , concat ! ( + "Size of: " , stringify ! ( whatever ) )); + assert_eq! (::std::mem::align_of::<whatever>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( whatever ) )); } impl Clone for whatever { fn clone(&self) -> Self { *self } @@ -24,8 +26,10 @@ pub struct whatever_child { } #[test] fn bindgen_test_layout_whatever_child() { - assert_eq!(::std::mem::size_of::<whatever_child>() , 1usize); - assert_eq!(::std::mem::align_of::<whatever_child>() , 1usize); + assert_eq!(::std::mem::size_of::<whatever_child>() , 1usize , concat ! ( + "Size of: " , stringify ! ( whatever_child ) )); + assert_eq! (::std::mem::align_of::<whatever_child>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( whatever_child ) )); } impl Clone for whatever_child { fn clone(&self) -> Self { *self } @@ -37,8 +41,19 @@ pub struct whatever_child_with_member { } #[test] fn bindgen_test_layout_whatever_child_with_member() { - assert_eq!(::std::mem::size_of::<whatever_child_with_member>() , 4usize); - assert_eq!(::std::mem::align_of::<whatever_child_with_member>() , 4usize); + assert_eq!(::std::mem::size_of::<whatever_child_with_member>() , 4usize , + concat ! ( + "Size of: " , stringify ! ( whatever_child_with_member ) )); + assert_eq! (::std::mem::align_of::<whatever_child_with_member>() , 4usize + , concat ! ( + "Alignment of " , stringify ! ( whatever_child_with_member ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const whatever_child_with_member ) ) . m_member + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + whatever_child_with_member ) , "::" , stringify ! ( m_member ) + )); } impl Clone for whatever_child_with_member { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/class_static.rs b/tests/expectations/tests/class_static.rs index 8108be2d..207295b6 100644 --- a/tests/expectations/tests/class_static.rs +++ b/tests/expectations/tests/class_static.rs @@ -20,8 +20,10 @@ extern "C" { } #[test] fn bindgen_test_layout_MyClass() { - assert_eq!(::std::mem::size_of::<MyClass>() , 1usize); - assert_eq!(::std::mem::align_of::<MyClass>() , 1usize); + assert_eq!(::std::mem::size_of::<MyClass>() , 1usize , concat ! ( + "Size of: " , stringify ! ( MyClass ) )); + assert_eq! (::std::mem::align_of::<MyClass>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( MyClass ) )); } impl Clone for MyClass { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/class_static_const.rs b/tests/expectations/tests/class_static_const.rs index eed6590c..5e59485b 100644 --- a/tests/expectations/tests/class_static_const.rs +++ b/tests/expectations/tests/class_static_const.rs @@ -14,8 +14,10 @@ pub const A_b: i32 = 63; pub const A_c: u32 = 255; #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::<A>() , 1usize); - assert_eq!(::std::mem::align_of::<A>() , 1usize); + assert_eq!(::std::mem::size_of::<A>() , 1usize , concat ! ( + "Size of: " , stringify ! ( A ) )); + assert_eq! (::std::mem::align_of::<A>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( A ) )); } impl Clone for A { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs index c3843b31..9184c9c8 100644 --- a/tests/expectations/tests/class_use_as.rs +++ b/tests/expectations/tests/class_use_as.rs @@ -14,8 +14,15 @@ pub struct whatever { } #[test] fn bindgen_test_layout_whatever() { - assert_eq!(::std::mem::size_of::<whatever>() , 4usize); - assert_eq!(::std::mem::align_of::<whatever>() , 4usize); + assert_eq!(::std::mem::size_of::<whatever>() , 4usize , concat ! ( + "Size of: " , stringify ! ( whatever ) )); + assert_eq! (::std::mem::align_of::<whatever>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( whatever ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const whatever ) ) . replacement as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( whatever ) , "::" , + stringify ! ( replacement ) )); } impl Clone for whatever { fn clone(&self) -> Self { *self } @@ -27,8 +34,15 @@ pub struct container { } #[test] fn bindgen_test_layout_container() { - assert_eq!(::std::mem::size_of::<container>() , 4usize); - assert_eq!(::std::mem::align_of::<container>() , 4usize); + assert_eq!(::std::mem::size_of::<container>() , 4usize , concat ! ( + "Size of: " , stringify ! ( container ) )); + assert_eq! (::std::mem::align_of::<container>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( container ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const container ) ) . c as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( container ) , "::" , + stringify ! ( c ) )); } impl Clone for container { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs index 8fa0951f..1d8e6b4d 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -17,13 +17,24 @@ pub struct WithoutDtor { } #[test] fn bindgen_test_layout_WithoutDtor() { - assert_eq!(::std::mem::size_of::<WithoutDtor>() , 8usize); - assert_eq!(::std::mem::align_of::<WithoutDtor>() , 8usize); + assert_eq!(::std::mem::size_of::<WithoutDtor>() , 8usize , concat ! ( + "Size of: " , stringify ! ( WithoutDtor ) )); + assert_eq! (::std::mem::align_of::<WithoutDtor>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( WithoutDtor ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithoutDtor ) ) . shouldBeWithDtor as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WithoutDtor ) , "::" , + stringify ! ( shouldBeWithDtor ) )); } #[test] fn __bindgen_test_layout_template_1() { assert_eq!(::std::mem::size_of::<HandleWithDtor<::std::os::raw::c_int>>() - , 8usize); + , 8usize , concat ! ( + "Size of template specialization: " , stringify ! ( + HandleWithDtor<::std::os::raw::c_int> ) )); assert_eq!(::std::mem::align_of::<HandleWithDtor<::std::os::raw::c_int>>() - , 8usize); + , 8usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + HandleWithDtor<::std::os::raw::c_int> ) )); } diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index a1bacbdb..1056fd69 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -43,8 +43,20 @@ pub struct A_Segment { } #[test] fn bindgen_test_layout_A_Segment() { - assert_eq!(::std::mem::size_of::<A_Segment>() , 8usize); - assert_eq!(::std::mem::align_of::<A_Segment>() , 4usize); + assert_eq!(::std::mem::size_of::<A_Segment>() , 8usize , concat ! ( + "Size of: " , stringify ! ( A_Segment ) )); + assert_eq! (::std::mem::align_of::<A_Segment>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( A_Segment ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const A_Segment ) ) . begin as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( A_Segment ) , "::" , + stringify ! ( begin ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const A_Segment ) ) . end as * const _ as usize + } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( A_Segment ) , "::" , + stringify ! ( end ) )); } impl Clone for A_Segment { fn clone(&self) -> Self { *self } @@ -57,8 +69,15 @@ pub struct A__bindgen_ty_1 { } #[test] fn bindgen_test_layout_A__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<A__bindgen_ty_1>() , 4usize); - assert_eq!(::std::mem::align_of::<A__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<A__bindgen_ty_1>() , 4usize , concat ! ( + "Size of: " , stringify ! ( A__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<A__bindgen_ty_1>() , 4usize , concat ! + ( "Alignment of " , stringify ! ( A__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const A__bindgen_ty_1 ) ) . f as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( A__bindgen_ty_1 ) , + "::" , stringify ! ( f ) )); } impl Clone for A__bindgen_ty_1 { fn clone(&self) -> Self { *self } @@ -71,16 +90,34 @@ pub struct A__bindgen_ty_2 { } #[test] fn bindgen_test_layout_A__bindgen_ty_2() { - assert_eq!(::std::mem::size_of::<A__bindgen_ty_2>() , 4usize); - assert_eq!(::std::mem::align_of::<A__bindgen_ty_2>() , 4usize); + assert_eq!(::std::mem::size_of::<A__bindgen_ty_2>() , 4usize , concat ! ( + "Size of: " , stringify ! ( A__bindgen_ty_2 ) )); + assert_eq! (::std::mem::align_of::<A__bindgen_ty_2>() , 4usize , concat ! + ( "Alignment of " , stringify ! ( A__bindgen_ty_2 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const A__bindgen_ty_2 ) ) . d as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( A__bindgen_ty_2 ) , + "::" , stringify ! ( d ) )); } impl Clone for A__bindgen_ty_2 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::<A>() , 12usize); - assert_eq!(::std::mem::align_of::<A>() , 4usize); + assert_eq!(::std::mem::size_of::<A>() , 12usize , concat ! ( + "Size of: " , stringify ! ( A ) )); + assert_eq! (::std::mem::align_of::<A>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( A ) )); + assert_eq! (unsafe { & ( * ( 0 as * const A ) ) . c as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( A ) , "::" , stringify + ! ( c ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const A ) ) . named_union as * const _ as usize + } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( A ) , "::" , stringify + ! ( named_union ) )); } impl Clone for A { fn clone(&self) -> Self { *self } @@ -98,16 +135,34 @@ pub struct B_Segment { } #[test] fn bindgen_test_layout_B_Segment() { - assert_eq!(::std::mem::size_of::<B_Segment>() , 8usize); - assert_eq!(::std::mem::align_of::<B_Segment>() , 4usize); + assert_eq!(::std::mem::size_of::<B_Segment>() , 8usize , concat ! ( + "Size of: " , stringify ! ( B_Segment ) )); + assert_eq! (::std::mem::align_of::<B_Segment>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( B_Segment ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const B_Segment ) ) . begin as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( B_Segment ) , "::" , + stringify ! ( begin ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const B_Segment ) ) . end as * const _ as usize + } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( B_Segment ) , "::" , + stringify ! ( end ) )); } impl Clone for B_Segment { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::<B>() , 4usize); - assert_eq!(::std::mem::align_of::<B>() , 4usize); + assert_eq!(::std::mem::size_of::<B>() , 4usize , concat ! ( + "Size of: " , stringify ! ( B ) )); + assert_eq! (::std::mem::align_of::<B>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( B ) )); + assert_eq! (unsafe { & ( * ( 0 as * const B ) ) . d as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( B ) , "::" , stringify + ! ( d ) )); } impl Clone for B { fn clone(&self) -> Self { *self } @@ -144,9 +199,36 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 { #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { assert_eq!(::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_1>() , - 16usize); - assert_eq!(::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_1>() , - 4usize); + 16usize , concat ! ( + "Size of: " , stringify ! ( C__bindgen_ty_1__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_1>() , + 4usize , concat ! ( + "Alignment of " , stringify ! ( C__bindgen_ty_1__bindgen_ty_1 + ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mX1 + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mX1 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mY1 + as * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( + C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mY1 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mX2 + as * const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( + C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mX2 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_1 ) ) . mY2 + as * const _ as usize } , 12usize , concat ! ( + "Alignment of field: " , stringify ! ( + C__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( mY2 ) + )); } impl Clone for C__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } @@ -159,18 +241,40 @@ pub struct C__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { - assert_eq!(::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_2>() , - 8usize); - assert_eq!(::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_2>() , - 4usize); + assert_eq!(::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_2>() , 8usize + , concat ! ( + "Size of: " , stringify ! ( C__bindgen_ty_1__bindgen_ty_2 ) )); + assert_eq! (::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_2>() , + 4usize , concat ! ( + "Alignment of " , stringify ! ( C__bindgen_ty_1__bindgen_ty_2 + ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_2 ) ) . + mStepSyntax as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + C__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( + mStepSyntax ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C__bindgen_ty_1__bindgen_ty_2 ) ) . + mSteps as * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( + C__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( mSteps + ) )); } impl Clone for C__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_C__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<C__bindgen_ty_1>() , 16usize); - assert_eq!(::std::mem::align_of::<C__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<C__bindgen_ty_1>() , 16usize , concat ! ( + "Size of: " , stringify ! ( C__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<C__bindgen_ty_1>() , 4usize , concat ! + ( "Alignment of " , stringify ! ( C__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C__bindgen_ty_1 ) ) . mFunc as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( C__bindgen_ty_1 ) , + "::" , stringify ! ( mFunc ) )); } impl Clone for C__bindgen_ty_1 { fn clone(&self) -> Self { *self } @@ -183,16 +287,34 @@ pub struct C_Segment { } #[test] fn bindgen_test_layout_C_Segment() { - assert_eq!(::std::mem::size_of::<C_Segment>() , 8usize); - assert_eq!(::std::mem::align_of::<C_Segment>() , 4usize); + assert_eq!(::std::mem::size_of::<C_Segment>() , 8usize , concat ! ( + "Size of: " , stringify ! ( C_Segment ) )); + assert_eq! (::std::mem::align_of::<C_Segment>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( C_Segment ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C_Segment ) ) . begin as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( C_Segment ) , "::" , + stringify ! ( begin ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C_Segment ) ) . end as * const _ as usize + } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( C_Segment ) , "::" , + stringify ! ( end ) )); } impl Clone for C_Segment { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::<C>() , 20usize); - assert_eq!(::std::mem::align_of::<C>() , 4usize); + assert_eq!(::std::mem::size_of::<C>() , 20usize , concat ! ( + "Size of: " , stringify ! ( C ) )); + assert_eq! (::std::mem::align_of::<C>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( C ) )); + assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . d as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( d ) )); } impl Clone for C { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/class_with_typedef.rs b/tests/expectations/tests/class_with_typedef.rs index bc19f2bd..d3141fd9 100644 --- a/tests/expectations/tests/class_with_typedef.rs +++ b/tests/expectations/tests/class_with_typedef.rs @@ -18,8 +18,33 @@ pub type C_MyInt = ::std::os::raw::c_int; pub type C_Lookup = *const ::std::os::raw::c_char; #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::<C>() , 72usize); - assert_eq!(::std::mem::align_of::<C>() , 8usize); + assert_eq!(::std::mem::size_of::<C>() , 72usize , concat ! ( + "Size of: " , stringify ! ( C ) )); + assert_eq! (::std::mem::align_of::<C>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( C ) )); + assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . c as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( c ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C ) ) . ptr as * const _ as usize } , + 8usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( ptr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C ) ) . arr as * const _ as usize } , + 16usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( arr ) )); + assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . d as * const _ as usize + } , 56usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( d ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C ) ) . other_ptr as * const _ as usize } + , 64usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( other_ptr ) )); } extern "C" { #[link_name = "_ZN1C6methodEi"] @@ -64,8 +89,15 @@ pub struct D { } #[test] fn bindgen_test_layout_D() { - assert_eq!(::std::mem::size_of::<D>() , 80usize); - assert_eq!(::std::mem::align_of::<D>() , 8usize); + assert_eq!(::std::mem::size_of::<D>() , 80usize , concat ! ( + "Size of: " , stringify ! ( D ) )); + assert_eq! (::std::mem::align_of::<D>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( D ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const D ) ) . ptr as * const _ as usize } , + 72usize , concat ! ( + "Alignment of field: " , stringify ! ( D ) , "::" , stringify + ! ( ptr ) )); } impl Clone for D { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs index f2a97952..1048138e 100644 --- a/tests/expectations/tests/complex.rs +++ b/tests/expectations/tests/complex.rs @@ -17,8 +17,15 @@ pub struct TestDouble { } #[test] fn bindgen_test_layout_TestDouble() { - assert_eq!(::std::mem::size_of::<TestDouble>() , 16usize); - assert_eq!(::std::mem::align_of::<TestDouble>() , 8usize); + assert_eq!(::std::mem::size_of::<TestDouble>() , 16usize , concat ! ( + "Size of: " , stringify ! ( TestDouble ) )); + assert_eq! (::std::mem::align_of::<TestDouble>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( TestDouble ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const TestDouble ) ) . mMember as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( TestDouble ) , "::" , + stringify ! ( mMember ) )); } impl Clone for TestDouble { fn clone(&self) -> Self { *self } @@ -30,8 +37,15 @@ pub struct TestDoublePtr { } #[test] fn bindgen_test_layout_TestDoublePtr() { - assert_eq!(::std::mem::size_of::<TestDoublePtr>() , 8usize); - assert_eq!(::std::mem::align_of::<TestDoublePtr>() , 8usize); + assert_eq!(::std::mem::size_of::<TestDoublePtr>() , 8usize , concat ! ( + "Size of: " , stringify ! ( TestDoublePtr ) )); + assert_eq! (::std::mem::align_of::<TestDoublePtr>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( TestDoublePtr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const TestDoublePtr ) ) . mMember as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( TestDoublePtr ) , "::" + , stringify ! ( mMember ) )); } impl Clone for TestDoublePtr { fn clone(&self) -> Self { *self } @@ -43,8 +57,15 @@ pub struct TestFloat { } #[test] fn bindgen_test_layout_TestFloat() { - assert_eq!(::std::mem::size_of::<TestFloat>() , 8usize); - assert_eq!(::std::mem::align_of::<TestFloat>() , 4usize); + assert_eq!(::std::mem::size_of::<TestFloat>() , 8usize , concat ! ( + "Size of: " , stringify ! ( TestFloat ) )); + assert_eq! (::std::mem::align_of::<TestFloat>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( TestFloat ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const TestFloat ) ) . mMember as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( TestFloat ) , "::" , + stringify ! ( mMember ) )); } impl Clone for TestFloat { fn clone(&self) -> Self { *self } @@ -56,8 +77,15 @@ pub struct TestFloatPtr { } #[test] fn bindgen_test_layout_TestFloatPtr() { - assert_eq!(::std::mem::size_of::<TestFloatPtr>() , 8usize); - assert_eq!(::std::mem::align_of::<TestFloatPtr>() , 8usize); + assert_eq!(::std::mem::size_of::<TestFloatPtr>() , 8usize , concat ! ( + "Size of: " , stringify ! ( TestFloatPtr ) )); + assert_eq! (::std::mem::align_of::<TestFloatPtr>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( TestFloatPtr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const TestFloatPtr ) ) . mMember as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( TestFloatPtr ) , "::" , + stringify ! ( mMember ) )); } impl Clone for TestFloatPtr { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/const_bool.rs b/tests/expectations/tests/const_bool.rs index 8a50a094..2c8ba788 100644 --- a/tests/expectations/tests/const_bool.rs +++ b/tests/expectations/tests/const_bool.rs @@ -13,8 +13,10 @@ pub struct A { pub const A_k: bool = false; #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::<A>() , 1usize); - assert_eq!(::std::mem::align_of::<A>() , 1usize); + assert_eq!(::std::mem::size_of::<A>() , 1usize , concat ! ( + "Size of: " , stringify ! ( A ) )); + assert_eq! (::std::mem::align_of::<A>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( A ) )); } impl Clone for A { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/const_enum_unnamed.rs b/tests/expectations/tests/const_enum_unnamed.rs index 0bd3987a..8a5f0f23 100644 --- a/tests/expectations/tests/const_enum_unnamed.rs +++ b/tests/expectations/tests/const_enum_unnamed.rs @@ -20,8 +20,10 @@ pub const Foo_FOO_BAR: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::FOO_BAR; pub enum Foo__bindgen_ty_1 { FOO_BAR = 10, } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::<Foo>() , 1usize); - assert_eq!(::std::mem::align_of::<Foo>() , 1usize); + assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); } impl Clone for Foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs index a676bb10..ae89a9b7 100644 --- a/tests/expectations/tests/constify-all-enums.rs +++ b/tests/expectations/tests/constify-all-enums.rs @@ -15,8 +15,15 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { - assert_eq!(::std::mem::size_of::<bar>() , 4usize); - assert_eq!(::std::mem::align_of::<bar>() , 4usize); + assert_eq!(::std::mem::size_of::<bar>() , 4usize , concat ! ( + "Size of: " , stringify ! ( bar ) )); + assert_eq! (::std::mem::align_of::<bar>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const bar ) ) . this_should_work as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( bar ) , "::" , + stringify ! ( this_should_work ) )); } impl Clone for bar { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/constructor-tp.rs b/tests/expectations/tests/constructor-tp.rs index 50220489..0f53317b 100644 --- a/tests/expectations/tests/constructor-tp.rs +++ b/tests/expectations/tests/constructor-tp.rs @@ -17,8 +17,10 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 1usize); - assert_eq!(::std::mem::align_of::<Bar>() , 1usize); + assert_eq!(::std::mem::size_of::<Bar>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); } extern "C" { #[link_name = "_ZN3BarC1Ev"] diff --git a/tests/expectations/tests/constructors.rs b/tests/expectations/tests/constructors.rs index 95afb82d..3abb2da7 100644 --- a/tests/expectations/tests/constructors.rs +++ b/tests/expectations/tests/constructors.rs @@ -11,8 +11,10 @@ pub struct TestOverload { } #[test] fn bindgen_test_layout_TestOverload() { - assert_eq!(::std::mem::size_of::<TestOverload>() , 1usize); - assert_eq!(::std::mem::align_of::<TestOverload>() , 1usize); + assert_eq!(::std::mem::size_of::<TestOverload>() , 1usize , concat ! ( + "Size of: " , stringify ! ( TestOverload ) )); + assert_eq! (::std::mem::align_of::<TestOverload>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( TestOverload ) )); } extern "C" { #[link_name = "_ZN12TestOverloadC1Ei"] @@ -47,8 +49,10 @@ pub struct TestPublicNoArgs { } #[test] fn bindgen_test_layout_TestPublicNoArgs() { - assert_eq!(::std::mem::size_of::<TestPublicNoArgs>() , 1usize); - assert_eq!(::std::mem::align_of::<TestPublicNoArgs>() , 1usize); + assert_eq!(::std::mem::size_of::<TestPublicNoArgs>() , 1usize , concat ! ( + "Size of: " , stringify ! ( TestPublicNoArgs ) )); + assert_eq! (::std::mem::align_of::<TestPublicNoArgs>() , 1usize , concat ! + ( "Alignment of " , stringify ! ( TestPublicNoArgs ) )); } extern "C" { #[link_name = "_ZN16TestPublicNoArgsC1Ev"] diff --git a/tests/expectations/tests/convert-floats.rs b/tests/expectations/tests/convert-floats.rs index 5cd38c13..5971db06 100644 --- a/tests/expectations/tests/convert-floats.rs +++ b/tests/expectations/tests/convert-floats.rs @@ -22,8 +22,40 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 48usize); - assert_eq!(::std::mem::align_of::<foo>() , 8usize); + assert_eq!(::std::mem::size_of::<foo>() , 48usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . baz as * const _ as usize } , + 4usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( baz ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bazz as * const _ as usize } , + 8usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bazz ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bazzz as * const _ as usize } , + 16usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bazzz ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . complexFloat as * const _ as + usize } , 24usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( complexFloat ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . complexDouble as * const _ as + usize } , 32usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( complexDouble ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/crtp.rs b/tests/expectations/tests/crtp.rs index cc488fd6..8fe0a5ae 100644 --- a/tests/expectations/tests/crtp.rs +++ b/tests/expectations/tests/crtp.rs @@ -17,8 +17,10 @@ pub struct Derived { } #[test] fn bindgen_test_layout_Derived() { - assert_eq!(::std::mem::size_of::<Derived>() , 1usize); - assert_eq!(::std::mem::align_of::<Derived>() , 1usize); + assert_eq!(::std::mem::size_of::<Derived>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Derived ) )); + assert_eq! (::std::mem::align_of::<Derived>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Derived ) )); } impl Clone for Derived { fn clone(&self) -> Self { *self } @@ -36,20 +38,31 @@ pub struct DerivedFromBaseWithDestructor { } #[test] fn bindgen_test_layout_DerivedFromBaseWithDestructor() { - assert_eq!(::std::mem::size_of::<DerivedFromBaseWithDestructor>() , - 1usize); - assert_eq!(::std::mem::align_of::<DerivedFromBaseWithDestructor>() , - 1usize); + assert_eq!(::std::mem::size_of::<DerivedFromBaseWithDestructor>() , 1usize + , concat ! ( + "Size of: " , stringify ! ( DerivedFromBaseWithDestructor ) )); + assert_eq! (::std::mem::align_of::<DerivedFromBaseWithDestructor>() , + 1usize , concat ! ( + "Alignment of " , stringify ! ( DerivedFromBaseWithDestructor + ) )); } #[test] fn __bindgen_test_layout_template_1() { - assert_eq!(::std::mem::size_of::<Base<Derived>>() , 1usize); - assert_eq!(::std::mem::align_of::<Base<Derived>>() , 1usize); + assert_eq!(::std::mem::size_of::<Base<Derived>>() , 1usize , concat ! ( + "Size of template specialization: " , stringify ! ( + Base<Derived> ) )); + assert_eq!(::std::mem::align_of::<Base<Derived>>() , 1usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + Base<Derived> ) )); } #[test] fn __bindgen_test_layout_template_2() { assert_eq!(::std::mem::size_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>() - , 1usize); + , 1usize , concat ! ( + "Size of template specialization: " , stringify ! ( + BaseWithDestructor<DerivedFromBaseWithDestructor> ) )); assert_eq!(::std::mem::align_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>() - , 1usize); + , 1usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + BaseWithDestructor<DerivedFromBaseWithDestructor> ) )); } diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/tests/expectations/tests/duplicated-namespaces-definitions.rs index da06a2a9..1b785fd7 100644 --- a/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -18,8 +18,20 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 8usize); - assert_eq!(::std::mem::align_of::<Bar>() , 4usize); + assert_eq!(::std::mem::size_of::<Bar>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Bar ) ) . foo as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Bar ) , "::" , + stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Bar ) ) . baz as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( Bar ) , "::" , + stringify ! ( baz ) )); } impl Clone for Bar { fn clone(&self) -> Self { *self } @@ -35,8 +47,15 @@ pub mod root { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::<Foo>() , 8usize); - assert_eq!(::std::mem::align_of::<Foo>() , 8usize); + assert_eq!(::std::mem::size_of::<Foo>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::<Foo>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Foo ) ) . ptr as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Foo ) , "::" , + stringify ! ( ptr ) )); } impl Clone for Foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index a55c344e..e372d98b 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -20,8 +20,14 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::<C>() , 16usize); - assert_eq!(::std::mem::align_of::<C>() , 8usize); + assert_eq!(::std::mem::size_of::<C>() , 16usize , concat ! ( + "Size of: " , stringify ! ( C ) )); + assert_eq! (::std::mem::align_of::<C>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( C ) )); + assert_eq! (unsafe { & ( * ( 0 as * const C ) ) . i as * const _ as usize + } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( i ) )); } impl Clone for C { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index 31013d3a..ffe5b7b6 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -19,8 +19,15 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 8usize); - assert_eq!(::std::mem::align_of::<Bar>() , 8usize); + assert_eq!(::std::mem::size_of::<Bar>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Bar ) ) . m_member as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Bar ) , "::" , + stringify ! ( m_member ) )); } impl Clone for Bar { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs index 119ea2b5..0637fea3 100644 --- a/tests/expectations/tests/forward_declared_complex_types.rs +++ b/tests/expectations/tests/forward_declared_complex_types.rs @@ -11,8 +11,10 @@ pub struct Foo_empty { } #[test] fn bindgen_test_layout_Foo_empty() { - assert_eq!(::std::mem::size_of::<Foo_empty>() , 1usize); - assert_eq!(::std::mem::align_of::<Foo_empty>() , 1usize); + assert_eq!(::std::mem::size_of::<Foo_empty>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo_empty ) )); + assert_eq! (::std::mem::align_of::<Foo_empty>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo_empty ) )); } impl Clone for Foo_empty { fn clone(&self) -> Self { *self } @@ -27,8 +29,15 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 8usize); - assert_eq!(::std::mem::align_of::<Bar>() , 8usize); + assert_eq!(::std::mem::size_of::<Bar>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Bar ) ) . f as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Bar ) , "::" , + stringify ! ( f ) )); } impl Clone for Bar { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/forward_declared_struct.rs b/tests/expectations/tests/forward_declared_struct.rs index 5c2764e1..51c61cdf 100644 --- a/tests/expectations/tests/forward_declared_struct.rs +++ b/tests/expectations/tests/forward_declared_struct.rs @@ -11,8 +11,14 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { - assert_eq!(::std::mem::size_of::<a>() , 4usize); - assert_eq!(::std::mem::align_of::<a>() , 4usize); + assert_eq!(::std::mem::size_of::<a>() , 4usize , concat ! ( + "Size of: " , stringify ! ( a ) )); + assert_eq! (::std::mem::align_of::<a>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( a ) )); + assert_eq! (unsafe { & ( * ( 0 as * const a ) ) . b as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( a ) , "::" , stringify + ! ( b ) )); } impl Clone for a { fn clone(&self) -> Self { *self } @@ -24,8 +30,14 @@ pub struct c { } #[test] fn bindgen_test_layout_c() { - assert_eq!(::std::mem::size_of::<c>() , 4usize); - assert_eq!(::std::mem::align_of::<c>() , 4usize); + assert_eq!(::std::mem::size_of::<c>() , 4usize , concat ! ( + "Size of: " , stringify ! ( c ) )); + assert_eq! (::std::mem::align_of::<c>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( c ) )); + assert_eq! (unsafe { & ( * ( 0 as * const c ) ) . d as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( c ) , "::" , stringify + ! ( d ) )); } impl Clone for c { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index dcae771b..eba6c7e2 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -17,8 +17,15 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::<Foo>() , 8usize); - assert_eq!(::std::mem::align_of::<Foo>() , 8usize); + assert_eq!(::std::mem::size_of::<Foo>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::<Foo>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Foo ) ) . bar as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Foo ) , "::" , + stringify ! ( bar ) )); } impl Clone for Foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/inherit_typedef.rs b/tests/expectations/tests/inherit_typedef.rs index ca9041e2..ff6a62d3 100644 --- a/tests/expectations/tests/inherit_typedef.rs +++ b/tests/expectations/tests/inherit_typedef.rs @@ -11,8 +11,10 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::<Foo>() , 1usize); - assert_eq!(::std::mem::align_of::<Foo>() , 1usize); + assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); } impl Clone for Foo { fn clone(&self) -> Self { *self } @@ -25,8 +27,10 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 1usize); - assert_eq!(::std::mem::align_of::<Bar>() , 1usize); + assert_eq!(::std::mem::size_of::<Bar>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); } impl Clone for Bar { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/inline_namespace.rs b/tests/expectations/tests/inline_namespace.rs index 5f6776b7..6b2c4f80 100644 --- a/tests/expectations/tests/inline_namespace.rs +++ b/tests/expectations/tests/inline_namespace.rs @@ -19,8 +19,15 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 4usize); - assert_eq!(::std::mem::align_of::<Bar>() , 4usize); + assert_eq!(::std::mem::size_of::<Bar>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Bar ) ) . baz as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Bar ) , "::" , + stringify ! ( baz ) )); } impl Clone for Bar { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/inline_namespace_conservative.rs b/tests/expectations/tests/inline_namespace_conservative.rs index d759a882..5b74a5f6 100644 --- a/tests/expectations/tests/inline_namespace_conservative.rs +++ b/tests/expectations/tests/inline_namespace_conservative.rs @@ -24,8 +24,15 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 4usize); - assert_eq!(::std::mem::align_of::<Bar>() , 4usize); + assert_eq!(::std::mem::size_of::<Bar>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Bar ) ) . baz as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Bar ) , "::" , + stringify ! ( baz ) )); } impl Clone for Bar { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/inner_const.rs b/tests/expectations/tests/inner_const.rs index 666b8ce2..3422f168 100644 --- a/tests/expectations/tests/inner_const.rs +++ b/tests/expectations/tests/inner_const.rs @@ -19,8 +19,15 @@ extern "C" { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::<Foo>() , 4usize); - assert_eq!(::std::mem::align_of::<Foo>() , 4usize); + assert_eq!(::std::mem::size_of::<Foo>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::<Foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Foo ) ) . bar as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Foo ) , "::" , + stringify ! ( bar ) )); } impl Clone for Foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index b965b92d..4345e422 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -17,8 +17,15 @@ pub struct InstantiateIt { } #[test] fn bindgen_test_layout_InstantiateIt() { - assert_eq!(::std::mem::size_of::<InstantiateIt>() , 16usize); - assert_eq!(::std::mem::align_of::<InstantiateIt>() , 8usize); + assert_eq!(::std::mem::size_of::<InstantiateIt>() , 16usize , concat ! ( + "Size of: " , stringify ! ( InstantiateIt ) )); + assert_eq! (::std::mem::align_of::<InstantiateIt>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( InstantiateIt ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const InstantiateIt ) ) . m_list as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( InstantiateIt ) , "::" + , stringify ! ( m_list ) )); } impl Clone for InstantiateIt { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index c6d9209e..8fcfd33d 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -14,8 +14,15 @@ pub mod root { } #[test] fn bindgen_test_layout_d() { - assert_eq!(::std::mem::size_of::<d>() , 24usize); - assert_eq!(::std::mem::align_of::<d>() , 8usize); + assert_eq!(::std::mem::size_of::<d>() , 24usize , concat ! ( + "Size of: " , stringify ! ( d ) )); + assert_eq! (::std::mem::align_of::<d>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( d ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const d ) ) . m as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( d ) , "::" , + stringify ! ( m ) )); } impl Clone for d { fn clone(&self) -> Self { *self } @@ -29,8 +36,25 @@ pub mod root { } #[test] fn bindgen_test_layout_i() { - assert_eq!(::std::mem::size_of::<i>() , 24usize); - assert_eq!(::std::mem::align_of::<i>() , 8usize); + assert_eq!(::std::mem::size_of::<i>() , 24usize , concat ! ( + "Size of: " , stringify ! ( i ) )); + assert_eq! (::std::mem::align_of::<i>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( i ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const i ) ) . j as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( i ) , "::" , + stringify ! ( j ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const i ) ) . k as * const _ as usize } , + 8usize , concat ! ( + "Alignment of field: " , stringify ! ( i ) , "::" , + stringify ! ( k ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const i ) ) . l as * const _ as usize } , + 16usize , concat ! ( + "Alignment of field: " , stringify ! ( i ) , "::" , + stringify ! ( l ) )); } impl Clone for i { fn clone(&self) -> Self { *self } @@ -57,7 +81,14 @@ pub mod root { } #[test] fn bindgen_test_layout_F() { - assert_eq!(::std::mem::size_of::<F>() , 264usize); - assert_eq!(::std::mem::align_of::<F>() , 8usize); + assert_eq!(::std::mem::size_of::<F>() , 264usize , concat ! ( + "Size of: " , stringify ! ( F ) )); + assert_eq! (::std::mem::align_of::<F>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( F ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const F ) ) . w as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( F ) , "::" , + stringify ! ( w ) )); } } diff --git a/tests/expectations/tests/issue-410.rs b/tests/expectations/tests/issue-410.rs index 0c91e2b7..a8e0d8d4 100644 --- a/tests/expectations/tests/issue-410.rs +++ b/tests/expectations/tests/issue-410.rs @@ -17,8 +17,10 @@ pub mod root { } #[test] fn bindgen_test_layout_Value() { - assert_eq!(::std::mem::size_of::<Value>() , 1usize); - assert_eq!(::std::mem::align_of::<Value>() , 1usize); + assert_eq!(::std::mem::size_of::<Value>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Value ) )); + assert_eq! (::std::mem::align_of::<Value>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Value ) )); } extern "C" { #[link_name = "_ZN2JS5Value1aE10JSWhyMagic"] diff --git a/tests/expectations/tests/issue-447.rs b/tests/expectations/tests/issue-447.rs index b49caa54..0582f412 100644 --- a/tests/expectations/tests/issue-447.rs +++ b/tests/expectations/tests/issue-447.rs @@ -21,9 +21,13 @@ pub mod root { #[test] fn bindgen_test_layout_GuardObjectNotifier() { assert_eq!(::std::mem::size_of::<GuardObjectNotifier>() , - 1usize); - assert_eq!(::std::mem::align_of::<GuardObjectNotifier>() , - 1usize); + 1usize , concat ! ( + "Size of: " , stringify ! ( GuardObjectNotifier ) + )); + assert_eq! (::std::mem::align_of::<GuardObjectNotifier>() , + 1usize , concat ! ( + "Alignment of " , stringify ! ( + GuardObjectNotifier ) )); } impl Clone for GuardObjectNotifier { fn clone(&self) -> Self { *self } @@ -37,8 +41,12 @@ pub mod root { } #[test] fn bindgen_test_layout_JSAutoCompartment() { - assert_eq!(::std::mem::size_of::<JSAutoCompartment>() , 1usize); - assert_eq!(::std::mem::align_of::<JSAutoCompartment>() , 1usize); + assert_eq!(::std::mem::size_of::<JSAutoCompartment>() , 1usize , + concat ! ( "Size of: " , stringify ! ( JSAutoCompartment ) + )); + assert_eq! (::std::mem::align_of::<JSAutoCompartment>() , 1usize , + concat ! ( + "Alignment of " , stringify ! ( JSAutoCompartment ) )); } extern "C" { #[link_name = diff --git a/tests/expectations/tests/issue_311.rs b/tests/expectations/tests/issue_311.rs index f01a9d93..debc893d 100644 --- a/tests/expectations/tests/issue_311.rs +++ b/tests/expectations/tests/issue_311.rs @@ -20,17 +20,23 @@ pub mod root { #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_1>() , - 1usize); - assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_1>() , - 1usize); + 1usize , concat ! ( + "Size of: " , stringify ! ( jsval_layout__bindgen_ty_1 ) + )); + assert_eq! (::std::mem::align_of::<jsval_layout__bindgen_ty_1>() , + 1usize , concat ! ( + "Alignment of " , stringify ! ( jsval_layout__bindgen_ty_1 + ) )); } impl Clone for jsval_layout__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_jsval_layout() { - assert_eq!(::std::mem::size_of::<jsval_layout>() , 1usize); - assert_eq!(::std::mem::align_of::<jsval_layout>() , 1usize); + assert_eq!(::std::mem::size_of::<jsval_layout>() , 1usize , concat ! ( + "Size of: " , stringify ! ( jsval_layout ) )); + assert_eq! (::std::mem::align_of::<jsval_layout>() , 1usize , concat ! + ( "Alignment of " , stringify ! ( jsval_layout ) )); } impl Clone for jsval_layout { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 530fdb22..ac092587 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -114,8 +114,13 @@ pub struct jsval_layout__bindgen_ty_1 { } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_1>() , 8usize); - assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_1>() , 8usize); + assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_1>() , 8usize , + concat ! ( + "Size of: " , stringify ! ( jsval_layout__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<jsval_layout__bindgen_ty_1>() , 8usize + , concat ! ( + "Alignment of " , stringify ! ( jsval_layout__bindgen_ty_1 ) + )); } impl Clone for jsval_layout__bindgen_ty_1 { fn clone(&self) -> Self { *self } @@ -167,21 +172,99 @@ pub struct jsval_layout__bindgen_ty_2__bindgen_ty_1 { #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_2__bindgen_ty_1>() - , 4usize); - assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_2__bindgen_ty_1>() - , 4usize); + , 4usize , concat ! ( + "Size of: " , stringify ! ( + jsval_layout__bindgen_ty_2__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<jsval_layout__bindgen_ty_2__bindgen_ty_1>() + , 4usize , concat ! ( + "Alignment of " , stringify ! ( + jsval_layout__bindgen_ty_2__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( + * ( 0 as * const jsval_layout__bindgen_ty_2__bindgen_ty_1 ) ) + . i32 as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + jsval_layout__bindgen_ty_2__bindgen_ty_1 ) , "::" , stringify + ! ( i32 ) )); + assert_eq! (unsafe { + & ( + * ( 0 as * const jsval_layout__bindgen_ty_2__bindgen_ty_1 ) ) + . u32 as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + jsval_layout__bindgen_ty_2__bindgen_ty_1 ) , "::" , stringify + ! ( u32 ) )); + assert_eq! (unsafe { + & ( + * ( 0 as * const jsval_layout__bindgen_ty_2__bindgen_ty_1 ) ) + . why as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + jsval_layout__bindgen_ty_2__bindgen_ty_1 ) , "::" , stringify + ! ( why ) )); } impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { - assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_2>() , 4usize); - assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_2>() , 4usize); + assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_2>() , 4usize , + concat ! ( + "Size of: " , stringify ! ( jsval_layout__bindgen_ty_2 ) )); + assert_eq! (::std::mem::align_of::<jsval_layout__bindgen_ty_2>() , 4usize + , concat ! ( + "Alignment of " , stringify ! ( jsval_layout__bindgen_ty_2 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const jsval_layout__bindgen_ty_2 ) ) . payload + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + jsval_layout__bindgen_ty_2 ) , "::" , stringify ! ( payload ) + )); } impl Clone for jsval_layout__bindgen_ty_2 { fn clone(&self) -> Self { *self } } +#[test] +fn bindgen_test_layout_jsval_layout() { + assert_eq!(::std::mem::size_of::<jsval_layout>() , 8usize , concat ! ( + "Size of: " , stringify ! ( jsval_layout ) )); + assert_eq! (::std::mem::align_of::<jsval_layout>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( jsval_layout ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const jsval_layout ) ) . asBits as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( jsval_layout ) , "::" , + stringify ! ( asBits ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const jsval_layout ) ) . debugView as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( jsval_layout ) , "::" , + stringify ! ( debugView ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const jsval_layout ) ) . s as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( jsval_layout ) , "::" , + stringify ! ( s ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const jsval_layout ) ) . asDouble as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( jsval_layout ) , "::" , + stringify ! ( asDouble ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const jsval_layout ) ) . asPtr as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( jsval_layout ) , "::" , + stringify ! ( asPtr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const jsval_layout ) ) . asWord as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( jsval_layout ) , "::" , + stringify ! ( asWord ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const jsval_layout ) ) . asUIntPtr as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( jsval_layout ) , "::" , + stringify ! ( asUIntPtr ) )); +} impl Clone for jsval_layout { fn clone(&self) -> Self { *self } } @@ -192,8 +275,15 @@ pub struct Value { } #[test] fn bindgen_test_layout_Value() { - assert_eq!(::std::mem::size_of::<Value>() , 8usize); - assert_eq!(::std::mem::align_of::<Value>() , 8usize); + assert_eq!(::std::mem::size_of::<Value>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Value ) )); + assert_eq! (::std::mem::align_of::<Value>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( Value ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Value ) ) . data as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Value ) , "::" , + stringify ! ( data ) )); } impl Clone for Value { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/layout.rs b/tests/expectations/tests/layout.rs new file mode 100644 index 00000000..5fae570c --- /dev/null +++ b/tests/expectations/tests/layout.rs @@ -0,0 +1,54 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>); +impl <T> __IncompleteArrayField<T> { + #[inline] + pub fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ptr(&self) -> *const T { ::std::mem::transmute(self) } + #[inline] + pub unsafe fn as_mut_ptr(&mut self) -> *mut T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl <T> ::std::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +impl <T> ::std::clone::Clone for __IncompleteArrayField<T> { + #[inline] + fn clone(&self) -> Self { Self::new() } +} +impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { } +#[repr(C, packed)] +#[derive(Debug, Copy)] +pub struct header { + pub proto: ::std::os::raw::c_char, + pub size: ::std::os::raw::c_uint, + pub data: __IncompleteArrayField<::std::os::raw::c_uchar>, + pub __bindgen_padding_0: [u8; 11usize], +} +#[test] +fn bindgen_test_layout_header() { + assert_eq!(::std::mem::size_of::<header>() , 16usize , concat ! ( + "Size of: " , stringify ! ( header ) )); +} +impl Clone for header { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs new file mode 100644 index 00000000..0479521c --- /dev/null +++ b/tests/expectations/tests/layout_align.rs @@ -0,0 +1,124 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>); +impl <T> __IncompleteArrayField<T> { + #[inline] + pub fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ptr(&self) -> *const T { ::std::mem::transmute(self) } + #[inline] + pub unsafe fn as_mut_ptr(&mut self) -> *mut T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl <T> ::std::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +impl <T> ::std::clone::Clone for __IncompleteArrayField<T> { + #[inline] + fn clone(&self) -> Self { Self::new() } +} +impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { } +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_kni_fifo { + /**< Next position to be written*/ + pub write: ::std::os::raw::c_uint, + /**< Next position to be read */ + pub read: ::std::os::raw::c_uint, + /**< Circular buffer length */ + pub len: ::std::os::raw::c_uint, + /**< Pointer size - for 32/64 bit OS */ + pub elem_size: ::std::os::raw::c_uint, + /**< The buffer contains mbuf pointers */ + pub buffer: __IncompleteArrayField<*mut ::std::os::raw::c_void>, + pub __bindgen_align: [u64; 0usize], +} +#[test] +fn bindgen_test_layout_rte_kni_fifo() { + assert_eq!(::std::mem::size_of::<rte_kni_fifo>() , 16usize , concat ! ( + "Size of: " , stringify ! ( rte_kni_fifo ) )); + assert_eq! (::std::mem::align_of::<rte_kni_fifo>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( rte_kni_fifo ) )); +} +impl Clone for rte_kni_fifo { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_link { + /**< ETH_SPEED_NUM_ */ + pub link_speed: u32, + pub _bitfield_1: u8, + pub __bindgen_align: [u64; 0usize], +} +#[test] +fn bindgen_test_layout_rte_eth_link() { + assert_eq!(::std::mem::size_of::<rte_eth_link>() , 8usize , concat ! ( + "Size of: " , stringify ! ( rte_eth_link ) )); + assert_eq! (::std::mem::align_of::<rte_eth_link>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( rte_eth_link ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_link ) ) . link_speed as * const + _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_link ) , "::" , + stringify ! ( link_speed ) )); +} +impl Clone for rte_eth_link { + fn clone(&self) -> Self { *self } +} +impl rte_eth_link { + #[inline] + pub fn link_duplex(&self) -> u16 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (1usize as u8)) >> + 0u32) as u16) + } + } + #[inline] + pub fn set_link_duplex(&mut self, val: u16) { + self._bitfield_1 &= !(1usize as u8); + self._bitfield_1 |= ((val as u16 as u8) << 0u32) & (1usize as u8); + } + #[inline] + pub fn link_autoneg(&self) -> u16 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (2usize as u8)) >> + 1u32) as u16) + } + } + #[inline] + pub fn set_link_autoneg(&mut self, val: u16) { + self._bitfield_1 &= !(2usize as u8); + self._bitfield_1 |= ((val as u16 as u8) << 1u32) & (2usize as u8); + } + #[inline] + pub fn link_status(&self) -> u16 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (4usize as u8)) >> + 2u32) as u16) + } + } + #[inline] + pub fn set_link_status(&mut self, val: u16) { + self._bitfield_1 &= !(4usize as u8); + self._bitfield_1 |= ((val as u16 as u8) << 2u32) & (4usize as u8); + } +} diff --git a/tests/expectations/tests/layout_arp.rs b/tests/expectations/tests/layout_arp.rs new file mode 100644 index 00000000..c868f627 --- /dev/null +++ b/tests/expectations/tests/layout_arp.rs @@ -0,0 +1,144 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +pub const ETHER_ADDR_LEN: ::std::os::raw::c_uint = 6; +pub const ARP_HRD_ETHER: ::std::os::raw::c_uint = 1; +pub const ARP_OP_REQUEST: ::std::os::raw::c_uint = 1; +pub const ARP_OP_REPLY: ::std::os::raw::c_uint = 2; +pub const ARP_OP_REVREQUEST: ::std::os::raw::c_uint = 3; +pub const ARP_OP_REVREPLY: ::std::os::raw::c_uint = 4; +pub const ARP_OP_INVREQUEST: ::std::os::raw::c_uint = 8; +pub const ARP_OP_INVREPLY: ::std::os::raw::c_uint = 9; +/** + * Ethernet address: + * A universally administered address is uniquely assigned to a device by its + * manufacturer. The first three octets (in transmission order) contain the + * Organizationally Unique Identifier (OUI). The following three (MAC-48 and + * EUI-48) octets are assigned by that organization with the only constraint + * of uniqueness. + * A locally administered address is assigned to a device by a network + * administrator and does not contain OUIs. + * See http://standards.ieee.org/regauth/groupmac/tutorial.html + */ +#[repr(C, packed)] +#[derive(Debug, Copy)] +pub struct ether_addr { + /**< Addr bytes in tx order */ + pub addr_bytes: [u8; 6usize], +} +#[test] +fn bindgen_test_layout_ether_addr() { + assert_eq!(::std::mem::size_of::<ether_addr>() , 6usize , concat ! ( + "Size of: " , stringify ! ( ether_addr ) )); + assert_eq! (::std::mem::align_of::<ether_addr>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( ether_addr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ether_addr ) ) . addr_bytes as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( ether_addr ) , "::" , + stringify ! ( addr_bytes ) )); +} +impl Clone for ether_addr { + fn clone(&self) -> Self { *self } +} +/** + * ARP header IPv4 payload. + */ +#[repr(C, packed)] +#[derive(Debug, Copy)] +pub struct arp_ipv4 { + /**< sender hardware address */ + pub arp_sha: ether_addr, + /**< sender IP address */ + pub arp_sip: u32, + /**< target hardware address */ + pub arp_tha: ether_addr, + /**< target IP address */ + pub arp_tip: u32, +} +#[test] +fn bindgen_test_layout_arp_ipv4() { + assert_eq!(::std::mem::size_of::<arp_ipv4>() , 20usize , concat ! ( + "Size of: " , stringify ! ( arp_ipv4 ) )); + assert_eq! (::std::mem::align_of::<arp_ipv4>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( arp_ipv4 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const arp_ipv4 ) ) . arp_sha as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( arp_ipv4 ) , "::" , + stringify ! ( arp_sha ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const arp_ipv4 ) ) . arp_sip as * const _ as + usize } , 6usize , concat ! ( + "Alignment of field: " , stringify ! ( arp_ipv4 ) , "::" , + stringify ! ( arp_sip ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const arp_ipv4 ) ) . arp_tha as * const _ as + usize } , 10usize , concat ! ( + "Alignment of field: " , stringify ! ( arp_ipv4 ) , "::" , + stringify ! ( arp_tha ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const arp_ipv4 ) ) . arp_tip as * const _ as + usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( arp_ipv4 ) , "::" , + stringify ! ( arp_tip ) )); +} +impl Clone for arp_ipv4 { + fn clone(&self) -> Self { *self } +} +/** + * ARP header. + */ +#[repr(C, packed)] +#[derive(Debug, Copy)] +pub struct arp_hdr { + pub arp_hrd: u16, + pub arp_pro: u16, + pub arp_hln: u8, + pub arp_pln: u8, + pub arp_op: u16, + pub arp_data: arp_ipv4, +} +#[test] +fn bindgen_test_layout_arp_hdr() { + assert_eq!(::std::mem::size_of::<arp_hdr>() , 28usize , concat ! ( + "Size of: " , stringify ! ( arp_hdr ) )); + assert_eq! (::std::mem::align_of::<arp_hdr>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( arp_hdr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const arp_hdr ) ) . arp_hrd as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( arp_hdr ) , "::" , + stringify ! ( arp_hrd ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const arp_hdr ) ) . arp_pro as * const _ as + usize } , 2usize , concat ! ( + "Alignment of field: " , stringify ! ( arp_hdr ) , "::" , + stringify ! ( arp_pro ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const arp_hdr ) ) . arp_hln as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( arp_hdr ) , "::" , + stringify ! ( arp_hln ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const arp_hdr ) ) . arp_pln as * const _ as + usize } , 5usize , concat ! ( + "Alignment of field: " , stringify ! ( arp_hdr ) , "::" , + stringify ! ( arp_pln ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const arp_hdr ) ) . arp_op as * const _ as + usize } , 6usize , concat ! ( + "Alignment of field: " , stringify ! ( arp_hdr ) , "::" , + stringify ! ( arp_op ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const arp_hdr ) ) . arp_data as * const _ as + usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( arp_hdr ) , "::" , + stringify ! ( arp_data ) )); +} +impl Clone for arp_hdr { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs new file mode 100644 index 00000000..bc690fb6 --- /dev/null +++ b/tests/expectations/tests/layout_array.rs @@ -0,0 +1,248 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +pub const RTE_CACHE_LINE_SIZE: ::std::os::raw::c_uint = 64; +pub const RTE_MEMPOOL_OPS_NAMESIZE: ::std::os::raw::c_uint = 32; +pub const RTE_MEMPOOL_MAX_OPS_IDX: ::std::os::raw::c_uint = 16; +pub const RTE_HEAP_NUM_FREELISTS: ::std::os::raw::c_uint = 13; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct rte_mempool([u8; 0]); +/** + * Prototype for implementation specific data provisioning function. + * + * The function should provide the implementation specific memory for + * for use by the other mempool ops functions in a given mempool ops struct. + * E.g. the default ops provides an instance of the rte_ring for this purpose. + * it will most likely point to a different type of data structure, and + * will be transparent to the application programmer. + * This function should set mp->pool_data. + */ +pub type rte_mempool_alloc_t = + ::std::option::Option<unsafe extern "C" fn(mp: *mut rte_mempool) + -> ::std::os::raw::c_int>; +/** + * Free the opaque private data pointed to by mp->pool_data pointer. + */ +pub type rte_mempool_free_t = + ::std::option::Option<unsafe extern "C" fn(mp: *mut rte_mempool)>; +/** + * Enqueue an object into the external pool. + */ +pub type rte_mempool_enqueue_t = + ::std::option::Option<unsafe extern "C" fn(mp: *mut rte_mempool, + obj_table: + *const *const ::std::os::raw::c_void, + n: ::std::os::raw::c_uint) + -> ::std::os::raw::c_int>; +/** + * Dequeue an object from the external pool. + */ +pub type rte_mempool_dequeue_t = + ::std::option::Option<unsafe extern "C" fn(mp: *mut rte_mempool, + obj_table: + *mut *mut ::std::os::raw::c_void, + n: ::std::os::raw::c_uint) + -> ::std::os::raw::c_int>; +/** + * Return the number of available objects in the external pool. + */ +pub type rte_mempool_get_count = + ::std::option::Option<unsafe extern "C" fn(mp: *const rte_mempool) + -> ::std::os::raw::c_uint>; +/** Structure defining mempool operations structure */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mempool_ops { + /**< Name of mempool ops struct. */ + pub name: [::std::os::raw::c_char; 32usize], + /**< Allocate private data. */ + pub alloc: rte_mempool_alloc_t, + /**< Free the external pool. */ + pub free: rte_mempool_free_t, + /**< Enqueue an object. */ + pub enqueue: rte_mempool_enqueue_t, + /**< Dequeue an object. */ + pub dequeue: rte_mempool_dequeue_t, + /**< Get qty of available objs. */ + pub get_count: rte_mempool_get_count, + pub __bindgen_padding_0: [u64; 7usize], +} +#[test] +fn bindgen_test_layout_rte_mempool_ops() { + assert_eq!(::std::mem::size_of::<rte_mempool_ops>() , 128usize , concat ! + ( "Size of: " , stringify ! ( rte_mempool_ops ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mempool_ops ) ) . name as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mempool_ops ) , + "::" , stringify ! ( name ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mempool_ops ) ) . alloc as * const _ + as usize } , 32usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mempool_ops ) , + "::" , stringify ! ( alloc ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mempool_ops ) ) . free as * const _ + as usize } , 40usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mempool_ops ) , + "::" , stringify ! ( free ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mempool_ops ) ) . enqueue as * const + _ as usize } , 48usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mempool_ops ) , + "::" , stringify ! ( enqueue ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mempool_ops ) ) . dequeue as * const + _ as usize } , 56usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mempool_ops ) , + "::" , stringify ! ( dequeue ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mempool_ops ) ) . get_count as * + const _ as usize } , 64usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mempool_ops ) , + "::" , stringify ! ( get_count ) )); +} +impl Clone for rte_mempool_ops { + fn clone(&self) -> Self { *self } +} +/** + * The rte_spinlock_t type. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct _bindgen_ty_1 { + /**< lock status 0 = unlocked, 1 = locked */ + pub locked: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<_bindgen_ty_1>() , 4usize , concat ! ( + "Size of: " , stringify ! ( _bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<_bindgen_ty_1>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( _bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const _bindgen_ty_1 ) ) . locked as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::" + , stringify ! ( locked ) )); +} +impl Clone for _bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +pub type rte_spinlock_t = _bindgen_ty_1; +/** + * Structure storing the table of registered ops structs, each of which contain + * the function pointers for the mempool ops functions. + * Each process has its own storage for this ops struct array so that + * the mempools can be shared across primary and secondary processes. + * The indices used to access the array are valid across processes, whereas + * any function pointers stored directly in the mempool struct would not be. + * This results in us simply having "ops_index" in the mempool struct. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mempool_ops_table { + /**< Spinlock for add/delete. */ + pub sl: rte_spinlock_t, + /**< Number of used ops structs in the table. */ + pub num_ops: u32, + pub __bindgen_padding_0: [u64; 7usize], + /** + * Storage for all possible ops structs. + */ + pub ops: [rte_mempool_ops; 16usize], +} +#[test] +fn bindgen_test_layout_rte_mempool_ops_table() { + assert_eq!(::std::mem::size_of::<rte_mempool_ops_table>() , 2112usize , + concat ! ( "Size of: " , stringify ! ( rte_mempool_ops_table ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mempool_ops_table ) ) . sl as * const + _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mempool_ops_table ) + , "::" , stringify ! ( sl ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mempool_ops_table ) ) . num_ops as * + const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mempool_ops_table ) + , "::" , stringify ! ( num_ops ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mempool_ops_table ) ) . ops as * + const _ as usize } , 64usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mempool_ops_table ) + , "::" , stringify ! ( ops ) )); +} +impl Clone for rte_mempool_ops_table { + fn clone(&self) -> Self { *self } +} +/** + * Structure to hold malloc heap + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct malloc_heap { + pub lock: rte_spinlock_t, + pub free_head: [malloc_heap__bindgen_ty_1; 13usize], + pub alloc_count: ::std::os::raw::c_uint, + pub total_size: usize, +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct malloc_heap__bindgen_ty_1 { + pub lh_first: *mut malloc_heap__bindgen_ty_1_malloc_elem, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct malloc_heap__bindgen_ty_1_malloc_elem([u8; 0]); +#[test] +fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<malloc_heap__bindgen_ty_1>() , 8usize , + concat ! ( + "Size of: " , stringify ! ( malloc_heap__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<malloc_heap__bindgen_ty_1>() , 8usize , + concat ! ( + "Alignment of " , stringify ! ( malloc_heap__bindgen_ty_1 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const malloc_heap__bindgen_ty_1 ) ) . lh_first + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + malloc_heap__bindgen_ty_1 ) , "::" , stringify ! ( lh_first ) + )); +} +impl Clone for malloc_heap__bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +#[test] +fn bindgen_test_layout_malloc_heap() { + assert_eq!(::std::mem::size_of::<malloc_heap>() , 128usize , concat ! ( + "Size of: " , stringify ! ( malloc_heap ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const malloc_heap ) ) . lock as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( malloc_heap ) , "::" , + stringify ! ( lock ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const malloc_heap ) ) . free_head as * const _ + as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( malloc_heap ) , "::" , + stringify ! ( free_head ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const malloc_heap ) ) . alloc_count as * const + _ as usize } , 112usize , concat ! ( + "Alignment of field: " , stringify ! ( malloc_heap ) , "::" , + stringify ! ( alloc_count ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const malloc_heap ) ) . total_size as * const _ + as usize } , 120usize , concat ! ( + "Alignment of field: " , stringify ! ( malloc_heap ) , "::" , + stringify ! ( total_size ) )); +} +impl Clone for malloc_heap { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs new file mode 100644 index 00000000..be4944bb --- /dev/null +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -0,0 +1,192 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +/** + * Stores a pointer to the ops struct, and the offset: the place to + * write the parsed result in the destination structure. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct cmdline_token_hdr { + pub ops: *mut cmdline_token_hdr_cmdline_token_ops, + pub offset: ::std::os::raw::c_uint, +} +/** + * A token is defined by this structure. + * + * parse() takes the token as first argument, then the source buffer + * starting at the token we want to parse. The 3rd arg is a pointer + * where we store the parsed data (as binary). It returns the number of + * parsed chars on success and a negative value on error. + * + * complete_get_nb() returns the number of possible values for this + * token if completion is possible. If it is NULL or if it returns 0, + * no completion is possible. + * + * complete_get_elt() copy in dstbuf (the size is specified in the + * parameter) the i-th possible completion for this token. returns 0 + * on success or and a negative value on error. + * + * get_help() fills the dstbuf with the help for the token. It returns + * -1 on error and 0 on success. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct cmdline_token_hdr_cmdline_token_ops { + /** parse(token ptr, buf, res pts, buf len) */ + pub parse: ::std::option::Option<unsafe extern "C" fn(arg1: + *mut cmdline_parse_token_hdr_t, + arg2: + *const ::std::os::raw::c_char, + arg3: + *mut ::std::os::raw::c_void, + arg4: + ::std::os::raw::c_uint) + -> ::std::os::raw::c_int>, + /** return the num of possible choices for this token */ + pub complete_get_nb: ::std::option::Option<unsafe extern "C" fn(arg1: + *mut cmdline_parse_token_hdr_t) + -> ::std::os::raw::c_int>, + /** return the elt x for this token (token, idx, dstbuf, size) */ + pub complete_get_elt: ::std::option::Option<unsafe extern "C" fn(arg1: + *mut cmdline_parse_token_hdr_t, + arg2: + ::std::os::raw::c_int, + arg3: + *mut ::std::os::raw::c_char, + arg4: + ::std::os::raw::c_uint) + -> ::std::os::raw::c_int>, + /** get help for this token (token, dstbuf, size) */ + pub get_help: ::std::option::Option<unsafe extern "C" fn(arg1: + *mut cmdline_parse_token_hdr_t, + arg2: + *mut ::std::os::raw::c_char, + arg3: + ::std::os::raw::c_uint) + -> ::std::os::raw::c_int>, +} +#[test] +fn bindgen_test_layout_cmdline_token_hdr_cmdline_token_ops() { + assert_eq!(::std::mem::size_of::<cmdline_token_hdr_cmdline_token_ops>() , + 32usize , concat ! ( + "Size of: " , stringify ! ( cmdline_token_hdr_cmdline_token_ops + ) )); + assert_eq! (::std::mem::align_of::<cmdline_token_hdr_cmdline_token_ops>() + , 8usize , concat ! ( + "Alignment of " , stringify ! ( + cmdline_token_hdr_cmdline_token_ops ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const cmdline_token_hdr_cmdline_token_ops ) ) . + parse as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + cmdline_token_hdr_cmdline_token_ops ) , "::" , stringify ! ( + parse ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const cmdline_token_hdr_cmdline_token_ops ) ) . + complete_get_nb as * const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( + cmdline_token_hdr_cmdline_token_ops ) , "::" , stringify ! ( + complete_get_nb ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const cmdline_token_hdr_cmdline_token_ops ) ) . + complete_get_elt as * const _ as usize } , 16usize , concat ! + ( + "Alignment of field: " , stringify ! ( + cmdline_token_hdr_cmdline_token_ops ) , "::" , stringify ! ( + complete_get_elt ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const cmdline_token_hdr_cmdline_token_ops ) ) . + get_help as * const _ as usize } , 24usize , concat ! ( + "Alignment of field: " , stringify ! ( + cmdline_token_hdr_cmdline_token_ops ) , "::" , stringify ! ( + get_help ) )); +} +impl Clone for cmdline_token_hdr_cmdline_token_ops { + fn clone(&self) -> Self { *self } +} +#[test] +fn bindgen_test_layout_cmdline_token_hdr() { + assert_eq!(::std::mem::size_of::<cmdline_token_hdr>() , 16usize , concat ! + ( "Size of: " , stringify ! ( cmdline_token_hdr ) )); + assert_eq! (::std::mem::align_of::<cmdline_token_hdr>() , 8usize , concat + ! ( "Alignment of " , stringify ! ( cmdline_token_hdr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const cmdline_token_hdr ) ) . ops as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( cmdline_token_hdr ) , + "::" , stringify ! ( ops ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const cmdline_token_hdr ) ) . offset as * const + _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( cmdline_token_hdr ) , + "::" , stringify ! ( offset ) )); +} +impl Clone for cmdline_token_hdr { + fn clone(&self) -> Self { *self } +} +pub type cmdline_parse_token_hdr_t = cmdline_token_hdr; +#[repr(u32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum cmdline_numtype { + UINT8 = 0, + UINT16 = 1, + UINT32 = 2, + UINT64 = 3, + INT8 = 4, + INT16 = 5, + INT32 = 6, + INT64 = 7, +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct cmdline_token_num_data { + pub type_: cmdline_numtype, +} +#[test] +fn bindgen_test_layout_cmdline_token_num_data() { + assert_eq!(::std::mem::size_of::<cmdline_token_num_data>() , 4usize , + concat ! ( "Size of: " , stringify ! ( cmdline_token_num_data ) + )); + assert_eq! (::std::mem::align_of::<cmdline_token_num_data>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( cmdline_token_num_data ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const cmdline_token_num_data ) ) . type_ as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( cmdline_token_num_data + ) , "::" , stringify ! ( type_ ) )); +} +impl Clone for cmdline_token_num_data { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct cmdline_token_num { + pub hdr: cmdline_token_hdr, + pub num_data: cmdline_token_num_data, +} +#[test] +fn bindgen_test_layout_cmdline_token_num() { + assert_eq!(::std::mem::size_of::<cmdline_token_num>() , 24usize , concat ! + ( "Size of: " , stringify ! ( cmdline_token_num ) )); + assert_eq! (::std::mem::align_of::<cmdline_token_num>() , 8usize , concat + ! ( "Alignment of " , stringify ! ( cmdline_token_num ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const cmdline_token_num ) ) . hdr as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( cmdline_token_num ) , + "::" , stringify ! ( hdr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const cmdline_token_num ) ) . num_data as * + const _ as usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( cmdline_token_num ) , + "::" , stringify ! ( num_data ) )); +} +impl Clone for cmdline_token_num { + fn clone(&self) -> Self { *self } +} +pub type cmdline_parse_token_num_t = cmdline_token_num; diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs new file mode 100644 index 00000000..0034e707 --- /dev/null +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -0,0 +1,1285 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>); +impl <T> __BindgenUnionField<T> { + #[inline] + pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) } + #[inline] + pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { ::std::mem::transmute(self) } +} +impl <T> ::std::default::Default for __BindgenUnionField<T> { + #[inline] + fn default() -> Self { Self::new() } +} +impl <T> ::std::clone::Clone for __BindgenUnionField<T> { + #[inline] + fn clone(&self) -> Self { Self::new() } +} +impl <T> ::std::marker::Copy for __BindgenUnionField<T> { } +impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +pub const ETH_MQ_RX_RSS_FLAG: ::std::os::raw::c_uint = 1; +pub const ETH_MQ_RX_DCB_FLAG: ::std::os::raw::c_uint = 2; +pub const ETH_MQ_RX_VMDQ_FLAG: ::std::os::raw::c_uint = 4; +pub const ETH_VMDQ_MAX_VLAN_FILTERS: ::std::os::raw::c_uint = 64; +pub const ETH_DCB_NUM_USER_PRIORITIES: ::std::os::raw::c_uint = 8; +pub const ETH_VMDQ_DCB_NUM_QUEUES: ::std::os::raw::c_uint = 128; +pub const ETH_DCB_NUM_QUEUES: ::std::os::raw::c_uint = 128; +pub const RTE_ETH_FDIR_MAX_FLEXLEN: ::std::os::raw::c_uint = 16; +pub const RTE_ETH_INSET_SIZE_MAX: ::std::os::raw::c_uint = 128; +pub const RTE_ETH_FLOW_UNKNOWN: ::std::os::raw::c_uint = 0; +pub const RTE_ETH_FLOW_RAW: ::std::os::raw::c_uint = 1; +pub const RTE_ETH_FLOW_IPV4: ::std::os::raw::c_uint = 2; +pub const RTE_ETH_FLOW_FRAG_IPV4: ::std::os::raw::c_uint = 3; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_TCP: ::std::os::raw::c_uint = 4; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_UDP: ::std::os::raw::c_uint = 5; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: ::std::os::raw::c_uint = 6; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: ::std::os::raw::c_uint = 7; +pub const RTE_ETH_FLOW_IPV6: ::std::os::raw::c_uint = 8; +pub const RTE_ETH_FLOW_FRAG_IPV6: ::std::os::raw::c_uint = 9; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_TCP: ::std::os::raw::c_uint = 10; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_UDP: ::std::os::raw::c_uint = 11; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: ::std::os::raw::c_uint = 12; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: ::std::os::raw::c_uint = 13; +pub const RTE_ETH_FLOW_L2_PAYLOAD: ::std::os::raw::c_uint = 14; +pub const RTE_ETH_FLOW_IPV6_EX: ::std::os::raw::c_uint = 15; +pub const RTE_ETH_FLOW_IPV6_TCP_EX: ::std::os::raw::c_uint = 16; +pub const RTE_ETH_FLOW_IPV6_UDP_EX: ::std::os::raw::c_uint = 17; +pub const RTE_ETH_FLOW_PORT: ::std::os::raw::c_uint = 18; +pub const RTE_ETH_FLOW_VXLAN: ::std::os::raw::c_uint = 19; +pub const RTE_ETH_FLOW_GENEVE: ::std::os::raw::c_uint = 20; +pub const RTE_ETH_FLOW_NVGRE: ::std::os::raw::c_uint = 21; +pub const RTE_ETH_FLOW_MAX: ::std::os::raw::c_uint = 22; +#[repr(u32)] +/** + * A set of values to identify what method is to be used to route + * packets to multiple queues. + */ +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum rte_eth_rx_mq_mode { + ETH_MQ_RX_NONE = 0, + ETH_MQ_RX_RSS = 1, + ETH_MQ_RX_DCB = 2, + ETH_MQ_RX_DCB_RSS = 3, + ETH_MQ_RX_VMDQ_ONLY = 4, + ETH_MQ_RX_VMDQ_RSS = 5, + ETH_MQ_RX_VMDQ_DCB = 6, + ETH_MQ_RX_VMDQ_DCB_RSS = 7, +} +/** + * A structure used to configure the RX features of an Ethernet port. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_rxmode { + /** The multi-queue packet distribution mode to be used, e.g. RSS. */ + pub mq_mode: rte_eth_rx_mq_mode, + /**< Only used if jumbo_frame enabled. */ + pub max_rx_pkt_len: u32, + /**< hdr buf size (header_split enabled).*/ + pub split_hdr_size: u16, + pub _bitfield_1: u16, +} +#[test] +fn bindgen_test_layout_rte_eth_rxmode() { + assert_eq!(::std::mem::size_of::<rte_eth_rxmode>() , 12usize , concat ! ( + "Size of: " , stringify ! ( rte_eth_rxmode ) )); + assert_eq! (::std::mem::align_of::<rte_eth_rxmode>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( rte_eth_rxmode ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_rxmode ) ) . mq_mode as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_rxmode ) , "::" + , stringify ! ( mq_mode ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_rxmode ) ) . max_rx_pkt_len as * + const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_rxmode ) , "::" + , stringify ! ( max_rx_pkt_len ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_rxmode ) ) . split_hdr_size as * + const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_rxmode ) , "::" + , stringify ! ( split_hdr_size ) )); +} +impl Clone for rte_eth_rxmode { + fn clone(&self) -> Self { *self } +} +impl rte_eth_rxmode { + #[inline] + pub fn header_split(&self) -> u16 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (1usize as u16)) >> + 0u32) as u16) + } + } + #[inline] + pub fn set_header_split(&mut self, val: u16) { + self._bitfield_1 &= !(1usize as u16); + self._bitfield_1 |= ((val as u16 as u16) << 0u32) & (1usize as u16); + } + #[inline] + pub fn hw_ip_checksum(&self) -> u16 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (2usize as u16)) >> + 1u32) as u16) + } + } + #[inline] + pub fn set_hw_ip_checksum(&mut self, val: u16) { + self._bitfield_1 &= !(2usize as u16); + self._bitfield_1 |= ((val as u16 as u16) << 1u32) & (2usize as u16); + } + #[inline] + pub fn hw_vlan_filter(&self) -> u16 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (4usize as u16)) >> + 2u32) as u16) + } + } + #[inline] + pub fn set_hw_vlan_filter(&mut self, val: u16) { + self._bitfield_1 &= !(4usize as u16); + self._bitfield_1 |= ((val as u16 as u16) << 2u32) & (4usize as u16); + } + #[inline] + pub fn hw_vlan_strip(&self) -> u16 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (8usize as u16)) >> + 3u32) as u16) + } + } + #[inline] + pub fn set_hw_vlan_strip(&mut self, val: u16) { + self._bitfield_1 &= !(8usize as u16); + self._bitfield_1 |= ((val as u16 as u16) << 3u32) & (8usize as u16); + } + #[inline] + pub fn hw_vlan_extend(&self) -> u16 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (16usize as u16)) >> + 4u32) as u16) + } + } + #[inline] + pub fn set_hw_vlan_extend(&mut self, val: u16) { + self._bitfield_1 &= !(16usize as u16); + self._bitfield_1 |= ((val as u16 as u16) << 4u32) & (16usize as u16); + } + #[inline] + pub fn jumbo_frame(&self) -> u16 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (32usize as u16)) >> + 5u32) as u16) + } + } + #[inline] + pub fn set_jumbo_frame(&mut self, val: u16) { + self._bitfield_1 &= !(32usize as u16); + self._bitfield_1 |= ((val as u16 as u16) << 5u32) & (32usize as u16); + } + #[inline] + pub fn hw_strip_crc(&self) -> u16 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (64usize as u16)) >> + 6u32) as u16) + } + } + #[inline] + pub fn set_hw_strip_crc(&mut self, val: u16) { + self._bitfield_1 &= !(64usize as u16); + self._bitfield_1 |= ((val as u16 as u16) << 6u32) & (64usize as u16); + } + #[inline] + pub fn enable_scatter(&self) -> u16 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (128usize as u16)) >> + 7u32) as u16) + } + } + #[inline] + pub fn set_enable_scatter(&mut self, val: u16) { + self._bitfield_1 &= !(128usize as u16); + self._bitfield_1 |= ((val as u16 as u16) << 7u32) & (128usize as u16); + } + #[inline] + pub fn enable_lro(&self) -> u16 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (256usize as u16)) >> + 8u32) as u16) + } + } + #[inline] + pub fn set_enable_lro(&mut self, val: u16) { + self._bitfield_1 &= !(256usize as u16); + self._bitfield_1 |= ((val as u16 as u16) << 8u32) & (256usize as u16); + } +} +#[repr(u32)] +/** + * A set of values to identify what method is to be used to transmit + * packets using multi-TCs. + */ +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum rte_eth_tx_mq_mode { + ETH_MQ_TX_NONE = 0, + ETH_MQ_TX_DCB = 1, + ETH_MQ_TX_VMDQ_DCB = 2, + ETH_MQ_TX_VMDQ_ONLY = 3, +} +/** + * A structure used to configure the TX features of an Ethernet port. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_txmode { + /**< TX multi-queues mode. */ + pub mq_mode: rte_eth_tx_mq_mode, + pub pvid: u16, + pub _bitfield_1: u8, +} +#[test] +fn bindgen_test_layout_rte_eth_txmode() { + assert_eq!(::std::mem::size_of::<rte_eth_txmode>() , 8usize , concat ! ( + "Size of: " , stringify ! ( rte_eth_txmode ) )); + assert_eq! (::std::mem::align_of::<rte_eth_txmode>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( rte_eth_txmode ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_txmode ) ) . mq_mode as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_txmode ) , "::" + , stringify ! ( mq_mode ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_txmode ) ) . pvid as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_txmode ) , "::" + , stringify ! ( pvid ) )); +} +impl Clone for rte_eth_txmode { + fn clone(&self) -> Self { *self } +} +impl rte_eth_txmode { + #[inline] + pub fn hw_vlan_reject_tagged(&self) -> u8 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (1usize as u8)) >> + 0u32) as u8) + } + } + #[inline] + pub fn set_hw_vlan_reject_tagged(&mut self, val: u8) { + self._bitfield_1 &= !(1usize as u8); + self._bitfield_1 |= ((val as u8 as u8) << 0u32) & (1usize as u8); + } + #[inline] + pub fn hw_vlan_reject_untagged(&self) -> u8 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (2usize as u8)) >> + 1u32) as u8) + } + } + #[inline] + pub fn set_hw_vlan_reject_untagged(&mut self, val: u8) { + self._bitfield_1 &= !(2usize as u8); + self._bitfield_1 |= ((val as u8 as u8) << 1u32) & (2usize as u8); + } + #[inline] + pub fn hw_vlan_insert_pvid(&self) -> u8 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (4usize as u8)) >> + 2u32) as u8) + } + } + #[inline] + pub fn set_hw_vlan_insert_pvid(&mut self, val: u8) { + self._bitfield_1 &= !(4usize as u8); + self._bitfield_1 |= ((val as u8 as u8) << 2u32) & (4usize as u8); + } +} +/** + * A structure used to configure the Receive Side Scaling (RSS) feature + * of an Ethernet port. + * If not NULL, the *rss_key* pointer of the *rss_conf* structure points + * to an array holding the RSS key to use for hashing specific header + * fields of received packets. The length of this array should be indicated + * by *rss_key_len* below. Otherwise, a default random hash key is used by + * the device driver. + * + * The *rss_key_len* field of the *rss_conf* structure indicates the length + * in bytes of the array pointed by *rss_key*. To be compatible, this length + * will be checked in i40e only. Others assume 40 bytes to be used as before. + * + * The *rss_hf* field of the *rss_conf* structure indicates the different + * types of IPv4/IPv6 packets to which the RSS hashing must be applied. + * Supplying an *rss_hf* equal to zero disables the RSS feature. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_rss_conf { + /**< If not NULL, 40-byte hash key. */ + pub rss_key: *mut u8, + /**< hash key length in bytes. */ + pub rss_key_len: u8, + /**< Hash functions to apply - see below. */ + pub rss_hf: u64, +} +#[test] +fn bindgen_test_layout_rte_eth_rss_conf() { + assert_eq!(::std::mem::size_of::<rte_eth_rss_conf>() , 24usize , concat ! + ( "Size of: " , stringify ! ( rte_eth_rss_conf ) )); + assert_eq! (::std::mem::align_of::<rte_eth_rss_conf>() , 8usize , concat ! + ( "Alignment of " , stringify ! ( rte_eth_rss_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_rss_conf ) ) . rss_key as * const + _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_rss_conf ) , + "::" , stringify ! ( rss_key ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_rss_conf ) ) . rss_key_len as * + const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_rss_conf ) , + "::" , stringify ! ( rss_key_len ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_rss_conf ) ) . rss_hf as * const + _ as usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_rss_conf ) , + "::" , stringify ! ( rss_hf ) )); +} +impl Clone for rte_eth_rss_conf { + fn clone(&self) -> Self { *self } +} +#[repr(u32)] +/** + * This enum indicates the possible number of traffic classes + * in DCB configratioins + */ +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum rte_eth_nb_tcs { ETH_4_TCS = 4, ETH_8_TCS = 8, } +#[repr(u32)] +/** + * This enum indicates the possible number of queue pools + * in VMDQ configurations. + */ +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum rte_eth_nb_pools { + ETH_8_POOLS = 8, + ETH_16_POOLS = 16, + ETH_32_POOLS = 32, + ETH_64_POOLS = 64, +} +/** + * A structure used to configure the VMDQ+DCB feature + * of an Ethernet port. + * + * Using this feature, packets are routed to a pool of queues, based + * on the vlan id in the vlan tag, and then to a specific queue within + * that pool, using the user priority vlan tag field. + * + * A default pool may be used, if desired, to route all traffic which + * does not match the vlan filter rules. + */ +#[repr(C)] +pub struct rte_eth_vmdq_dcb_conf { + /**< With DCB, 16 or 32 pools */ + pub nb_queue_pools: rte_eth_nb_pools, + /**< If non-zero, use a default pool */ + pub enable_default_pool: u8, + /**< The default pool, if applicable */ + pub default_pool: u8, + /**< We can have up to 64 filters/mappings */ + pub nb_pool_maps: u8, + /**< VMDq vlan pool maps. */ + pub pool_map: [rte_eth_vmdq_dcb_conf__bindgen_ty_1; 64usize], + pub dcb_tc: [u8; 8usize], +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { + /**< The vlan id of the received frame */ + pub vlan_id: u16, + /**< Bitmask of pools for packet rx */ + pub pools: u64, +} +#[test] +fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<rte_eth_vmdq_dcb_conf__bindgen_ty_1>() , + 16usize , concat ! ( + "Size of: " , stringify ! ( rte_eth_vmdq_dcb_conf__bindgen_ty_1 + ) )); + assert_eq! (::std::mem::align_of::<rte_eth_vmdq_dcb_conf__bindgen_ty_1>() + , 8usize , concat ! ( + "Alignment of " , stringify ! ( + rte_eth_vmdq_dcb_conf__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_dcb_conf__bindgen_ty_1 ) ) . + vlan_id as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_vmdq_dcb_conf__bindgen_ty_1 ) , "::" , stringify ! ( + vlan_id ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_dcb_conf__bindgen_ty_1 ) ) . + pools as * const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_vmdq_dcb_conf__bindgen_ty_1 ) , "::" , stringify ! ( + pools ) )); +} +impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +#[test] +fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { + assert_eq!(::std::mem::size_of::<rte_eth_vmdq_dcb_conf>() , 1040usize , + concat ! ( "Size of: " , stringify ! ( rte_eth_vmdq_dcb_conf ) + )); + assert_eq! (::std::mem::align_of::<rte_eth_vmdq_dcb_conf>() , 8usize , + concat ! ( + "Alignment of " , stringify ! ( rte_eth_vmdq_dcb_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_dcb_conf ) ) . + nb_queue_pools as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_dcb_conf ) + , "::" , stringify ! ( nb_queue_pools ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_dcb_conf ) ) . + enable_default_pool as * const _ as usize } , 4usize , concat + ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_dcb_conf ) + , "::" , stringify ! ( enable_default_pool ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_dcb_conf ) ) . default_pool + as * const _ as usize } , 5usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_dcb_conf ) + , "::" , stringify ! ( default_pool ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_dcb_conf ) ) . nb_pool_maps + as * const _ as usize } , 6usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_dcb_conf ) + , "::" , stringify ! ( nb_pool_maps ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_dcb_conf ) ) . pool_map as * + const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_dcb_conf ) + , "::" , stringify ! ( pool_map ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_dcb_conf ) ) . dcb_tc as * + const _ as usize } , 1032usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_dcb_conf ) + , "::" , stringify ! ( dcb_tc ) )); +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_dcb_rx_conf { + /**< Possible DCB TCs, 4 or 8 TCs */ + pub nb_tcs: rte_eth_nb_tcs, + /** Traffic class each UP mapped to. */ + pub dcb_tc: [u8; 8usize], +} +#[test] +fn bindgen_test_layout_rte_eth_dcb_rx_conf() { + assert_eq!(::std::mem::size_of::<rte_eth_dcb_rx_conf>() , 12usize , concat + ! ( "Size of: " , stringify ! ( rte_eth_dcb_rx_conf ) )); + assert_eq! (::std::mem::align_of::<rte_eth_dcb_rx_conf>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( rte_eth_dcb_rx_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_dcb_rx_conf ) ) . nb_tcs as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_dcb_rx_conf ) , + "::" , stringify ! ( nb_tcs ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_dcb_rx_conf ) ) . dcb_tc as * + const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_dcb_rx_conf ) , + "::" , stringify ! ( dcb_tc ) )); +} +impl Clone for rte_eth_dcb_rx_conf { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_vmdq_dcb_tx_conf { + /**< With DCB, 16 or 32 pools. */ + pub nb_queue_pools: rte_eth_nb_pools, + /** Traffic class each UP mapped to. */ + pub dcb_tc: [u8; 8usize], +} +#[test] +fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { + assert_eq!(::std::mem::size_of::<rte_eth_vmdq_dcb_tx_conf>() , 12usize , + concat ! ( + "Size of: " , stringify ! ( rte_eth_vmdq_dcb_tx_conf ) )); + assert_eq! (::std::mem::align_of::<rte_eth_vmdq_dcb_tx_conf>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( rte_eth_vmdq_dcb_tx_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_dcb_tx_conf ) ) . + nb_queue_pools as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_vmdq_dcb_tx_conf ) , "::" , stringify ! ( + nb_queue_pools ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_dcb_tx_conf ) ) . dcb_tc as + * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_vmdq_dcb_tx_conf ) , "::" , stringify ! ( dcb_tc ) )); +} +impl Clone for rte_eth_vmdq_dcb_tx_conf { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_dcb_tx_conf { + /**< Possible DCB TCs, 4 or 8 TCs. */ + pub nb_tcs: rte_eth_nb_tcs, + /** Traffic class each UP mapped to. */ + pub dcb_tc: [u8; 8usize], +} +#[test] +fn bindgen_test_layout_rte_eth_dcb_tx_conf() { + assert_eq!(::std::mem::size_of::<rte_eth_dcb_tx_conf>() , 12usize , concat + ! ( "Size of: " , stringify ! ( rte_eth_dcb_tx_conf ) )); + assert_eq! (::std::mem::align_of::<rte_eth_dcb_tx_conf>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( rte_eth_dcb_tx_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_dcb_tx_conf ) ) . nb_tcs as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_dcb_tx_conf ) , + "::" , stringify ! ( nb_tcs ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_dcb_tx_conf ) ) . dcb_tc as * + const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_dcb_tx_conf ) , + "::" , stringify ! ( dcb_tc ) )); +} +impl Clone for rte_eth_dcb_tx_conf { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_vmdq_tx_conf { + /**< VMDq mode, 64 pools. */ + pub nb_queue_pools: rte_eth_nb_pools, +} +#[test] +fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { + assert_eq!(::std::mem::size_of::<rte_eth_vmdq_tx_conf>() , 4usize , concat + ! ( "Size of: " , stringify ! ( rte_eth_vmdq_tx_conf ) )); + assert_eq! (::std::mem::align_of::<rte_eth_vmdq_tx_conf>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( rte_eth_vmdq_tx_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_tx_conf ) ) . nb_queue_pools + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_tx_conf ) + , "::" , stringify ! ( nb_queue_pools ) )); +} +impl Clone for rte_eth_vmdq_tx_conf { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +pub struct rte_eth_vmdq_rx_conf { + /**< VMDq only mode, 8 or 64 pools */ + pub nb_queue_pools: rte_eth_nb_pools, + /**< If non-zero, use a default pool */ + pub enable_default_pool: u8, + /**< The default pool, if applicable */ + pub default_pool: u8, + /**< Enable VT loop back */ + pub enable_loop_back: u8, + /**< We can have up to 64 filters/mappings */ + pub nb_pool_maps: u8, + /**< Flags from ETH_VMDQ_ACCEPT_* */ + pub rx_mode: u32, + /**< VMDq vlan pool maps. */ + pub pool_map: [rte_eth_vmdq_rx_conf__bindgen_ty_1; 64usize], +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { + /**< The vlan id of the received frame */ + pub vlan_id: u16, + /**< Bitmask of pools for packet rx */ + pub pools: u64, +} +#[test] +fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<rte_eth_vmdq_rx_conf__bindgen_ty_1>() , + 16usize , concat ! ( + "Size of: " , stringify ! ( rte_eth_vmdq_rx_conf__bindgen_ty_1 + ) )); + assert_eq! (::std::mem::align_of::<rte_eth_vmdq_rx_conf__bindgen_ty_1>() , + 8usize , concat ! ( + "Alignment of " , stringify ! ( + rte_eth_vmdq_rx_conf__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_rx_conf__bindgen_ty_1 ) ) . + vlan_id as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_vmdq_rx_conf__bindgen_ty_1 ) , "::" , stringify ! ( + vlan_id ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_rx_conf__bindgen_ty_1 ) ) . + pools as * const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_vmdq_rx_conf__bindgen_ty_1 ) , "::" , stringify ! ( + pools ) )); +} +impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +#[test] +fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { + assert_eq!(::std::mem::size_of::<rte_eth_vmdq_rx_conf>() , 1040usize , + concat ! ( "Size of: " , stringify ! ( rte_eth_vmdq_rx_conf ) + )); + assert_eq! (::std::mem::align_of::<rte_eth_vmdq_rx_conf>() , 8usize , + concat ! ( + "Alignment of " , stringify ! ( rte_eth_vmdq_rx_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_rx_conf ) ) . nb_queue_pools + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_rx_conf ) + , "::" , stringify ! ( nb_queue_pools ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_rx_conf ) ) . + enable_default_pool as * const _ as usize } , 4usize , concat + ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_rx_conf ) + , "::" , stringify ! ( enable_default_pool ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_rx_conf ) ) . default_pool + as * const _ as usize } , 5usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_rx_conf ) + , "::" , stringify ! ( default_pool ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_rx_conf ) ) . + enable_loop_back as * const _ as usize } , 6usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_rx_conf ) + , "::" , stringify ! ( enable_loop_back ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_rx_conf ) ) . nb_pool_maps + as * const _ as usize } , 7usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_rx_conf ) + , "::" , stringify ! ( nb_pool_maps ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_rx_conf ) ) . rx_mode as * + const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_rx_conf ) + , "::" , stringify ! ( rx_mode ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_vmdq_rx_conf ) ) . pool_map as * + const _ as usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_vmdq_rx_conf ) + , "::" , stringify ! ( pool_map ) )); +} +#[repr(u32)] +/** + * Flow Director setting modes: none, signature or perfect. + */ +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum rte_fdir_mode { + RTE_FDIR_MODE_NONE = 0, + RTE_FDIR_MODE_SIGNATURE = 1, + RTE_FDIR_MODE_PERFECT = 2, + RTE_FDIR_MODE_PERFECT_MAC_VLAN = 3, + RTE_FDIR_MODE_PERFECT_TUNNEL = 4, +} +#[repr(u32)] +/** + * Memory space that can be configured to store Flow Director filters + * in the board memory. + */ +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum rte_fdir_pballoc_type { + RTE_FDIR_PBALLOC_64K = 0, + RTE_FDIR_PBALLOC_128K = 1, + RTE_FDIR_PBALLOC_256K = 2, +} +#[repr(u32)] +/** + * Select report mode of FDIR hash information in RX descriptors. + */ +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum rte_fdir_status_mode { + RTE_FDIR_NO_REPORT_STATUS = 0, + RTE_FDIR_REPORT_STATUS = 1, + RTE_FDIR_REPORT_STATUS_ALWAYS = 2, +} +/** + * A structure used to define the input for IPV4 flow + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_ipv4_flow { + /**< IPv4 source address in big endian. */ + pub src_ip: u32, + /**< IPv4 destination address in big endian. */ + pub dst_ip: u32, + /**< Type of service to match. */ + pub tos: u8, + /**< Time to live to match. */ + pub ttl: u8, + /**< Protocol, next header in big endian. */ + pub proto: u8, +} +#[test] +fn bindgen_test_layout_rte_eth_ipv4_flow() { + assert_eq!(::std::mem::size_of::<rte_eth_ipv4_flow>() , 12usize , concat ! + ( "Size of: " , stringify ! ( rte_eth_ipv4_flow ) )); + assert_eq! (::std::mem::align_of::<rte_eth_ipv4_flow>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( rte_eth_ipv4_flow ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_ipv4_flow ) ) . src_ip as * const + _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_ipv4_flow ) , + "::" , stringify ! ( src_ip ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_ipv4_flow ) ) . dst_ip as * const + _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_ipv4_flow ) , + "::" , stringify ! ( dst_ip ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_ipv4_flow ) ) . tos as * const _ + as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_ipv4_flow ) , + "::" , stringify ! ( tos ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_ipv4_flow ) ) . ttl as * const _ + as usize } , 9usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_ipv4_flow ) , + "::" , stringify ! ( ttl ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_ipv4_flow ) ) . proto as * const + _ as usize } , 10usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_ipv4_flow ) , + "::" , stringify ! ( proto ) )); +} +impl Clone for rte_eth_ipv4_flow { + fn clone(&self) -> Self { *self } +} +/** + * A structure used to define the input for IPV6 flow + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_ipv6_flow { + /**< IPv6 source address in big endian. */ + pub src_ip: [u32; 4usize], + /**< IPv6 destination address in big endian. */ + pub dst_ip: [u32; 4usize], + /**< Traffic class to match. */ + pub tc: u8, + /**< Protocol, next header to match. */ + pub proto: u8, + /**< Hop limits to match. */ + pub hop_limits: u8, +} +#[test] +fn bindgen_test_layout_rte_eth_ipv6_flow() { + assert_eq!(::std::mem::size_of::<rte_eth_ipv6_flow>() , 36usize , concat ! + ( "Size of: " , stringify ! ( rte_eth_ipv6_flow ) )); + assert_eq! (::std::mem::align_of::<rte_eth_ipv6_flow>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( rte_eth_ipv6_flow ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_ipv6_flow ) ) . src_ip as * const + _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_ipv6_flow ) , + "::" , stringify ! ( src_ip ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_ipv6_flow ) ) . dst_ip as * const + _ as usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_ipv6_flow ) , + "::" , stringify ! ( dst_ip ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_ipv6_flow ) ) . tc as * const _ + as usize } , 32usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_ipv6_flow ) , + "::" , stringify ! ( tc ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_ipv6_flow ) ) . proto as * const + _ as usize } , 33usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_ipv6_flow ) , + "::" , stringify ! ( proto ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_ipv6_flow ) ) . hop_limits as * + const _ as usize } , 34usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_ipv6_flow ) , + "::" , stringify ! ( hop_limits ) )); +} +impl Clone for rte_eth_ipv6_flow { + fn clone(&self) -> Self { *self } +} +/** + * A structure used to configure FDIR masks that are used by the device + * to match the various fields of RX packet headers. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_fdir_masks { + /**< Bit mask for vlan_tci in big endian */ + pub vlan_tci_mask: u16, + /** Bit mask for ipv4 flow in big endian. */ + pub ipv4_mask: rte_eth_ipv4_flow, + /** Bit maks for ipv6 flow in big endian. */ + pub ipv6_mask: rte_eth_ipv6_flow, + /** Bit mask for L4 source port in big endian. */ + pub src_port_mask: u16, + /** Bit mask for L4 destination port in big endian. */ + pub dst_port_mask: u16, + /** 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the + first byte on the wire */ + pub mac_addr_byte_mask: u8, + /** Bit mask for tunnel ID in big endian. */ + pub tunnel_id_mask: u32, + /**< 1 - Match tunnel type, + 0 - Ignore tunnel type. */ + pub tunnel_type_mask: u8, +} +#[test] +fn bindgen_test_layout_rte_eth_fdir_masks() { + assert_eq!(::std::mem::size_of::<rte_eth_fdir_masks>() , 68usize , concat + ! ( "Size of: " , stringify ! ( rte_eth_fdir_masks ) )); + assert_eq! (::std::mem::align_of::<rte_eth_fdir_masks>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( rte_eth_fdir_masks ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_masks ) ) . vlan_tci_mask as + * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_masks ) , + "::" , stringify ! ( vlan_tci_mask ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_masks ) ) . ipv4_mask as * + const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_masks ) , + "::" , stringify ! ( ipv4_mask ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_masks ) ) . ipv6_mask as * + const _ as usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_masks ) , + "::" , stringify ! ( ipv6_mask ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_masks ) ) . src_port_mask as + * const _ as usize } , 52usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_masks ) , + "::" , stringify ! ( src_port_mask ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_masks ) ) . dst_port_mask as + * const _ as usize } , 54usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_masks ) , + "::" , stringify ! ( dst_port_mask ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_masks ) ) . + mac_addr_byte_mask as * const _ as usize } , 56usize , concat + ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_masks ) , + "::" , stringify ! ( mac_addr_byte_mask ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_masks ) ) . tunnel_id_mask + as * const _ as usize } , 60usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_masks ) , + "::" , stringify ! ( tunnel_id_mask ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_masks ) ) . tunnel_type_mask + as * const _ as usize } , 64usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_masks ) , + "::" , stringify ! ( tunnel_type_mask ) )); +} +impl Clone for rte_eth_fdir_masks { + fn clone(&self) -> Self { *self } +} +#[repr(u32)] +/** + * Payload type + */ +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum rte_eth_payload_type { + RTE_ETH_PAYLOAD_UNKNOWN = 0, + RTE_ETH_RAW_PAYLOAD = 1, + RTE_ETH_L2_PAYLOAD = 2, + RTE_ETH_L3_PAYLOAD = 3, + RTE_ETH_L4_PAYLOAD = 4, + RTE_ETH_PAYLOAD_MAX = 8, +} +/** + * A structure used to select bytes extracted from the protocol layers to + * flexible payload for filter + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_flex_payload_cfg { + /**< Payload type */ + pub type_: rte_eth_payload_type, + pub src_offset: [u16; 16usize], +} +#[test] +fn bindgen_test_layout_rte_eth_flex_payload_cfg() { + assert_eq!(::std::mem::size_of::<rte_eth_flex_payload_cfg>() , 36usize , + concat ! ( + "Size of: " , stringify ! ( rte_eth_flex_payload_cfg ) )); + assert_eq! (::std::mem::align_of::<rte_eth_flex_payload_cfg>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( rte_eth_flex_payload_cfg ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_flex_payload_cfg ) ) . type_ as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_flex_payload_cfg ) , "::" , stringify ! ( type_ ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_flex_payload_cfg ) ) . src_offset + as * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_flex_payload_cfg ) , "::" , stringify ! ( src_offset ) + )); +} +impl Clone for rte_eth_flex_payload_cfg { + fn clone(&self) -> Self { *self } +} +/** + * A structure used to define FDIR masks for flexible payload + * for each flow type + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_fdir_flex_mask { + pub flow_type: u16, + pub mask: [u8; 16usize], +} +#[test] +fn bindgen_test_layout_rte_eth_fdir_flex_mask() { + assert_eq!(::std::mem::size_of::<rte_eth_fdir_flex_mask>() , 18usize , + concat ! ( "Size of: " , stringify ! ( rte_eth_fdir_flex_mask ) + )); + assert_eq! (::std::mem::align_of::<rte_eth_fdir_flex_mask>() , 2usize , + concat ! ( + "Alignment of " , stringify ! ( rte_eth_fdir_flex_mask ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_flex_mask ) ) . flow_type as + * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_flex_mask + ) , "::" , stringify ! ( flow_type ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_flex_mask ) ) . mask as * + const _ as usize } , 2usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_flex_mask + ) , "::" , stringify ! ( mask ) )); +} +impl Clone for rte_eth_fdir_flex_mask { + fn clone(&self) -> Self { *self } +} +/** + * A structure used to define all flexible payload related setting + * include flex payload and flex mask + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_fdir_flex_conf { + /**< The number of following payload cfg */ + pub nb_payloads: u16, + /**< The number of following mask */ + pub nb_flexmasks: u16, + pub flex_set: [rte_eth_flex_payload_cfg; 8usize], + pub flex_mask: [rte_eth_fdir_flex_mask; 22usize], +} +#[test] +fn bindgen_test_layout_rte_eth_fdir_flex_conf() { + assert_eq!(::std::mem::size_of::<rte_eth_fdir_flex_conf>() , 688usize , + concat ! ( "Size of: " , stringify ! ( rte_eth_fdir_flex_conf ) + )); + assert_eq! (::std::mem::align_of::<rte_eth_fdir_flex_conf>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( rte_eth_fdir_flex_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_flex_conf ) ) . nb_payloads + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_flex_conf + ) , "::" , stringify ! ( nb_payloads ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_flex_conf ) ) . nb_flexmasks + as * const _ as usize } , 2usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_flex_conf + ) , "::" , stringify ! ( nb_flexmasks ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_flex_conf ) ) . flex_set as + * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_flex_conf + ) , "::" , stringify ! ( flex_set ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_fdir_flex_conf ) ) . flex_mask as + * const _ as usize } , 292usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_fdir_flex_conf + ) , "::" , stringify ! ( flex_mask ) )); +} +impl Clone for rte_eth_fdir_flex_conf { + fn clone(&self) -> Self { *self } +} +/** + * A structure used to configure the Flow Director (FDIR) feature + * of an Ethernet port. + * + * If mode is RTE_FDIR_DISABLE, the pballoc value is ignored. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_fdir_conf { + /**< Flow Director mode. */ + pub mode: rte_fdir_mode, + /**< Space for FDIR filters. */ + pub pballoc: rte_fdir_pballoc_type, + /**< How to report FDIR hash. */ + pub status: rte_fdir_status_mode, + /** RX queue of packets matching a "drop" filter in perfect mode. */ + pub drop_queue: u8, + pub mask: rte_eth_fdir_masks, + pub flex_conf: rte_eth_fdir_flex_conf, +} +#[test] +fn bindgen_test_layout_rte_fdir_conf() { + assert_eq!(::std::mem::size_of::<rte_fdir_conf>() , 772usize , concat ! ( + "Size of: " , stringify ! ( rte_fdir_conf ) )); + assert_eq! (::std::mem::align_of::<rte_fdir_conf>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( rte_fdir_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_fdir_conf ) ) . mode as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_fdir_conf ) , "::" + , stringify ! ( mode ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_fdir_conf ) ) . pballoc as * const _ + as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_fdir_conf ) , "::" + , stringify ! ( pballoc ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_fdir_conf ) ) . status as * const _ + as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_fdir_conf ) , "::" + , stringify ! ( status ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_fdir_conf ) ) . drop_queue as * const + _ as usize } , 12usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_fdir_conf ) , "::" + , stringify ! ( drop_queue ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_fdir_conf ) ) . mask as * const _ as + usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_fdir_conf ) , "::" + , stringify ! ( mask ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_fdir_conf ) ) . flex_conf as * const + _ as usize } , 84usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_fdir_conf ) , "::" + , stringify ! ( flex_conf ) )); +} +impl Clone for rte_fdir_conf { + fn clone(&self) -> Self { *self } +} +/** + * A structure used to enable/disable specific device interrupts. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_intr_conf { + /** enable/disable lsc interrupt. 0 (default) - disable, 1 enable */ + pub lsc: u16, + /** enable/disable rxq interrupt. 0 (default) - disable, 1 enable */ + pub rxq: u16, +} +#[test] +fn bindgen_test_layout_rte_intr_conf() { + assert_eq!(::std::mem::size_of::<rte_intr_conf>() , 4usize , concat ! ( + "Size of: " , stringify ! ( rte_intr_conf ) )); + assert_eq! (::std::mem::align_of::<rte_intr_conf>() , 2usize , concat ! ( + "Alignment of " , stringify ! ( rte_intr_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_intr_conf ) ) . lsc as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_intr_conf ) , "::" + , stringify ! ( lsc ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_intr_conf ) ) . rxq as * const _ as + usize } , 2usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_intr_conf ) , "::" + , stringify ! ( rxq ) )); +} +impl Clone for rte_intr_conf { + fn clone(&self) -> Self { *self } +} +/** + * A structure used to configure an Ethernet port. + * Depending upon the RX multi-queue mode, extra advanced + * configuration settings may be needed. + */ +#[repr(C)] +pub struct rte_eth_conf { + /**< bitmap of ETH_LINK_SPEED_XXX of speeds to be + used. ETH_LINK_SPEED_FIXED disables link + autonegotiation, and a unique speed shall be + set. Otherwise, the bitmap defines the set of + speeds to be advertised. If the special value + ETH_LINK_SPEED_AUTONEG (0) is used, all speeds + supported are advertised. */ + pub link_speeds: u32, + /**< Port RX configuration. */ + pub rxmode: rte_eth_rxmode, + /**< Port TX configuration. */ + pub txmode: rte_eth_txmode, + /**< Loopback operation mode. By default the value + is 0, meaning the loopback mode is disabled. + Read the datasheet of given ethernet controller + for details. The possible values of this field + are defined in implementation of each driver. */ + pub lpbk_mode: u32, + /**< Port RX filtering configuration (union). */ + pub rx_adv_conf: rte_eth_conf__bindgen_ty_1, + /**< Port TX DCB configuration (union). */ + pub tx_adv_conf: rte_eth_conf__bindgen_ty_2, + /** Currently,Priority Flow Control(PFC) are supported,if DCB with PFC + is needed,and the variable must be set ETH_DCB_PFC_SUPPORT. */ + pub dcb_capability_en: u32, + /**< FDIR configuration. */ + pub fdir_conf: rte_fdir_conf, + /**< Interrupt mode configuration. */ + pub intr_conf: rte_intr_conf, +} +#[repr(C)] +pub struct rte_eth_conf__bindgen_ty_1 { + /**< Port RSS configuration */ + pub rss_conf: rte_eth_rss_conf, + pub vmdq_dcb_conf: rte_eth_vmdq_dcb_conf, + pub dcb_rx_conf: rte_eth_dcb_rx_conf, + pub vmdq_rx_conf: rte_eth_vmdq_rx_conf, +} +#[test] +fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<rte_eth_conf__bindgen_ty_1>() , 2120usize + , concat ! ( + "Size of: " , stringify ! ( rte_eth_conf__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<rte_eth_conf__bindgen_ty_1>() , 8usize + , concat ! ( + "Alignment of " , stringify ! ( rte_eth_conf__bindgen_ty_1 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf__bindgen_ty_1 ) ) . rss_conf + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_conf__bindgen_ty_1 ) , "::" , stringify ! ( rss_conf ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf__bindgen_ty_1 ) ) . + vmdq_dcb_conf as * const _ as usize } , 24usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_conf__bindgen_ty_1 ) , "::" , stringify ! ( + vmdq_dcb_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf__bindgen_ty_1 ) ) . + dcb_rx_conf as * const _ as usize } , 1064usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_conf__bindgen_ty_1 ) , "::" , stringify ! ( + dcb_rx_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf__bindgen_ty_1 ) ) . + vmdq_rx_conf as * const _ as usize } , 1080usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_conf__bindgen_ty_1 ) , "::" , stringify ! ( + vmdq_rx_conf ) )); +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_eth_conf__bindgen_ty_2 { + pub vmdq_dcb_tx_conf: __BindgenUnionField<rte_eth_vmdq_dcb_tx_conf>, + pub dcb_tx_conf: __BindgenUnionField<rte_eth_dcb_tx_conf>, + pub vmdq_tx_conf: __BindgenUnionField<rte_eth_vmdq_tx_conf>, + pub bindgen_union_field: [u32; 3usize], +} +#[test] +fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { + assert_eq!(::std::mem::size_of::<rte_eth_conf__bindgen_ty_2>() , 12usize , + concat ! ( + "Size of: " , stringify ! ( rte_eth_conf__bindgen_ty_2 ) )); + assert_eq! (::std::mem::align_of::<rte_eth_conf__bindgen_ty_2>() , 4usize + , concat ! ( + "Alignment of " , stringify ! ( rte_eth_conf__bindgen_ty_2 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf__bindgen_ty_2 ) ) . + vmdq_dcb_tx_conf as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_conf__bindgen_ty_2 ) , "::" , stringify ! ( + vmdq_dcb_tx_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf__bindgen_ty_2 ) ) . + dcb_tx_conf as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_conf__bindgen_ty_2 ) , "::" , stringify ! ( + dcb_tx_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf__bindgen_ty_2 ) ) . + vmdq_tx_conf as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_eth_conf__bindgen_ty_2 ) , "::" , stringify ! ( + vmdq_tx_conf ) )); +} +impl Clone for rte_eth_conf__bindgen_ty_2 { + fn clone(&self) -> Self { *self } +} +#[test] +fn bindgen_test_layout_rte_eth_conf() { + assert_eq!(::std::mem::size_of::<rte_eth_conf>() , 2944usize , concat ! ( + "Size of: " , stringify ! ( rte_eth_conf ) )); + assert_eq! (::std::mem::align_of::<rte_eth_conf>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( rte_eth_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf ) ) . link_speeds as * const + _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" , + stringify ! ( link_speeds ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf ) ) . rxmode as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" , + stringify ! ( rxmode ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf ) ) . txmode as * const _ as + usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" , + stringify ! ( txmode ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf ) ) . lpbk_mode as * const _ + as usize } , 24usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" , + stringify ! ( lpbk_mode ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf ) ) . rx_adv_conf as * const + _ as usize } , 32usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" , + stringify ! ( rx_adv_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf ) ) . tx_adv_conf as * const + _ as usize } , 2152usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" , + stringify ! ( tx_adv_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf ) ) . dcb_capability_en as * + const _ as usize } , 2164usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" , + stringify ! ( dcb_capability_en ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf ) ) . fdir_conf as * const _ + as usize } , 2168usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" , + stringify ! ( fdir_conf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_eth_conf ) ) . intr_conf as * const _ + as usize } , 2940usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" , + stringify ! ( intr_conf ) )); +} diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs new file mode 100644 index 00000000..e0e3579a --- /dev/null +++ b/tests/expectations/tests/layout_kni_mbuf.rs @@ -0,0 +1,111 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +pub const RTE_CACHE_LINE_MIN_SIZE: ::std::os::raw::c_uint = 64; +pub const RTE_CACHE_LINE_SIZE: ::std::os::raw::c_uint = 64; +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_kni_mbuf { + pub buf_addr: *mut ::std::os::raw::c_void, + pub buf_physaddr: u64, + pub pad0: [::std::os::raw::c_char; 2usize], + /**< Start address of data in segment buffer. */ + pub data_off: u16, + pub pad1: [::std::os::raw::c_char; 2usize], + /**< Number of segments. */ + pub nb_segs: u8, + pub pad4: [::std::os::raw::c_char; 1usize], + /**< Offload features. */ + pub ol_flags: u64, + pub pad2: [::std::os::raw::c_char; 4usize], + /**< Total pkt len: sum of all segment data_len. */ + pub pkt_len: u32, + /**< Amount of data in segment buffer. */ + pub data_len: u16, + pub __bindgen_padding_0: [u8; 22usize], + pub pad3: [::std::os::raw::c_char; 8usize], + pub pool: *mut ::std::os::raw::c_void, + pub next: *mut ::std::os::raw::c_void, + pub __bindgen_padding_1: [u64; 5usize], +} +#[test] +fn bindgen_test_layout_rte_kni_mbuf() { + assert_eq!(::std::mem::size_of::<rte_kni_mbuf>() , 128usize , concat ! ( + "Size of: " , stringify ! ( rte_kni_mbuf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . buf_addr as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( buf_addr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . buf_physaddr as * + const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( buf_physaddr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . pad0 as * const _ as + usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( pad0 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . data_off as * const _ + as usize } , 18usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( data_off ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . pad1 as * const _ as + usize } , 20usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( pad1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . nb_segs as * const _ + as usize } , 22usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( nb_segs ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . pad4 as * const _ as + usize } , 23usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( pad4 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . ol_flags as * const _ + as usize } , 24usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( ol_flags ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . pad2 as * const _ as + usize } , 32usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( pad2 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . pkt_len as * const _ + as usize } , 36usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( pkt_len ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . data_len as * const _ + as usize } , 40usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( data_len ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . pad3 as * const _ as + usize } , 64usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( pad3 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . pool as * const _ as + usize } , 72usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( pool ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_kni_mbuf ) ) . next as * const _ as + usize } , 80usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_kni_mbuf ) , "::" , + stringify ! ( next ) )); +} +impl Clone for rte_kni_mbuf { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs new file mode 100644 index 00000000..f1702673 --- /dev/null +++ b/tests/expectations/tests/layout_mbuf.rs @@ -0,0 +1,733 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>); +impl <T> __BindgenUnionField<T> { + #[inline] + pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) } + #[inline] + pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { ::std::mem::transmute(self) } +} +impl <T> ::std::default::Default for __BindgenUnionField<T> { + #[inline] + fn default() -> Self { Self::new() } +} +impl <T> ::std::clone::Clone for __BindgenUnionField<T> { + #[inline] + fn clone(&self) -> Self { Self::new() } +} +impl <T> ::std::marker::Copy for __BindgenUnionField<T> { } +impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +pub const RTE_CACHE_LINE_MIN_SIZE: ::std::os::raw::c_uint = 64; +pub const RTE_CACHE_LINE_SIZE: ::std::os::raw::c_uint = 64; +pub type phys_addr_t = u64; +pub type MARKER = [*mut ::std::os::raw::c_void; 0usize]; +pub type MARKER8 = [u8; 0usize]; +pub type MARKER64 = [u64; 0usize]; +/** + * The atomic counter structure. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct _bindgen_ty_1 { + /**< An internal counter value. */ + pub cnt: i16, +} +#[test] +fn bindgen_test_layout__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<_bindgen_ty_1>() , 2usize , concat ! ( + "Size of: " , stringify ! ( _bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<_bindgen_ty_1>() , 2usize , concat ! ( + "Alignment of " , stringify ! ( _bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const _bindgen_ty_1 ) ) . cnt as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::" + , stringify ! ( cnt ) )); +} +impl Clone for _bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +pub type rte_atomic16_t = _bindgen_ty_1; +/** + * The generic rte_mbuf, containing a packet mbuf. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mbuf { + pub cacheline0: MARKER, + /**< Virtual address of segment buffer. */ + pub buf_addr: *mut ::std::os::raw::c_void, + /**< Physical address of segment buffer. */ + pub buf_physaddr: phys_addr_t, + /**< Length of segment buffer. */ + pub buf_len: u16, + pub rearm_data: MARKER8, + pub data_off: u16, + pub __bindgen_anon_1: rte_mbuf__bindgen_ty_1, + /**< Number of segments. */ + pub nb_segs: u8, + /**< Input port. */ + pub port: u8, + /**< Offload features. */ + pub ol_flags: u64, + pub rx_descriptor_fields1: MARKER, + pub __bindgen_anon_2: rte_mbuf__bindgen_ty_2, + /**< Total pkt len: sum of all segments. */ + pub pkt_len: u32, + /**< Amount of data in segment buffer. */ + pub data_len: u16, + /** VLAN TCI (CPU order), valid if PKT_RX_VLAN_STRIPPED is set. */ + pub vlan_tci: u16, + /**< hash information */ + pub hash: rte_mbuf__bindgen_ty_3, + /**< Sequence number. See also rte_reorder_insert() */ + pub seqn: u32, + /** Outer VLAN TCI (CPU order), valid if PKT_RX_QINQ_STRIPPED is set. */ + pub vlan_tci_outer: u16, + pub cacheline1: MARKER, + pub __bindgen_anon_3: rte_mbuf__bindgen_ty_4, + /**< Pool from which mbuf was allocated. */ + pub pool: *mut rte_mbuf_rte_mempool, + /**< Next segment of scattered packet. */ + pub next: *mut rte_mbuf, + pub __bindgen_anon_4: rte_mbuf__bindgen_ty_5, + /** Size of the application private data. In case of an indirect + * mbuf, it stores the direct mbuf private data size. */ + pub priv_size: u16, + /** Timesync flags for use with IEEE1588. */ + pub timesync: u16, + pub __bindgen_padding_0: [u32; 7usize], +} +/** + * 16-bit Reference counter. + * It should only be accessed using the following functions: + * rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and + * rte_mbuf_refcnt_set(). The functionality of these functions (atomic, + * or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC + * config option. + */ +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mbuf__bindgen_ty_1 { + /**< Atomically accessed refcnt */ + pub refcnt_atomic: __BindgenUnionField<rte_atomic16_t>, + /**< Non-atomically accessed refcnt */ + pub refcnt: __BindgenUnionField<u16>, + pub bindgen_union_field: u16, +} +#[test] +fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<rte_mbuf__bindgen_ty_1>() , 2usize , + concat ! ( "Size of: " , stringify ! ( rte_mbuf__bindgen_ty_1 ) + )); + assert_eq! (::std::mem::align_of::<rte_mbuf__bindgen_ty_1>() , 2usize , + concat ! ( + "Alignment of " , stringify ! ( rte_mbuf__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_1 ) ) . + refcnt_atomic as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf__bindgen_ty_1 + ) , "::" , stringify ! ( refcnt_atomic ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_1 ) ) . refcnt as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf__bindgen_ty_1 + ) , "::" , stringify ! ( refcnt ) )); +} +impl Clone for rte_mbuf__bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mbuf__bindgen_ty_2 { + /**< L2/L3/L4 and tunnel information. */ + pub packet_type: __BindgenUnionField<u32>, + pub __bindgen_anon_1: __BindgenUnionField<rte_mbuf__bindgen_ty_2__bindgen_ty_1>, + pub bindgen_union_field: u32, +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { + pub _bitfield_1: u32, +} +#[test] +fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<rte_mbuf__bindgen_ty_2__bindgen_ty_1>() , + 4usize , concat ! ( + "Size of: " , stringify ! ( + rte_mbuf__bindgen_ty_2__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<rte_mbuf__bindgen_ty_2__bindgen_ty_1>() + , 4usize , concat ! ( + "Alignment of " , stringify ! ( + rte_mbuf__bindgen_ty_2__bindgen_ty_1 ) )); +} +impl Clone for rte_mbuf__bindgen_ty_2__bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { + #[inline] + pub fn l2_type(&self) -> u32 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (15usize as u32)) >> + 0u32) as u32) + } + } + #[inline] + pub fn set_l2_type(&mut self, val: u32) { + self._bitfield_1 &= !(15usize as u32); + self._bitfield_1 |= ((val as u32 as u32) << 0u32) & (15usize as u32); + } + #[inline] + pub fn l3_type(&self) -> u32 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (240usize as u32)) >> + 4u32) as u32) + } + } + #[inline] + pub fn set_l3_type(&mut self, val: u32) { + self._bitfield_1 &= !(240usize as u32); + self._bitfield_1 |= ((val as u32 as u32) << 4u32) & (240usize as u32); + } + #[inline] + pub fn l4_type(&self) -> u32 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (3840usize as u32)) >> + 8u32) as u32) + } + } + #[inline] + pub fn set_l4_type(&mut self, val: u32) { + self._bitfield_1 &= !(3840usize as u32); + self._bitfield_1 |= + ((val as u32 as u32) << 8u32) & (3840usize as u32); + } + #[inline] + pub fn tun_type(&self) -> u32 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (61440usize as u32)) >> + 12u32) as u32) + } + } + #[inline] + pub fn set_tun_type(&mut self, val: u32) { + self._bitfield_1 &= !(61440usize as u32); + self._bitfield_1 |= + ((val as u32 as u32) << 12u32) & (61440usize as u32); + } + #[inline] + pub fn inner_l2_type(&self) -> u32 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (983040usize as u32)) + >> 16u32) as u32) + } + } + #[inline] + pub fn set_inner_l2_type(&mut self, val: u32) { + self._bitfield_1 &= !(983040usize as u32); + self._bitfield_1 |= + ((val as u32 as u32) << 16u32) & (983040usize as u32); + } + #[inline] + pub fn inner_l3_type(&self) -> u32 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (15728640usize as u32)) + >> 20u32) as u32) + } + } + #[inline] + pub fn set_inner_l3_type(&mut self, val: u32) { + self._bitfield_1 &= !(15728640usize as u32); + self._bitfield_1 |= + ((val as u32 as u32) << 20u32) & (15728640usize as u32); + } + #[inline] + pub fn inner_l4_type(&self) -> u32 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & + (251658240usize as u32)) >> 24u32) as + u32) + } + } + #[inline] + pub fn set_inner_l4_type(&mut self, val: u32) { + self._bitfield_1 &= !(251658240usize as u32); + self._bitfield_1 |= + ((val as u32 as u32) << 24u32) & (251658240usize as u32); + } +} +#[test] +fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { + assert_eq!(::std::mem::size_of::<rte_mbuf__bindgen_ty_2>() , 4usize , + concat ! ( "Size of: " , stringify ! ( rte_mbuf__bindgen_ty_2 ) + )); + assert_eq! (::std::mem::align_of::<rte_mbuf__bindgen_ty_2>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( rte_mbuf__bindgen_ty_2 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_2 ) ) . packet_type + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf__bindgen_ty_2 + ) , "::" , stringify ! ( packet_type ) )); +} +impl Clone for rte_mbuf__bindgen_ty_2 { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mbuf__bindgen_ty_3 { + /**< RSS hash result if RSS enabled */ + pub rss: __BindgenUnionField<u32>, + /**< Filter identifier if FDIR enabled */ + pub fdir: __BindgenUnionField<rte_mbuf__bindgen_ty_3__bindgen_ty_1>, + /**< Hierarchical scheduler */ + pub sched: __BindgenUnionField<rte_mbuf__bindgen_ty_3__bindgen_ty_2>, + /**< User defined tags. See rte_distributor_process() */ + pub usr: __BindgenUnionField<u32>, + pub bindgen_union_field: [u32; 2usize], +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1 { + pub __bindgen_anon_1: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, + pub hi: u32, +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { + pub __bindgen_anon_1: __BindgenUnionField<rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1>, + pub lo: __BindgenUnionField<u32>, + pub bindgen_union_field: u32, +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { + pub hash: u16, + pub id: u16, +} +#[test] +fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1>() + , 4usize , concat ! ( + "Size of: " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 + ) )); + assert_eq! (::std::mem::align_of::<rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1>() + , 2usize , concat ! ( + "Alignment of " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 + ) )); + assert_eq! (unsafe { + & ( + * ( + 0 as * const + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 + ) ) . hash as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 + ) , "::" , stringify ! ( hash ) )); + assert_eq! (unsafe { + & ( + * ( + 0 as * const + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 + ) ) . id as * const _ as usize } , 2usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 + ) , "::" , stringify ! ( id ) )); +} +impl Clone for + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +#[test] +fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1>() + , 4usize , concat ! ( + "Size of: " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1>() + , 4usize , concat ! ( + "Alignment of " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( + * ( + 0 as * const + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 ) ) . lo as + * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 ) , "::" , + stringify ! ( lo ) )); +} +impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +#[test] +fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<rte_mbuf__bindgen_ty_3__bindgen_ty_1>() , + 8usize , concat ! ( + "Size of: " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<rte_mbuf__bindgen_ty_3__bindgen_ty_1>() + , 4usize , concat ! ( + "Alignment of " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_3__bindgen_ty_1 ) ) + . hi as * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_1 ) , "::" , stringify ! ( + hi ) )); +} +impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { + pub lo: u32, + pub hi: u32, +} +#[test] +fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { + assert_eq!(::std::mem::size_of::<rte_mbuf__bindgen_ty_3__bindgen_ty_2>() , + 8usize , concat ! ( + "Size of: " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_2 ) )); + assert_eq! (::std::mem::align_of::<rte_mbuf__bindgen_ty_3__bindgen_ty_2>() + , 4usize , concat ! ( + "Alignment of " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_2 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_3__bindgen_ty_2 ) ) + . lo as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_2 ) , "::" , stringify ! ( + lo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_3__bindgen_ty_2 ) ) + . hi as * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( + rte_mbuf__bindgen_ty_3__bindgen_ty_2 ) , "::" , stringify ! ( + hi ) )); +} +impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { + fn clone(&self) -> Self { *self } +} +#[test] +fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { + assert_eq!(::std::mem::size_of::<rte_mbuf__bindgen_ty_3>() , 8usize , + concat ! ( "Size of: " , stringify ! ( rte_mbuf__bindgen_ty_3 ) + )); + assert_eq! (::std::mem::align_of::<rte_mbuf__bindgen_ty_3>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( rte_mbuf__bindgen_ty_3 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_3 ) ) . rss as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf__bindgen_ty_3 + ) , "::" , stringify ! ( rss ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_3 ) ) . fdir as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf__bindgen_ty_3 + ) , "::" , stringify ! ( fdir ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_3 ) ) . sched as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf__bindgen_ty_3 + ) , "::" , stringify ! ( sched ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_3 ) ) . usr as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf__bindgen_ty_3 + ) , "::" , stringify ! ( usr ) )); +} +impl Clone for rte_mbuf__bindgen_ty_3 { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mbuf__bindgen_ty_4 { + /**< Can be used for external metadata */ + pub userdata: __BindgenUnionField<*mut ::std::os::raw::c_void>, + /**< Allow 8-byte userdata on 32-bit */ + pub udata64: __BindgenUnionField<u64>, + pub bindgen_union_field: u64, +} +#[test] +fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { + assert_eq!(::std::mem::size_of::<rte_mbuf__bindgen_ty_4>() , 8usize , + concat ! ( "Size of: " , stringify ! ( rte_mbuf__bindgen_ty_4 ) + )); + assert_eq! (::std::mem::align_of::<rte_mbuf__bindgen_ty_4>() , 8usize , + concat ! ( + "Alignment of " , stringify ! ( rte_mbuf__bindgen_ty_4 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_4 ) ) . userdata as + * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf__bindgen_ty_4 + ) , "::" , stringify ! ( userdata ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_4 ) ) . udata64 as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf__bindgen_ty_4 + ) , "::" , stringify ! ( udata64 ) )); +} +impl Clone for rte_mbuf__bindgen_ty_4 { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct rte_mbuf_rte_mempool([u8; 0]); +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mbuf__bindgen_ty_5 { + /**< combined for easy fetch */ + pub tx_offload: __BindgenUnionField<u64>, + pub __bindgen_anon_1: __BindgenUnionField<rte_mbuf__bindgen_ty_5__bindgen_ty_1>, + pub bindgen_union_field: u64, +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { + pub _bitfield_1: u64, +} +#[test] +fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<rte_mbuf__bindgen_ty_5__bindgen_ty_1>() , + 8usize , concat ! ( + "Size of: " , stringify ! ( + rte_mbuf__bindgen_ty_5__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<rte_mbuf__bindgen_ty_5__bindgen_ty_1>() + , 8usize , concat ! ( + "Alignment of " , stringify ! ( + rte_mbuf__bindgen_ty_5__bindgen_ty_1 ) )); +} +impl Clone for rte_mbuf__bindgen_ty_5__bindgen_ty_1 { + fn clone(&self) -> Self { *self } +} +impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { + #[inline] + pub fn l2_len(&self) -> u64 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (127usize as u64)) >> + 0u32) as u64) + } + } + #[inline] + pub fn set_l2_len(&mut self, val: u64) { + self._bitfield_1 &= !(127usize as u64); + self._bitfield_1 |= ((val as u64 as u64) << 0u32) & (127usize as u64); + } + #[inline] + pub fn l3_len(&self) -> u64 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (65408usize as u64)) >> + 7u32) as u64) + } + } + #[inline] + pub fn set_l3_len(&mut self, val: u64) { + self._bitfield_1 &= !(65408usize as u64); + self._bitfield_1 |= + ((val as u64 as u64) << 7u32) & (65408usize as u64); + } + #[inline] + pub fn l4_len(&self) -> u64 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & (16711680usize as u64)) + >> 16u32) as u64) + } + } + #[inline] + pub fn set_l4_len(&mut self, val: u64) { + self._bitfield_1 &= !(16711680usize as u64); + self._bitfield_1 |= + ((val as u64 as u64) << 16u32) & (16711680usize as u64); + } + #[inline] + pub fn tso_segsz(&self) -> u64 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & + (1099494850560usize as u64)) >> 24u32) + as u64) + } + } + #[inline] + pub fn set_tso_segsz(&mut self, val: u64) { + self._bitfield_1 &= !(1099494850560usize as u64); + self._bitfield_1 |= + ((val as u64 as u64) << 24u32) & (1099494850560usize as u64); + } + #[inline] + pub fn outer_l3_len(&self) -> u64 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & + (561850441793536usize as u64)) >> + 40u32) as u64) + } + } + #[inline] + pub fn set_outer_l3_len(&mut self, val: u64) { + self._bitfield_1 &= !(561850441793536usize as u64); + self._bitfield_1 |= + ((val as u64 as u64) << 40u32) & (561850441793536usize as u64); + } + #[inline] + pub fn outer_l2_len(&self) -> u64 { + unsafe { + ::std::mem::transmute(((self._bitfield_1 & + (71494644084506624usize as u64)) >> + 49u32) as u64) + } + } + #[inline] + pub fn set_outer_l2_len(&mut self, val: u64) { + self._bitfield_1 &= !(71494644084506624usize as u64); + self._bitfield_1 |= + ((val as u64 as u64) << 49u32) & (71494644084506624usize as u64); + } +} +#[test] +fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { + assert_eq!(::std::mem::size_of::<rte_mbuf__bindgen_ty_5>() , 8usize , + concat ! ( "Size of: " , stringify ! ( rte_mbuf__bindgen_ty_5 ) + )); + assert_eq! (::std::mem::align_of::<rte_mbuf__bindgen_ty_5>() , 8usize , + concat ! ( + "Alignment of " , stringify ! ( rte_mbuf__bindgen_ty_5 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf__bindgen_ty_5 ) ) . tx_offload + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf__bindgen_ty_5 + ) , "::" , stringify ! ( tx_offload ) )); +} +impl Clone for rte_mbuf__bindgen_ty_5 { + fn clone(&self) -> Self { *self } +} +#[test] +fn bindgen_test_layout_rte_mbuf() { + assert_eq!(::std::mem::size_of::<rte_mbuf>() , 128usize , concat ! ( + "Size of: " , stringify ! ( rte_mbuf ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . cacheline0 as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( cacheline0 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . buf_addr as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( buf_addr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . buf_physaddr as * const _ + as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( buf_physaddr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . buf_len as * const _ as + usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( buf_len ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . rearm_data as * const _ as + usize } , 18usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( rearm_data ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . data_off as * const _ as + usize } , 18usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( data_off ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . nb_segs as * const _ as + usize } , 22usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( nb_segs ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . port as * const _ as usize + } , 23usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( port ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . ol_flags as * const _ as + usize } , 24usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( ol_flags ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . rx_descriptor_fields1 as * + const _ as usize } , 32usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( rx_descriptor_fields1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . pkt_len as * const _ as + usize } , 36usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( pkt_len ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . data_len as * const _ as + usize } , 40usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( data_len ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . vlan_tci as * const _ as + usize } , 42usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( vlan_tci ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . hash as * const _ as usize + } , 44usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( hash ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . seqn as * const _ as usize + } , 52usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( seqn ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . vlan_tci_outer as * const + _ as usize } , 56usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( vlan_tci_outer ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . cacheline1 as * const _ as + usize } , 64usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( cacheline1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . pool as * const _ as usize + } , 72usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( pool ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . next as * const _ as usize + } , 80usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( next ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . priv_size as * const _ as + usize } , 96usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( priv_size ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const rte_mbuf ) ) . timesync as * const _ as + usize } , 98usize , concat ! ( + "Alignment of field: " , stringify ! ( rte_mbuf ) , "::" , + stringify ! ( timesync ) )); +} +impl Clone for rte_mbuf { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/method-mangling.rs b/tests/expectations/tests/method-mangling.rs index 3b5107a8..94877dca 100644 --- a/tests/expectations/tests/method-mangling.rs +++ b/tests/expectations/tests/method-mangling.rs @@ -11,8 +11,10 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::<Foo>() , 1usize); - assert_eq!(::std::mem::align_of::<Foo>() , 1usize); + assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); } extern "C" { #[link_name = "_ZN3Foo4typeEv"] diff --git a/tests/expectations/tests/module-whitelisted.rs b/tests/expectations/tests/module-whitelisted.rs index 6f88c54b..cee91305 100644 --- a/tests/expectations/tests/module-whitelisted.rs +++ b/tests/expectations/tests/module-whitelisted.rs @@ -14,8 +14,10 @@ pub mod root { } #[test] fn bindgen_test_layout_Test() { - assert_eq!(::std::mem::size_of::<Test>() , 1usize); - assert_eq!(::std::mem::align_of::<Test>() , 1usize); + assert_eq!(::std::mem::size_of::<Test>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Test ) )); + assert_eq! (::std::mem::align_of::<Test>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Test ) )); } impl Clone for Test { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/msvc-no-usr.rs b/tests/expectations/tests/msvc-no-usr.rs index 8cab8cdc..842ca1f3 100644 --- a/tests/expectations/tests/msvc-no-usr.rs +++ b/tests/expectations/tests/msvc-no-usr.rs @@ -11,8 +11,15 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::<A>() , 8usize); - assert_eq!(::std::mem::align_of::<A>() , 8usize); + assert_eq!(::std::mem::size_of::<A>() , 8usize , concat ! ( + "Size of: " , stringify ! ( A ) )); + assert_eq! (::std::mem::align_of::<A>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( A ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const A ) ) . foo as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( A ) , "::" , stringify + ! ( foo ) )); } impl Clone for A { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs b/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs index 5e9cf522..008ed565 100644 --- a/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs +++ b/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs @@ -11,8 +11,10 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::<Foo>() , 1usize); - assert_eq!(::std::mem::align_of::<Foo>() , 1usize); + assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); } impl Clone for Foo { fn clone(&self) -> Self { *self } @@ -24,8 +26,10 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 1usize); - assert_eq!(::std::mem::align_of::<Bar>() , 1usize); + assert_eq!(::std::mem::size_of::<Bar>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); } impl Clone for Bar { fn clone(&self) -> Self { *self } @@ -37,8 +41,10 @@ pub struct Baz { } #[test] fn bindgen_test_layout_Baz() { - assert_eq!(::std::mem::size_of::<Baz>() , 1usize); - assert_eq!(::std::mem::align_of::<Baz>() , 1usize); + assert_eq!(::std::mem::size_of::<Baz>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Baz ) )); + assert_eq! (::std::mem::align_of::<Baz>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Baz ) )); } impl Clone for Baz { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/mutable.rs b/tests/expectations/tests/mutable.rs index 0d0d6ea3..82689ce1 100644 --- a/tests/expectations/tests/mutable.rs +++ b/tests/expectations/tests/mutable.rs @@ -12,8 +12,20 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::<C>() , 8usize); - assert_eq!(::std::mem::align_of::<C>() , 4usize); + assert_eq!(::std::mem::size_of::<C>() , 8usize , concat ! ( + "Size of: " , stringify ! ( C ) )); + assert_eq! (::std::mem::align_of::<C>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( C ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C ) ) . m_member as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( m_member ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C ) ) . m_other as * const _ as usize } , + 4usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( m_other ) )); } impl Clone for C { fn clone(&self) -> Self { *self } @@ -25,8 +37,15 @@ pub struct NonCopiable { } #[test] fn bindgen_test_layout_NonCopiable() { - assert_eq!(::std::mem::size_of::<NonCopiable>() , 4usize); - assert_eq!(::std::mem::align_of::<NonCopiable>() , 4usize); + assert_eq!(::std::mem::size_of::<NonCopiable>() , 4usize , concat ! ( + "Size of: " , stringify ! ( NonCopiable ) )); + assert_eq! (::std::mem::align_of::<NonCopiable>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( NonCopiable ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const NonCopiable ) ) . m_member as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( NonCopiable ) , "::" , + stringify ! ( m_member ) )); } #[repr(C)] #[derive(Debug)] @@ -36,7 +55,17 @@ pub struct NonCopiableWithNonCopiableMutableMember { #[test] fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { assert_eq!(::std::mem::size_of::<NonCopiableWithNonCopiableMutableMember>() - , 4usize); - assert_eq!(::std::mem::align_of::<NonCopiableWithNonCopiableMutableMember>() - , 4usize); + , 4usize , concat ! ( + "Size of: " , stringify ! ( + NonCopiableWithNonCopiableMutableMember ) )); + assert_eq! (::std::mem::align_of::<NonCopiableWithNonCopiableMutableMember>() + , 4usize , concat ! ( + "Alignment of " , stringify ! ( + NonCopiableWithNonCopiableMutableMember ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const NonCopiableWithNonCopiableMutableMember ) + ) . m_member as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + NonCopiableWithNonCopiableMutableMember ) , "::" , stringify ! + ( m_member ) )); } diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index ece4e341..4d27385d 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -34,8 +34,15 @@ pub mod root { } #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::<A>() , 4usize); - assert_eq!(::std::mem::align_of::<A>() , 4usize); + assert_eq!(::std::mem::size_of::<A>() , 4usize , concat ! ( + "Size of: " , stringify ! ( A ) )); + assert_eq! (::std::mem::align_of::<A>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( A ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const A ) ) . b as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( A ) , "::" , + stringify ! ( b ) )); } extern "C" { #[link_name = "_ZN12_GLOBAL__N_11A20lets_hope_this_worksEv"] diff --git a/tests/expectations/tests/nested.rs b/tests/expectations/tests/nested.rs index fdd435aa..4c119bc7 100644 --- a/tests/expectations/tests/nested.rs +++ b/tests/expectations/tests/nested.rs @@ -11,8 +11,15 @@ pub struct Calc { } #[test] fn bindgen_test_layout_Calc() { - assert_eq!(::std::mem::size_of::<Calc>() , 4usize); - assert_eq!(::std::mem::align_of::<Calc>() , 4usize); + assert_eq!(::std::mem::size_of::<Calc>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Calc ) )); + assert_eq! (::std::mem::align_of::<Calc>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Calc ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Calc ) ) . w as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Calc ) , "::" , + stringify ! ( w ) )); } impl Clone for Calc { fn clone(&self) -> Self { *self } @@ -35,24 +42,41 @@ pub struct Test_Size_Dimension { } #[test] fn bindgen_test_layout_Test_Size_Dimension() { - assert_eq!(::std::mem::size_of::<Test_Size_Dimension>() , 4usize); - assert_eq!(::std::mem::align_of::<Test_Size_Dimension>() , 4usize); + assert_eq!(::std::mem::size_of::<Test_Size_Dimension>() , 4usize , concat + ! ( "Size of: " , stringify ! ( Test_Size_Dimension ) )); + assert_eq! (::std::mem::align_of::<Test_Size_Dimension>() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( Test_Size_Dimension ) )); } impl Clone for Test_Size_Dimension { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_Test_Size() { - assert_eq!(::std::mem::size_of::<Test_Size>() , 8usize); - assert_eq!(::std::mem::align_of::<Test_Size>() , 4usize); + assert_eq!(::std::mem::size_of::<Test_Size>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Test_Size ) )); + assert_eq! (::std::mem::align_of::<Test_Size>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Test_Size ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test_Size ) ) . mWidth as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Test_Size ) , "::" , + stringify ! ( mWidth ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test_Size ) ) . mHeight as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( Test_Size ) , "::" , + stringify ! ( mHeight ) )); } impl Clone for Test_Size { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_Test() { - assert_eq!(::std::mem::size_of::<Test>() , 1usize); - assert_eq!(::std::mem::align_of::<Test>() , 1usize); + assert_eq!(::std::mem::size_of::<Test>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Test ) )); + assert_eq! (::std::mem::align_of::<Test>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Test ) )); } impl Clone for Test { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/nested_vtable.rs b/tests/expectations/tests/nested_vtable.rs index d74ad55f..7cc30423 100644 --- a/tests/expectations/tests/nested_vtable.rs +++ b/tests/expectations/tests/nested_vtable.rs @@ -14,8 +14,10 @@ pub struct nsISupports { } #[test] fn bindgen_test_layout_nsISupports() { - assert_eq!(::std::mem::size_of::<nsISupports>() , 8usize); - assert_eq!(::std::mem::align_of::<nsISupports>() , 8usize); + assert_eq!(::std::mem::size_of::<nsISupports>() , 8usize , concat ! ( + "Size of: " , stringify ! ( nsISupports ) )); + assert_eq! (::std::mem::align_of::<nsISupports>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( nsISupports ) )); } impl Clone for nsISupports { fn clone(&self) -> Self { *self } @@ -27,8 +29,10 @@ pub struct nsIRunnable { } #[test] fn bindgen_test_layout_nsIRunnable() { - assert_eq!(::std::mem::size_of::<nsIRunnable>() , 8usize); - assert_eq!(::std::mem::align_of::<nsIRunnable>() , 8usize); + assert_eq!(::std::mem::size_of::<nsIRunnable>() , 8usize , concat ! ( + "Size of: " , stringify ! ( nsIRunnable ) )); + assert_eq! (::std::mem::align_of::<nsIRunnable>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( nsIRunnable ) )); } impl Clone for nsIRunnable { fn clone(&self) -> Self { *self } @@ -40,8 +44,10 @@ pub struct Runnable { } #[test] fn bindgen_test_layout_Runnable() { - assert_eq!(::std::mem::size_of::<Runnable>() , 8usize); - assert_eq!(::std::mem::align_of::<Runnable>() , 8usize); + assert_eq!(::std::mem::size_of::<Runnable>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Runnable ) )); + assert_eq! (::std::mem::align_of::<Runnable>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( Runnable ) )); } impl Clone for Runnable { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/nested_within_namespace.rs b/tests/expectations/tests/nested_within_namespace.rs index 0c9c31ef..db4e0493 100644 --- a/tests/expectations/tests/nested_within_namespace.rs +++ b/tests/expectations/tests/nested_within_namespace.rs @@ -22,16 +22,30 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar_Baz() { - assert_eq!(::std::mem::size_of::<Bar_Baz>() , 4usize); - assert_eq!(::std::mem::align_of::<Bar_Baz>() , 4usize); + assert_eq!(::std::mem::size_of::<Bar_Baz>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Bar_Baz ) )); + assert_eq! (::std::mem::align_of::<Bar_Baz>() , 4usize , concat ! + ( "Alignment of " , stringify ! ( Bar_Baz ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Bar_Baz ) ) . foo as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Bar_Baz ) , + "::" , stringify ! ( foo ) )); } impl Clone for Bar_Baz { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 4usize); - assert_eq!(::std::mem::align_of::<Bar>() , 4usize); + assert_eq!(::std::mem::size_of::<Bar>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Bar ) ) . foo as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Bar ) , "::" , + stringify ! ( foo ) )); } impl Clone for Bar { fn clone(&self) -> Self { *self } @@ -43,8 +57,15 @@ pub mod root { } #[test] fn bindgen_test_layout_Baz() { - assert_eq!(::std::mem::size_of::<Baz>() , 4usize); - assert_eq!(::std::mem::align_of::<Baz>() , 4usize); + assert_eq!(::std::mem::size_of::<Baz>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Baz ) )); + assert_eq! (::std::mem::align_of::<Baz>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Baz ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Baz ) ) . baz as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Baz ) , "::" , + stringify ! ( baz ) )); } impl Clone for Baz { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/no-comments.rs b/tests/expectations/tests/no-comments.rs index 8a4371e7..c3bb13c4 100644 --- a/tests/expectations/tests/no-comments.rs +++ b/tests/expectations/tests/no-comments.rs @@ -11,8 +11,15 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::<Foo>() , 4usize); - assert_eq!(::std::mem::align_of::<Foo>() , 4usize); + assert_eq!(::std::mem::size_of::<Foo>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::<Foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Foo ) ) . s as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Foo ) , "::" , + stringify ! ( s ) )); } impl Clone for Foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs index e45b2678..4de75797 100644 --- a/tests/expectations/tests/no-derive-debug.rs +++ b/tests/expectations/tests/no-derive-debug.rs @@ -18,8 +18,20 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { - assert_eq!(::std::mem::size_of::<bar>() , 8usize); - assert_eq!(::std::mem::align_of::<bar>() , 4usize); + assert_eq!(::std::mem::size_of::<bar>() , 8usize , concat ! ( + "Size of: " , stringify ! ( bar ) )); + assert_eq! (::std::mem::align_of::<bar>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const bar ) ) . foo as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( bar ) , "::" , + stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const bar ) ) . baz as * const _ as usize } , + 4usize , concat ! ( + "Alignment of field: " , stringify ! ( bar ) , "::" , + stringify ! ( baz ) )); } impl Clone for bar { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/no-recursive-whitelisting.rs b/tests/expectations/tests/no-recursive-whitelisting.rs index 5bc21665..c8341990 100644 --- a/tests/expectations/tests/no-recursive-whitelisting.rs +++ b/tests/expectations/tests/no-recursive-whitelisting.rs @@ -12,8 +12,15 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!(::std::mem::size_of::<Foo>() , 8usize); - assert_eq!(::std::mem::align_of::<Foo>() , 8usize); + assert_eq!(::std::mem::size_of::<Foo>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::<Foo>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Foo ) ) . baz as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Foo ) , "::" , + stringify ! ( baz ) )); } impl Clone for Foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/no-std.rs b/tests/expectations/tests/no-std.rs index f50a889d..21cfda00 100644 --- a/tests/expectations/tests/no-std.rs +++ b/tests/expectations/tests/no-std.rs @@ -15,8 +15,25 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::core::mem::size_of::<foo>() , 16usize); - assert_eq!(::core::mem::align_of::<foo>() , 8usize); + assert_eq!(::core::mem::size_of::<foo>() , 16usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::core::mem::align_of::<foo>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . a as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . b as * const _ as usize } , + 4usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( b ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , + 8usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bar ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index 2d68ee50..544ced07 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -18,8 +18,15 @@ pub struct FooStruct { } #[test] fn bindgen_test_layout_FooStruct() { - assert_eq!(::std::mem::size_of::<FooStruct>() , 8usize); - assert_eq!(::std::mem::align_of::<FooStruct>() , 8usize); + assert_eq!(::std::mem::size_of::<FooStruct>() , 8usize , concat ! ( + "Size of: " , stringify ! ( FooStruct ) )); + assert_eq! (::std::mem::align_of::<FooStruct>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( FooStruct ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const FooStruct ) ) . foo as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( FooStruct ) , "::" , + stringify ! ( foo ) )); } impl Clone for FooStruct { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/objc_method.rs b/tests/expectations/tests/objc_method.rs index e2db24f6..d0342a21 100644 --- a/tests/expectations/tests/objc_method.rs +++ b/tests/expectations/tests/objc_method.rs @@ -11,7 +11,38 @@ extern crate objc; pub type id = *mut objc::runtime::Object; pub trait Foo { unsafe fn method(self); + unsafe fn methodWithInt_(self, foo: ::std::os::raw::c_int); + unsafe fn methodWithFoo_(self, foo: id); + unsafe fn methodReturningInt(self) + -> ::std::os::raw::c_int; + unsafe fn methodReturningFoo(self) + -> *mut id; + unsafe fn methodWithArg1_andArg2_andArg3_(self, + intvalue: ::std::os::raw::c_int, + ptr: + *mut ::std::os::raw::c_char, + floatvalue: f32); } impl Foo for id { unsafe fn method(self) { msg_send!(self , method) } + unsafe fn methodWithInt_(self, foo: ::std::os::raw::c_int) { + msg_send!(self , methodWithInt:foo ) + } + unsafe fn methodWithFoo_(self, foo: id) { + msg_send!(self , methodWithFoo:foo ) + } + unsafe fn methodReturningInt(self) -> ::std::os::raw::c_int { + msg_send!(self , methodReturningInt) + } + unsafe fn methodReturningFoo(self) -> *mut id { + msg_send!(self , methodReturningFoo) + } + unsafe fn methodWithArg1_andArg2_andArg3_(self, + intvalue: ::std::os::raw::c_int, + ptr: + *mut ::std::os::raw::c_char, + floatvalue: f32) { + msg_send!(self , + methodWithArg1:intvalue andArg2:ptr andArg3:floatvalue ) + } } diff --git a/tests/expectations/tests/only_bitfields.rs b/tests/expectations/tests/only_bitfields.rs index 68968826..7811584b 100644 --- a/tests/expectations/tests/only_bitfields.rs +++ b/tests/expectations/tests/only_bitfields.rs @@ -11,8 +11,10 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::<C>() , 1usize); - assert_eq!(::std::mem::align_of::<C>() , 1usize); + assert_eq!(::std::mem::size_of::<C>() , 1usize , concat ! ( + "Size of: " , stringify ! ( C ) )); + assert_eq! (::std::mem::align_of::<C>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( C ) )); } impl Clone for C { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/opaque-tracing.rs b/tests/expectations/tests/opaque-tracing.rs index 7dcc4eef..b19a1e68 100644 --- a/tests/expectations/tests/opaque-tracing.rs +++ b/tests/expectations/tests/opaque-tracing.rs @@ -11,8 +11,10 @@ pub struct Container { } #[test] fn bindgen_test_layout_Container() { - assert_eq!(::std::mem::size_of::<Container>() , 8usize); - assert_eq!(::std::mem::align_of::<Container>() , 4usize); + assert_eq!(::std::mem::size_of::<Container>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Container ) )); + assert_eq! (::std::mem::align_of::<Container>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Container ) )); } impl Clone for Container { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs index c94caa1f..cba5952e 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -12,8 +12,10 @@ pub struct opaque { } #[test] fn bindgen_test_layout_opaque() { - assert_eq!(::std::mem::size_of::<opaque>() , 4usize); - assert_eq!(::std::mem::align_of::<opaque>() , 4usize); + assert_eq!(::std::mem::size_of::<opaque>() , 4usize , concat ! ( + "Size of: " , stringify ! ( opaque ) )); + assert_eq! (::std::mem::align_of::<opaque>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( opaque ) )); } impl Clone for opaque { fn clone(&self) -> Self { *self } @@ -25,8 +27,15 @@ pub struct container { } #[test] fn bindgen_test_layout_container() { - assert_eq!(::std::mem::size_of::<container>() , 4usize); - assert_eq!(::std::mem::align_of::<container>() , 4usize); + assert_eq!(::std::mem::size_of::<container>() , 4usize , concat ! ( + "Size of: " , stringify ! ( container ) )); + assert_eq! (::std::mem::align_of::<container>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( container ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const container ) ) . contained as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( container ) , "::" , + stringify ! ( contained ) )); } impl Clone for container { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 118a1782..3cfa6d87 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -14,8 +14,10 @@ pub struct OtherOpaque { } #[test] fn bindgen_test_layout_OtherOpaque() { - assert_eq!(::std::mem::size_of::<OtherOpaque>() , 4usize); - assert_eq!(::std::mem::align_of::<OtherOpaque>() , 4usize); + assert_eq!(::std::mem::size_of::<OtherOpaque>() , 4usize , concat ! ( + "Size of: " , stringify ! ( OtherOpaque ) )); + assert_eq! (::std::mem::align_of::<OtherOpaque>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( OtherOpaque ) )); } impl Clone for OtherOpaque { fn clone(&self) -> Self { *self } @@ -37,8 +39,25 @@ pub struct WithOpaquePtr { } #[test] fn bindgen_test_layout_WithOpaquePtr() { - assert_eq!(::std::mem::size_of::<WithOpaquePtr>() , 16usize); - assert_eq!(::std::mem::align_of::<WithOpaquePtr>() , 8usize); + assert_eq!(::std::mem::size_of::<WithOpaquePtr>() , 16usize , concat ! ( + "Size of: " , stringify ! ( WithOpaquePtr ) )); + assert_eq! (::std::mem::align_of::<WithOpaquePtr>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( WithOpaquePtr ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithOpaquePtr ) ) . whatever as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WithOpaquePtr ) , "::" + , stringify ! ( whatever ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithOpaquePtr ) ) . other as * const _ as + usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( WithOpaquePtr ) , "::" + , stringify ! ( other ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithOpaquePtr ) ) . t as * const _ as + usize } , 12usize , concat ! ( + "Alignment of field: " , stringify ! ( WithOpaquePtr ) , "::" + , stringify ! ( t ) )); } impl Clone for WithOpaquePtr { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs index c4ac37d1..809e224a 100644 --- a/tests/expectations/tests/private.rs +++ b/tests/expectations/tests/private.rs @@ -13,8 +13,20 @@ pub struct HasPrivate { } #[test] fn bindgen_test_layout_HasPrivate() { - assert_eq!(::std::mem::size_of::<HasPrivate>() , 8usize); - assert_eq!(::std::mem::align_of::<HasPrivate>() , 4usize); + assert_eq!(::std::mem::size_of::<HasPrivate>() , 8usize , concat ! ( + "Size of: " , stringify ! ( HasPrivate ) )); + assert_eq! (::std::mem::align_of::<HasPrivate>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( HasPrivate ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const HasPrivate ) ) . mNotPrivate as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( HasPrivate ) , "::" , + stringify ! ( mNotPrivate ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const HasPrivate ) ) . mIsPrivate as * const _ + as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( HasPrivate ) , "::" , + stringify ! ( mIsPrivate ) )); } impl Clone for HasPrivate { fn clone(&self) -> Self { *self } @@ -28,8 +40,20 @@ pub struct VeryPrivate { } #[test] fn bindgen_test_layout_VeryPrivate() { - assert_eq!(::std::mem::size_of::<VeryPrivate>() , 8usize); - assert_eq!(::std::mem::align_of::<VeryPrivate>() , 4usize); + assert_eq!(::std::mem::size_of::<VeryPrivate>() , 8usize , concat ! ( + "Size of: " , stringify ! ( VeryPrivate ) )); + assert_eq! (::std::mem::align_of::<VeryPrivate>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( VeryPrivate ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const VeryPrivate ) ) . mIsPrivate as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( VeryPrivate ) , "::" , + stringify ! ( mIsPrivate ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const VeryPrivate ) ) . mIsAlsoPrivate as * + const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( VeryPrivate ) , "::" , + stringify ! ( mIsAlsoPrivate ) )); } impl Clone for VeryPrivate { fn clone(&self) -> Self { *self } @@ -44,8 +68,20 @@ pub struct ContradictPrivate { } #[test] fn bindgen_test_layout_ContradictPrivate() { - assert_eq!(::std::mem::size_of::<ContradictPrivate>() , 8usize); - assert_eq!(::std::mem::align_of::<ContradictPrivate>() , 4usize); + assert_eq!(::std::mem::size_of::<ContradictPrivate>() , 8usize , concat ! + ( "Size of: " , stringify ! ( ContradictPrivate ) )); + assert_eq! (::std::mem::align_of::<ContradictPrivate>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( ContradictPrivate ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ContradictPrivate ) ) . mNotPrivate as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( ContradictPrivate ) , + "::" , stringify ! ( mNotPrivate ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ContradictPrivate ) ) . mIsPrivate as * + const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( ContradictPrivate ) , + "::" , stringify ! ( mIsPrivate ) )); } impl Clone for ContradictPrivate { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/public-dtor.rs b/tests/expectations/tests/public-dtor.rs index 851857ee..d4c18c6b 100644 --- a/tests/expectations/tests/public-dtor.rs +++ b/tests/expectations/tests/public-dtor.rs @@ -11,6 +11,8 @@ pub struct cv_String { } #[test] fn bindgen_test_layout_cv_String() { - assert_eq!(::std::mem::size_of::<cv_String>() , 1usize); - assert_eq!(::std::mem::align_of::<cv_String>() , 1usize); + assert_eq!(::std::mem::size_of::<cv_String>() , 1usize , concat ! ( + "Size of: " , stringify ! ( cv_String ) )); + assert_eq! (::std::mem::align_of::<cv_String>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( cv_String ) )); } diff --git a/tests/expectations/tests/ref_argument_array.rs b/tests/expectations/tests/ref_argument_array.rs index c88492d7..675bbbca 100644 --- a/tests/expectations/tests/ref_argument_array.rs +++ b/tests/expectations/tests/ref_argument_array.rs @@ -15,8 +15,10 @@ pub struct nsID { } #[test] fn bindgen_test_layout_nsID() { - assert_eq!(::std::mem::size_of::<nsID>() , 8usize); - assert_eq!(::std::mem::align_of::<nsID>() , 8usize); + assert_eq!(::std::mem::size_of::<nsID>() , 8usize , concat ! ( + "Size of: " , stringify ! ( nsID ) )); + assert_eq! (::std::mem::align_of::<nsID>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( nsID ) )); } impl Clone for nsID { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs index 74ee229c..baeab03e 100644 --- a/tests/expectations/tests/reparented_replacement.rs +++ b/tests/expectations/tests/reparented_replacement.rs @@ -18,8 +18,15 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 4usize); - assert_eq!(::std::mem::align_of::<Bar>() , 4usize); + assert_eq!(::std::mem::size_of::<Bar>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Bar ) ) . bazz as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Bar ) , "::" , + stringify ! ( bazz ) )); } impl Clone for Bar { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index f4fee442..ed55080a 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -20,8 +20,15 @@ pub struct Test { } #[test] fn bindgen_test_layout_Test() { - assert_eq!(::std::mem::size_of::<Test>() , 4usize); - assert_eq!(::std::mem::align_of::<Test>() , 4usize); + assert_eq!(::std::mem::size_of::<Test>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Test ) )); + assert_eq! (::std::mem::align_of::<Test>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Test ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . a as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( a ) )); } impl Clone for Test { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index dbf93daa..4dde8266 100644 --- a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -15,8 +15,20 @@ pub struct JS_shadow_Zone { } #[test] fn bindgen_test_layout_JS_shadow_Zone() { - assert_eq!(::std::mem::size_of::<JS_shadow_Zone>() , 8usize); - assert_eq!(::std::mem::align_of::<JS_shadow_Zone>() , 4usize); + assert_eq!(::std::mem::size_of::<JS_shadow_Zone>() , 8usize , concat ! ( + "Size of: " , stringify ! ( JS_shadow_Zone ) )); + assert_eq! (::std::mem::align_of::<JS_shadow_Zone>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( JS_shadow_Zone ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const JS_shadow_Zone ) ) . x as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( JS_shadow_Zone ) , "::" + , stringify ! ( x ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const JS_shadow_Zone ) ) . y as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( JS_shadow_Zone ) , "::" + , stringify ! ( y ) )); } impl Clone for JS_shadow_Zone { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs index 78351ecc..87df768d 100644 --- a/tests/expectations/tests/size_t_template.rs +++ b/tests/expectations/tests/size_t_template.rs @@ -11,8 +11,15 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::<C>() , 12usize); - assert_eq!(::std::mem::align_of::<C>() , 4usize); + assert_eq!(::std::mem::size_of::<C>() , 12usize , concat ! ( + "Size of: " , stringify ! ( C ) )); + assert_eq! (::std::mem::align_of::<C>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( C ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C ) ) . arr as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( arr ) )); } impl Clone for C { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs index 388cc595..60f12262 100644 --- a/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -16,16 +16,30 @@ pub struct a_b { } #[test] fn bindgen_test_layout_a_b() { - assert_eq!(::std::mem::size_of::<a_b>() , 4usize); - assert_eq!(::std::mem::align_of::<a_b>() , 4usize); + assert_eq!(::std::mem::size_of::<a_b>() , 4usize , concat ! ( + "Size of: " , stringify ! ( a_b ) )); + assert_eq! (::std::mem::align_of::<a_b>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( a_b ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const a_b ) ) . val_b as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( a_b ) , "::" , + stringify ! ( val_b ) )); } impl Clone for a_b { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_a() { - assert_eq!(::std::mem::size_of::<a>() , 8usize); - assert_eq!(::std::mem::align_of::<a>() , 8usize); + assert_eq!(::std::mem::size_of::<a>() , 8usize , concat ! ( + "Size of: " , stringify ! ( a ) )); + assert_eq! (::std::mem::align_of::<a>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const a ) ) . val_a as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( a ) , "::" , stringify + ! ( val_a ) )); } impl Clone for a { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/struct_with_anon_struct.rs b/tests/expectations/tests/struct_with_anon_struct.rs index 1c49675d..75baf354 100644 --- a/tests/expectations/tests/struct_with_anon_struct.rs +++ b/tests/expectations/tests/struct_with_anon_struct.rs @@ -17,16 +17,35 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( b ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 8usize); - assert_eq!(::std::mem::align_of::<foo>() , 4usize); + assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bar ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/struct_with_anon_struct_array.rs b/tests/expectations/tests/struct_with_anon_struct_array.rs index 6e1c0315..f20f03d8 100644 --- a/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -18,8 +18,20 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( b ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } @@ -32,16 +44,40 @@ pub struct foo__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_2() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_2>() , 8usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_2>() , 4usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_2>() , 8usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_2 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_2>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_2 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_2 ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_2 ) , + "::" , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_2 ) ) . b as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_2 ) , + "::" , stringify ! ( b ) )); } impl Clone for foo__bindgen_ty_2 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 208usize); - assert_eq!(::std::mem::align_of::<foo>() , 4usize); + assert_eq!(::std::mem::size_of::<foo>() , 208usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . baz as * const _ as usize } , + 16usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( baz ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/tests/expectations/tests/struct_with_anon_struct_pointer.rs index aa77d4b6..087ff3d8 100644 --- a/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -17,16 +17,35 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( b ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 8usize); - assert_eq!(::std::mem::align_of::<foo>() , 8usize); + assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bar ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index 0d2e937a..ac4b6f75 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -42,16 +42,35 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( b ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 4usize); - assert_eq!(::std::mem::align_of::<foo>() , 4usize); + assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bar ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index 1b77fccc..982b3bdc 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -17,16 +17,30 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( b ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 8usize); - assert_eq!(::std::mem::align_of::<foo>() , 4usize); + assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 2914eb41..26edbceb 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -42,16 +42,30 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( b ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 4usize); - assert_eq!(::std::mem::align_of::<foo>() , 4usize); + assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index 3fb83a47..90f2fba2 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -14,8 +14,15 @@ pub struct bitfield { } #[test] fn bindgen_test_layout_bitfield() { - assert_eq!(::std::mem::size_of::<bitfield>() , 16usize); - assert_eq!(::std::mem::align_of::<bitfield>() , 4usize); + assert_eq!(::std::mem::size_of::<bitfield>() , 16usize , concat ! ( + "Size of: " , stringify ! ( bitfield ) )); + assert_eq! (::std::mem::align_of::<bitfield>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( bitfield ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const bitfield ) ) . e as * const _ as usize } + , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( bitfield ) , "::" , + stringify ! ( e ) )); } impl Clone for bitfield { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs index 52906a81..b81baa00 100644 --- a/tests/expectations/tests/struct_with_derive_debug.rs +++ b/tests/expectations/tests/struct_with_derive_debug.rs @@ -11,8 +11,15 @@ pub struct LittleArray { } #[test] fn bindgen_test_layout_LittleArray() { - assert_eq!(::std::mem::size_of::<LittleArray>() , 128usize); - assert_eq!(::std::mem::align_of::<LittleArray>() , 4usize); + assert_eq!(::std::mem::size_of::<LittleArray>() , 128usize , concat ! ( + "Size of: " , stringify ! ( LittleArray ) )); + assert_eq! (::std::mem::align_of::<LittleArray>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( LittleArray ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const LittleArray ) ) . a as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( LittleArray ) , "::" , + stringify ! ( a ) )); } impl Clone for LittleArray { fn clone(&self) -> Self { *self } @@ -23,8 +30,15 @@ pub struct BigArray { } #[test] fn bindgen_test_layout_BigArray() { - assert_eq!(::std::mem::size_of::<BigArray>() , 132usize); - assert_eq!(::std::mem::align_of::<BigArray>() , 4usize); + assert_eq!(::std::mem::size_of::<BigArray>() , 132usize , concat ! ( + "Size of: " , stringify ! ( BigArray ) )); + assert_eq! (::std::mem::align_of::<BigArray>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( BigArray ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const BigArray ) ) . a as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( BigArray ) , "::" , + stringify ! ( a ) )); } #[repr(C)] #[derive(Debug, Copy)] @@ -33,8 +47,15 @@ pub struct WithLittleArray { } #[test] fn bindgen_test_layout_WithLittleArray() { - assert_eq!(::std::mem::size_of::<WithLittleArray>() , 128usize); - assert_eq!(::std::mem::align_of::<WithLittleArray>() , 4usize); + assert_eq!(::std::mem::size_of::<WithLittleArray>() , 128usize , concat ! + ( "Size of: " , stringify ! ( WithLittleArray ) )); + assert_eq! (::std::mem::align_of::<WithLittleArray>() , 4usize , concat ! + ( "Alignment of " , stringify ! ( WithLittleArray ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithLittleArray ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WithLittleArray ) , + "::" , stringify ! ( a ) )); } impl Clone for WithLittleArray { fn clone(&self) -> Self { *self } @@ -45,6 +66,13 @@ pub struct WithBigArray { } #[test] fn bindgen_test_layout_WithBigArray() { - assert_eq!(::std::mem::size_of::<WithBigArray>() , 132usize); - assert_eq!(::std::mem::align_of::<WithBigArray>() , 4usize); + assert_eq!(::std::mem::size_of::<WithBigArray>() , 132usize , concat ! ( + "Size of: " , stringify ! ( WithBigArray ) )); + assert_eq! (::std::mem::align_of::<WithBigArray>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( WithBigArray ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithBigArray ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WithBigArray ) , "::" , + stringify ! ( a ) )); } diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index b3e0a5ca..4bd5586b 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -51,9 +51,25 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_1>() , - 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>() , - 2usize); + 4usize , concat ! ( + "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_1 ) + )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>() , + 2usize , concat ! ( + "Alignment of " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . c1 + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( c1 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . c2 + as * const _ as usize } , 2usize , concat ! ( + "Alignment of field: " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( c2 ) + )); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } @@ -69,25 +85,67 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_2>() , - 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>() , - 1usize); + 4usize , concat ! ( + "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_2 ) + )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>() , + 1usize , concat ! ( + "Alignment of " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_2 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d1 + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d1 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d2 + as * const _ as usize } , 1usize , concat ! ( + "Alignment of field: " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d2 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d3 + as * const _ as usize } , 2usize , concat ! ( + "Alignment of field: " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d3 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . d4 + as * const _ as usize } , 3usize , concat ! ( + "Alignment of field: " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( d4 ) + )); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( b ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 8usize); - assert_eq!(::std::mem::align_of::<foo>() , 4usize); + assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . a as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( a ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/struct_with_packing.rs b/tests/expectations/tests/struct_with_packing.rs index 93fc3f11..b7afdafe 100644 --- a/tests/expectations/tests/struct_with_packing.rs +++ b/tests/expectations/tests/struct_with_packing.rs @@ -12,8 +12,18 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { - assert_eq!(::std::mem::size_of::<a>() , 3usize); - assert_eq!(::std::mem::align_of::<a>() , 1usize); + assert_eq!(::std::mem::size_of::<a>() , 3usize , concat ! ( + "Size of: " , stringify ! ( a ) )); + assert_eq! (::std::mem::align_of::<a>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( a ) )); + assert_eq! (unsafe { & ( * ( 0 as * const a ) ) . b as * const _ as usize + } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( a ) , "::" , stringify + ! ( b ) )); + assert_eq! (unsafe { & ( * ( 0 as * const a ) ) . c as * const _ as usize + } , 1usize , concat ! ( + "Alignment of field: " , stringify ! ( a ) , "::" , stringify + ! ( c ) )); } impl Clone for a { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/struct_with_struct.rs b/tests/expectations/tests/struct_with_struct.rs index c8cdc927..d28806c4 100644 --- a/tests/expectations/tests/struct_with_struct.rs +++ b/tests/expectations/tests/struct_with_struct.rs @@ -17,16 +17,35 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . x as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( x ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . y as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( y ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 8usize); - assert_eq!(::std::mem::align_of::<foo>() , 4usize); + assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bar ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/template-fun-ty.rs b/tests/expectations/tests/template-fun-ty.rs new file mode 100644 index 00000000..c2a8a028 --- /dev/null +++ b/tests/expectations/tests/template-fun-ty.rs @@ -0,0 +1,31 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Foo<T> { + pub _address: u8, + pub _phantom_0: ::std::marker::PhantomData<T>, +} +pub type Foo_FunctionPtr<T> = + ::std::option::Option<unsafe extern "C" fn() -> T>; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct RefPtr<T> { + pub _address: u8, + pub _phantom_0: ::std::marker::PhantomData<T>, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct RefPtr_Proxy<T, R, Args> { + pub _address: u8, + pub _phantom_0: ::std::marker::PhantomData<T>, + pub _phantom_1: ::std::marker::PhantomData<R>, + pub _phantom_2: ::std::marker::PhantomData<Args>, +} +pub type RefPtr_Proxy_member_function<R, Args> = + ::std::option::Option<unsafe extern "C" fn(arg1: Args) -> R>; +pub type Returner<T> = ::std::option::Option<unsafe extern "C" fn() -> T>; diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 22e5a087..844dc6c2 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -44,8 +44,15 @@ pub struct RootedContainer { } #[test] fn bindgen_test_layout_RootedContainer() { - assert_eq!(::std::mem::size_of::<RootedContainer>() , 24usize); - assert_eq!(::std::mem::align_of::<RootedContainer>() , 8usize); + assert_eq!(::std::mem::size_of::<RootedContainer>() , 24usize , concat ! ( + "Size of: " , stringify ! ( RootedContainer ) )); + assert_eq! (::std::mem::align_of::<RootedContainer>() , 8usize , concat ! + ( "Alignment of " , stringify ! ( RootedContainer ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const RootedContainer ) ) . root as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( RootedContainer ) , + "::" , stringify ! ( root ) )); } impl Clone for RootedContainer { fn clone(&self) -> Self { *self } @@ -63,8 +70,15 @@ pub struct PODButContainsDtor { } #[test] fn bindgen_test_layout_PODButContainsDtor() { - assert_eq!(::std::mem::size_of::<PODButContainsDtor>() , 4usize); - assert_eq!(::std::mem::align_of::<PODButContainsDtor>() , 4usize); + assert_eq!(::std::mem::size_of::<PODButContainsDtor>() , 4usize , concat ! + ( "Size of: " , stringify ! ( PODButContainsDtor ) )); + assert_eq! (::std::mem::align_of::<PODButContainsDtor>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( PODButContainsDtor ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const PODButContainsDtor ) ) . member as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( PODButContainsDtor ) , + "::" , stringify ! ( member ) )); } /** <div rustbindgen opaque> */ #[repr(C)] @@ -79,8 +93,15 @@ pub struct POD { } #[test] fn bindgen_test_layout_POD() { - assert_eq!(::std::mem::size_of::<POD>() , 4usize); - assert_eq!(::std::mem::align_of::<POD>() , 4usize); + assert_eq!(::std::mem::size_of::<POD>() , 4usize , concat ! ( + "Size of: " , stringify ! ( POD ) )); + assert_eq! (::std::mem::align_of::<POD>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( POD ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const POD ) ) . opaque_member as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( POD ) , "::" , + stringify ! ( opaque_member ) )); } impl Clone for POD { fn clone(&self) -> Self { *self } @@ -118,8 +139,10 @@ pub struct Untemplated { } #[test] fn bindgen_test_layout_Untemplated() { - assert_eq!(::std::mem::size_of::<Untemplated>() , 1usize); - assert_eq!(::std::mem::align_of::<Untemplated>() , 1usize); + assert_eq!(::std::mem::size_of::<Untemplated>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Untemplated ) )); + assert_eq! (::std::mem::align_of::<Untemplated>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Untemplated ) )); } impl Clone for Untemplated { fn clone(&self) -> Self { *self } @@ -171,14 +194,22 @@ pub struct TemplateWithVar<T> { #[test] fn __bindgen_test_layout_template_1() { assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>() - , 24usize); + , 24usize , concat ! ( + "Size of template specialization: " , stringify ! ( + Foo<::std::os::raw::c_int, ::std::os::raw::c_int> ) )); assert_eq!(::std::mem::align_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>() - , 8usize); + , 8usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + Foo<::std::os::raw::c_int, ::std::os::raw::c_int> ) )); } #[test] fn __bindgen_test_layout_template_2() { assert_eq!(::std::mem::size_of::<WithDtor<::std::os::raw::c_int>>() , - 4usize); + 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( + WithDtor<::std::os::raw::c_int> ) )); assert_eq!(::std::mem::align_of::<WithDtor<::std::os::raw::c_int>>() , - 4usize); + 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + WithDtor<::std::os::raw::c_int> ) )); } diff --git a/tests/expectations/tests/type-referenced-by-whitelisted-function.rs b/tests/expectations/tests/type-referenced-by-whitelisted-function.rs index c9686501..f4201a56 100644 --- a/tests/expectations/tests/type-referenced-by-whitelisted-function.rs +++ b/tests/expectations/tests/type-referenced-by-whitelisted-function.rs @@ -11,8 +11,15 @@ pub struct dl_phdr_info { } #[test] fn bindgen_test_layout_dl_phdr_info() { - assert_eq!(::std::mem::size_of::<dl_phdr_info>() , 4usize); - assert_eq!(::std::mem::align_of::<dl_phdr_info>() , 4usize); + assert_eq!(::std::mem::size_of::<dl_phdr_info>() , 4usize , concat ! ( + "Size of: " , stringify ! ( dl_phdr_info ) )); + assert_eq! (::std::mem::align_of::<dl_phdr_info>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( dl_phdr_info ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const dl_phdr_info ) ) . x as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( dl_phdr_info ) , "::" , + stringify ! ( x ) )); } impl Clone for dl_phdr_info { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/type_alias_template_specialized.rs b/tests/expectations/tests/type_alias_template_specialized.rs index 11813bc6..5dd2038f 100644 --- a/tests/expectations/tests/type_alias_template_specialized.rs +++ b/tests/expectations/tests/type_alias_template_specialized.rs @@ -11,8 +11,15 @@ pub struct Rooted { } #[test] fn bindgen_test_layout_Rooted() { - assert_eq!(::std::mem::size_of::<Rooted>() , 4usize); - assert_eq!(::std::mem::align_of::<Rooted>() , 4usize); + assert_eq!(::std::mem::size_of::<Rooted>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Rooted ) )); + assert_eq! (::std::mem::align_of::<Rooted>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Rooted ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Rooted ) ) . ptr as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Rooted ) , "::" , + stringify ! ( ptr ) )); } impl Clone for Rooted { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index 1188393d..c199b7ab 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -35,8 +35,15 @@ pub struct nsFoo { } #[test] fn bindgen_test_layout_nsFoo() { - assert_eq!(::std::mem::size_of::<nsFoo>() , 8usize); - assert_eq!(::std::mem::align_of::<nsFoo>() , 8usize); + assert_eq!(::std::mem::size_of::<nsFoo>() , 8usize , concat ! ( + "Size of: " , stringify ! ( nsFoo ) )); + assert_eq! (::std::mem::align_of::<nsFoo>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( nsFoo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const nsFoo ) ) . mBar as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( nsFoo ) , "::" , + stringify ! ( mBar ) )); } impl Clone for nsFoo { fn clone(&self) -> Self { *self } @@ -48,8 +55,17 @@ pub struct mozilla_FragmentOrURL { } #[test] fn bindgen_test_layout_mozilla_FragmentOrURL() { - assert_eq!(::std::mem::size_of::<mozilla_FragmentOrURL>() , 1usize); - assert_eq!(::std::mem::align_of::<mozilla_FragmentOrURL>() , 1usize); + assert_eq!(::std::mem::size_of::<mozilla_FragmentOrURL>() , 1usize , + concat ! ( "Size of: " , stringify ! ( mozilla_FragmentOrURL ) + )); + assert_eq! (::std::mem::align_of::<mozilla_FragmentOrURL>() , 1usize , + concat ! ( + "Alignment of " , stringify ! ( mozilla_FragmentOrURL ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const mozilla_FragmentOrURL ) ) . mIsLocalRef + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( mozilla_FragmentOrURL ) + , "::" , stringify ! ( mIsLocalRef ) )); } impl Clone for mozilla_FragmentOrURL { fn clone(&self) -> Self { *self } @@ -61,8 +77,10 @@ pub struct mozilla_Position { } #[test] fn bindgen_test_layout_mozilla_Position() { - assert_eq!(::std::mem::size_of::<mozilla_Position>() , 1usize); - assert_eq!(::std::mem::align_of::<mozilla_Position>() , 1usize); + assert_eq!(::std::mem::size_of::<mozilla_Position>() , 1usize , concat ! ( + "Size of: " , stringify ! ( mozilla_Position ) )); + assert_eq! (::std::mem::align_of::<mozilla_Position>() , 1usize , concat ! + ( "Alignment of " , stringify ! ( mozilla_Position ) )); } impl Clone for mozilla_Position { fn clone(&self) -> Self { *self } @@ -88,8 +106,15 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 8usize); - assert_eq!(::std::mem::align_of::<Bar>() , 8usize); + assert_eq!(::std::mem::size_of::<Bar>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Bar ) ) . mFoo as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Bar ) , "::" , + stringify ! ( mFoo ) )); } impl Clone for Bar { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index fa511e51..cb69d603 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -43,8 +43,15 @@ pub mod root { } #[test] fn bindgen_test_layout_bar() { - assert_eq!(::std::mem::size_of::<bar>() , 4usize); - assert_eq!(::std::mem::align_of::<bar>() , 4usize); + assert_eq!(::std::mem::size_of::<bar>() , 4usize , concat ! ( + "Size of: " , stringify ! ( bar ) )); + assert_eq! (::std::mem::align_of::<bar>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const bar ) ) . baz as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( bar ) , "::" , + stringify ! ( baz ) )); } impl Clone for bar { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index 9be626ff..ad707b63 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -37,6 +37,18 @@ pub struct UnionWithDtor { } #[test] fn bindgen_test_layout_UnionWithDtor() { - assert_eq!(::std::mem::size_of::<UnionWithDtor>() , 8usize); - assert_eq!(::std::mem::align_of::<UnionWithDtor>() , 8usize); + assert_eq!(::std::mem::size_of::<UnionWithDtor>() , 8usize , concat ! ( + "Size of: " , stringify ! ( UnionWithDtor ) )); + assert_eq! (::std::mem::align_of::<UnionWithDtor>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( UnionWithDtor ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const UnionWithDtor ) ) . mFoo as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( UnionWithDtor ) , "::" + , stringify ! ( mFoo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const UnionWithDtor ) ) . mBar as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( UnionWithDtor ) , "::" + , stringify ! ( mBar ) )); } diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index 495e80f9..64eb3fe4 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -38,8 +38,25 @@ pub struct _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<_bindgen_ty_1>() , 8usize); - assert_eq!(::std::mem::align_of::<_bindgen_ty_1>() , 8usize); + assert_eq!(::std::mem::size_of::<_bindgen_ty_1>() , 8usize , concat ! ( + "Size of: " , stringify ! ( _bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<_bindgen_ty_1>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( _bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const _bindgen_ty_1 ) ) . mInt as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::" + , stringify ! ( mInt ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const _bindgen_ty_1 ) ) . mFloat as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::" + , stringify ! ( mFloat ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const _bindgen_ty_1 ) ) . mPointer as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::" + , stringify ! ( mPointer ) )); } impl Clone for _bindgen_ty_1 { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index f0a21512..4b9c635f 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -42,16 +42,35 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 8usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as + usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( b ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 8usize); - assert_eq!(::std::mem::align_of::<foo>() , 4usize); + assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bar ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 548b0dc4..449fd440 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -42,8 +42,10 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } @@ -78,8 +80,15 @@ impl foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 4usize); - assert_eq!(::std::mem::align_of::<foo>() , 4usize); + assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . a as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( a ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index 95278556..16b33551 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -43,16 +43,35 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 4usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( b ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 4usize); - assert_eq!(::std::mem::align_of::<foo>() , 4usize); + assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bar ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 2d6fab97..7982728a 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -45,16 +45,46 @@ pub struct pixel__bindgen_ty_1 { } #[test] fn bindgen_test_layout_pixel__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<pixel__bindgen_ty_1>() , 4usize); - assert_eq!(::std::mem::align_of::<pixel__bindgen_ty_1>() , 1usize); + assert_eq!(::std::mem::size_of::<pixel__bindgen_ty_1>() , 4usize , concat + ! ( "Size of: " , stringify ! ( pixel__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<pixel__bindgen_ty_1>() , 1usize , + concat ! ( + "Alignment of " , stringify ! ( pixel__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . r as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) , + "::" , stringify ! ( r ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . g as * const _ + as usize } , 1usize , concat ! ( + "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) , + "::" , stringify ! ( g ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . b as * const _ + as usize } , 2usize , concat ! ( + "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) , + "::" , stringify ! ( b ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const pixel__bindgen_ty_1 ) ) . a as * const _ + as usize } , 3usize , concat ! ( + "Alignment of field: " , stringify ! ( pixel__bindgen_ty_1 ) , + "::" , stringify ! ( a ) )); } impl Clone for pixel__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_pixel() { - assert_eq!(::std::mem::size_of::<pixel>() , 4usize); - assert_eq!(::std::mem::align_of::<pixel>() , 4usize); + assert_eq!(::std::mem::size_of::<pixel>() , 4usize , concat ! ( + "Size of: " , stringify ! ( pixel ) )); + assert_eq! (::std::mem::align_of::<pixel>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( pixel ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const pixel ) ) . rgba as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( pixel ) , "::" , + stringify ! ( rgba ) )); } impl Clone for pixel { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index eb214017..1e7f918c 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -44,16 +44,35 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 2usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 2usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 2usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 2usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . b as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( b ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1 ) ) . c as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo__bindgen_ty_1 ) , + "::" , stringify ! ( c ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 4usize); - assert_eq!(::std::mem::align_of::<foo>() , 4usize); + assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . a as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( a ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index b921f33c..58407cdb 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -37,8 +37,20 @@ pub struct WithBigArray { } #[test] fn bindgen_test_layout_WithBigArray() { - assert_eq!(::std::mem::size_of::<WithBigArray>() , 132usize); - assert_eq!(::std::mem::align_of::<WithBigArray>() , 4usize); + assert_eq!(::std::mem::size_of::<WithBigArray>() , 132usize , concat ! ( + "Size of: " , stringify ! ( WithBigArray ) )); + assert_eq! (::std::mem::align_of::<WithBigArray>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( WithBigArray ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithBigArray ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WithBigArray ) , "::" , + stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithBigArray ) ) . b as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WithBigArray ) , "::" , + stringify ! ( b ) )); } impl Clone for WithBigArray { fn clone(&self) -> Self { *self } @@ -52,8 +64,20 @@ pub struct WithBigArray2 { } #[test] fn bindgen_test_layout_WithBigArray2() { - assert_eq!(::std::mem::size_of::<WithBigArray2>() , 36usize); - assert_eq!(::std::mem::align_of::<WithBigArray2>() , 4usize); + assert_eq!(::std::mem::size_of::<WithBigArray2>() , 36usize , concat ! ( + "Size of: " , stringify ! ( WithBigArray2 ) )); + assert_eq! (::std::mem::align_of::<WithBigArray2>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( WithBigArray2 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithBigArray2 ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WithBigArray2 ) , "::" + , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithBigArray2 ) ) . b as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WithBigArray2 ) , "::" + , stringify ! ( b ) )); } impl Clone for WithBigArray2 { fn clone(&self) -> Self { *self } @@ -67,8 +91,20 @@ pub struct WithBigMember { } #[test] fn bindgen_test_layout_WithBigMember() { - assert_eq!(::std::mem::size_of::<WithBigMember>() , 132usize); - assert_eq!(::std::mem::align_of::<WithBigMember>() , 4usize); + assert_eq!(::std::mem::size_of::<WithBigMember>() , 132usize , concat ! ( + "Size of: " , stringify ! ( WithBigMember ) )); + assert_eq! (::std::mem::align_of::<WithBigMember>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( WithBigMember ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithBigMember ) ) . a as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WithBigMember ) , "::" + , stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const WithBigMember ) ) . b as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( WithBigMember ) , "::" + , stringify ! ( b ) )); } impl Clone for WithBigMember { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index af9e442d..17c3c8f0 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -51,9 +51,25 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_1>() , - 2usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>() , - 2usize); + 2usize , concat ! ( + "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_1 ) + )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>() , + 2usize , concat ! ( + "Alignment of " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . b1 + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( b1 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_1 ) ) . b2 + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( b2 ) + )); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } @@ -68,25 +84,50 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_2>() , - 2usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>() , - 2usize); + 2usize , concat ! ( + "Size of: " , stringify ! ( foo__bindgen_ty_1__bindgen_ty_2 ) + )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>() , + 2usize , concat ! ( + "Alignment of " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_2 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . c1 + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( c1 ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo__bindgen_ty_1__bindgen_ty_2 ) ) . c2 + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + foo__bindgen_ty_1__bindgen_ty_2 ) , "::" , stringify ! ( c2 ) + )); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1>() , 2usize); + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1>() , 4usize , concat ! + ( "Size of: " , stringify ! ( foo__bindgen_ty_1 ) )); + assert_eq! (::std::mem::align_of::<foo__bindgen_ty_1>() , 2usize , concat + ! ( "Alignment of " , stringify ! ( foo__bindgen_ty_1 ) )); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 4usize); - assert_eq!(::std::mem::align_of::<foo>() , 4usize); + assert_eq!(::std::mem::size_of::<foo>() , 4usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . a as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( a ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/unknown_attr.rs b/tests/expectations/tests/unknown_attr.rs index fd9cce45..12a35760 100644 --- a/tests/expectations/tests/unknown_attr.rs +++ b/tests/expectations/tests/unknown_attr.rs @@ -8,7 +8,26 @@ #[derive(Debug, Copy)] pub struct _bindgen_ty_1 { pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, + pub __bindgen_padding_0: u64, pub __clang_max_align_nonce2: f64, + pub __bindgen_padding_1: u64, +} +#[test] +fn bindgen_test_layout__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<_bindgen_ty_1>() , 32usize , concat ! ( + "Size of: " , stringify ! ( _bindgen_ty_1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const _bindgen_ty_1 ) ) . + __clang_max_align_nonce1 as * const _ as usize } , 0usize , + concat ! ( + "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::" + , stringify ! ( __clang_max_align_nonce1 ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const _bindgen_ty_1 ) ) . + __clang_max_align_nonce2 as * const _ as usize } , 16usize , + concat ! ( + "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::" + , stringify ! ( __clang_max_align_nonce2 ) )); } impl Clone for _bindgen_ty_1 { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index b0900f5f..f09d1519 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -14,8 +14,25 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::core::mem::size_of::<foo>() , 16usize); - assert_eq!(::core::mem::align_of::<foo>() , 8usize); + assert_eq!(::core::mem::size_of::<foo>() , 16usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::core::mem::align_of::<foo>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . a as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( a ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . b as * const _ as usize } , + 4usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( b ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . bar as * const _ as usize } , + 8usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( bar ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/var-tracing.rs b/tests/expectations/tests/var-tracing.rs index ef5660eb..7a09bcb6 100644 --- a/tests/expectations/tests/var-tracing.rs +++ b/tests/expectations/tests/var-tracing.rs @@ -11,8 +11,15 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 4usize); - assert_eq!(::std::mem::align_of::<Bar>() , 4usize); + assert_eq!(::std::mem::size_of::<Bar>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Bar ) ) . m_baz as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Bar ) , "::" , + stringify ! ( m_baz ) )); } extern "C" { #[link_name = "_ZN3BarC1Ei"] @@ -40,8 +47,10 @@ extern "C" { } #[test] fn bindgen_test_layout_Baz() { - assert_eq!(::std::mem::size_of::<Baz>() , 1usize); - assert_eq!(::std::mem::align_of::<Baz>() , 1usize); + assert_eq!(::std::mem::size_of::<Baz>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Baz ) )); + assert_eq! (::std::mem::align_of::<Baz>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Baz ) )); } impl Clone for Baz { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/variadic-method.rs b/tests/expectations/tests/variadic-method.rs index 34301069..45155128 100644 --- a/tests/expectations/tests/variadic-method.rs +++ b/tests/expectations/tests/variadic-method.rs @@ -15,8 +15,10 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 1usize); - assert_eq!(::std::mem::align_of::<Bar>() , 1usize); + assert_eq!(::std::mem::size_of::<Bar>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Bar ) )); + assert_eq! (::std::mem::align_of::<Bar>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Bar ) )); } extern "C" { #[link_name = "_ZN3Bar3fooEPKcz"] diff --git a/tests/expectations/tests/vector.rs b/tests/expectations/tests/vector.rs index b8ca5735..4b689744 100644 --- a/tests/expectations/tests/vector.rs +++ b/tests/expectations/tests/vector.rs @@ -11,8 +11,15 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::<foo>() , 8usize); - assert_eq!(::std::mem::align_of::<foo>() , 8usize); + assert_eq!(::std::mem::size_of::<foo>() , 8usize , concat ! ( + "Size of: " , stringify ! ( foo ) )); + assert_eq! (::std::mem::align_of::<foo>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( foo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const foo ) ) . mMember as * const _ as usize } + , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( foo ) , "::" , + stringify ! ( mMember ) )); } impl Clone for foo { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/virtual_dtor.rs b/tests/expectations/tests/virtual_dtor.rs index 9571f084..de5e01af 100644 --- a/tests/expectations/tests/virtual_dtor.rs +++ b/tests/expectations/tests/virtual_dtor.rs @@ -14,6 +14,8 @@ pub struct nsSlots { } #[test] fn bindgen_test_layout_nsSlots() { - assert_eq!(::std::mem::size_of::<nsSlots>() , 8usize); - assert_eq!(::std::mem::align_of::<nsSlots>() , 8usize); + assert_eq!(::std::mem::size_of::<nsSlots>() , 8usize , concat ! ( + "Size of: " , stringify ! ( nsSlots ) )); + assert_eq! (::std::mem::align_of::<nsSlots>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( nsSlots ) )); } diff --git a/tests/expectations/tests/virtual_inheritance.rs b/tests/expectations/tests/virtual_inheritance.rs index f271223f..e0510730 100644 --- a/tests/expectations/tests/virtual_inheritance.rs +++ b/tests/expectations/tests/virtual_inheritance.rs @@ -11,8 +11,15 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::<A>() , 4usize); - assert_eq!(::std::mem::align_of::<A>() , 4usize); + assert_eq!(::std::mem::size_of::<A>() , 4usize , concat ! ( + "Size of: " , stringify ! ( A ) )); + assert_eq! (::std::mem::align_of::<A>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( A ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const A ) ) . foo as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( A ) , "::" , stringify + ! ( foo ) )); } impl Clone for A { fn clone(&self) -> Self { *self } @@ -28,8 +35,15 @@ pub struct B { } #[test] fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::<B>() , 16usize); - assert_eq!(::std::mem::align_of::<B>() , 8usize); + assert_eq!(::std::mem::size_of::<B>() , 16usize , concat ! ( + "Size of: " , stringify ! ( B ) )); + assert_eq! (::std::mem::align_of::<B>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( B ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const B ) ) . bar as * const _ as usize } , + 8usize , concat ! ( + "Alignment of field: " , stringify ! ( B ) , "::" , stringify + ! ( bar ) )); } impl Clone for B { fn clone(&self) -> Self { *self } @@ -45,8 +59,15 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::<C>() , 16usize); - assert_eq!(::std::mem::align_of::<C>() , 8usize); + assert_eq!(::std::mem::size_of::<C>() , 16usize , concat ! ( + "Size of: " , stringify ! ( C ) )); + assert_eq! (::std::mem::align_of::<C>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( C ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const C ) ) . baz as * const _ as usize } , + 8usize , concat ! ( + "Alignment of field: " , stringify ! ( C ) , "::" , stringify + ! ( baz ) )); } impl Clone for C { fn clone(&self) -> Self { *self } @@ -60,8 +81,10 @@ pub struct D { } #[test] fn bindgen_test_layout_D() { - assert_eq!(::std::mem::size_of::<D>() , 40usize); - assert_eq!(::std::mem::align_of::<D>() , 8usize); + assert_eq!(::std::mem::size_of::<D>() , 40usize , concat ! ( + "Size of: " , stringify ! ( D ) )); + assert_eq! (::std::mem::align_of::<D>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( D ) )); } impl Clone for D { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/virtual_overloaded.rs b/tests/expectations/tests/virtual_overloaded.rs index 7833cdbf..9937cf5d 100644 --- a/tests/expectations/tests/virtual_overloaded.rs +++ b/tests/expectations/tests/virtual_overloaded.rs @@ -14,8 +14,10 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::<C>() , 8usize); - assert_eq!(::std::mem::align_of::<C>() , 8usize); + assert_eq!(::std::mem::size_of::<C>() , 8usize , concat ! ( + "Size of: " , stringify ! ( C ) )); + assert_eq! (::std::mem::align_of::<C>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( C ) )); } impl Clone for C { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/vtable_recursive_sig.rs b/tests/expectations/tests/vtable_recursive_sig.rs index ce62eeb0..6cf3135f 100644 --- a/tests/expectations/tests/vtable_recursive_sig.rs +++ b/tests/expectations/tests/vtable_recursive_sig.rs @@ -11,8 +11,10 @@ pub struct Derived { } #[test] fn bindgen_test_layout_Derived() { - assert_eq!(::std::mem::size_of::<Derived>() , 8usize); - assert_eq!(::std::mem::align_of::<Derived>() , 8usize); + assert_eq!(::std::mem::size_of::<Derived>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Derived ) )); + assert_eq! (::std::mem::align_of::<Derived>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( Derived ) )); } impl Clone for Derived { fn clone(&self) -> Self { *self } @@ -27,8 +29,10 @@ pub struct Base { } #[test] fn bindgen_test_layout_Base() { - assert_eq!(::std::mem::size_of::<Base>() , 8usize); - assert_eq!(::std::mem::align_of::<Base>() , 8usize); + assert_eq!(::std::mem::size_of::<Base>() , 8usize , concat ! ( + "Size of: " , stringify ! ( Base ) )); + assert_eq! (::std::mem::align_of::<Base>() , 8usize , concat ! ( + "Alignment of " , stringify ! ( Base ) )); } impl Clone for Base { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index 56ee76a5..98765b09 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -31,8 +31,70 @@ pub struct Weird { } #[test] fn bindgen_test_layout_Weird() { - assert_eq!(::std::mem::size_of::<Weird>() , 24usize); - assert_eq!(::std::mem::align_of::<Weird>() , 4usize); + assert_eq!(::std::mem::size_of::<Weird>() , 24usize , concat ! ( + "Size of: " , stringify ! ( Weird ) )); + assert_eq! (::std::mem::align_of::<Weird>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Weird ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Weird ) ) . mStrokeDasharrayLength as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Weird ) , "::" , + stringify ! ( mStrokeDasharrayLength ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Weird ) ) . mClipRule as * const _ as + usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( Weird ) , "::" , + stringify ! ( mClipRule ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Weird ) ) . mColorInterpolation as * + const _ as usize } , 9usize , concat ! ( + "Alignment of field: " , stringify ! ( Weird ) , "::" , + stringify ! ( mColorInterpolation ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Weird ) ) . mColorInterpolationFilters as + * const _ as usize } , 10usize , concat ! ( + "Alignment of field: " , stringify ! ( Weird ) , "::" , + stringify ! ( mColorInterpolationFilters ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Weird ) ) . mFillRule as * const _ as + usize } , 11usize , concat ! ( + "Alignment of field: " , stringify ! ( Weird ) , "::" , + stringify ! ( mFillRule ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Weird ) ) . mImageRendering as * const _ + as usize } , 12usize , concat ! ( + "Alignment of field: " , stringify ! ( Weird ) , "::" , + stringify ! ( mImageRendering ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Weird ) ) . mPaintOrder as * const _ as + usize } , 13usize , concat ! ( + "Alignment of field: " , stringify ! ( Weird ) , "::" , + stringify ! ( mPaintOrder ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Weird ) ) . mShapeRendering as * const _ + as usize } , 14usize , concat ! ( + "Alignment of field: " , stringify ! ( Weird ) , "::" , + stringify ! ( mShapeRendering ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Weird ) ) . mStrokeLinecap as * const _ + as usize } , 15usize , concat ! ( + "Alignment of field: " , stringify ! ( Weird ) , "::" , + stringify ! ( mStrokeLinecap ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Weird ) ) . mStrokeLinejoin as * const _ + as usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( Weird ) , "::" , + stringify ! ( mStrokeLinejoin ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Weird ) ) . mTextAnchor as * const _ as + usize } , 17usize , concat ! ( + "Alignment of field: " , stringify ! ( Weird ) , "::" , + stringify ! ( mTextAnchor ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Weird ) ) . mTextRendering as * const _ + as usize } , 18usize , concat ! ( + "Alignment of field: " , stringify ! ( Weird ) , "::" , + stringify ! ( mTextRendering ) )); } impl Clone for Weird { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/what_is_going_on.rs b/tests/expectations/tests/what_is_going_on.rs index 6f1998d1..d0265c4e 100644 --- a/tests/expectations/tests/what_is_going_on.rs +++ b/tests/expectations/tests/what_is_going_on.rs @@ -11,8 +11,10 @@ pub struct UnknownUnits { } #[test] fn bindgen_test_layout_UnknownUnits() { - assert_eq!(::std::mem::size_of::<UnknownUnits>() , 1usize); - assert_eq!(::std::mem::align_of::<UnknownUnits>() , 1usize); + assert_eq!(::std::mem::size_of::<UnknownUnits>() , 1usize , concat ! ( + "Size of: " , stringify ! ( UnknownUnits ) )); + assert_eq! (::std::mem::align_of::<UnknownUnits>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( UnknownUnits ) )); } impl Clone for UnknownUnits { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/whitelist-namespaces-basic.rs b/tests/expectations/tests/whitelist-namespaces-basic.rs index cbb12f6b..06f24ff0 100644 --- a/tests/expectations/tests/whitelist-namespaces-basic.rs +++ b/tests/expectations/tests/whitelist-namespaces-basic.rs @@ -20,8 +20,10 @@ pub mod root { } #[test] fn bindgen_test_layout_Helper() { - assert_eq!(::std::mem::size_of::<Helper>() , 1usize); - assert_eq!(::std::mem::align_of::<Helper>() , 1usize); + assert_eq!(::std::mem::size_of::<Helper>() , 1usize , concat ! + ( "Size of: " , stringify ! ( Helper ) )); + assert_eq! (::std::mem::align_of::<Helper>() , 1usize , concat + ! ( "Alignment of " , stringify ! ( Helper ) )); } impl Clone for Helper { fn clone(&self) -> Self { *self } diff --git a/tests/expectations/tests/whitelist-namespaces.rs b/tests/expectations/tests/whitelist-namespaces.rs index bc257af6..d3707800 100644 --- a/tests/expectations/tests/whitelist-namespaces.rs +++ b/tests/expectations/tests/whitelist-namespaces.rs @@ -20,8 +20,10 @@ pub mod root { } #[test] fn bindgen_test_layout_Helper() { - assert_eq!(::std::mem::size_of::<Helper>() , 1usize); - assert_eq!(::std::mem::align_of::<Helper>() , 1usize); + assert_eq!(::std::mem::size_of::<Helper>() , 1usize , concat ! + ( "Size of: " , stringify ! ( Helper ) )); + assert_eq! (::std::mem::align_of::<Helper>() , 1usize , concat + ! ( "Alignment of " , stringify ! ( Helper ) )); } impl Clone for Helper { fn clone(&self) -> Self { *self } @@ -34,8 +36,15 @@ pub mod root { } #[test] fn bindgen_test_layout_Test() { - assert_eq!(::std::mem::size_of::<Test>() , 1usize); - assert_eq!(::std::mem::align_of::<Test>() , 1usize); + assert_eq!(::std::mem::size_of::<Test>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Test ) )); + assert_eq! (::std::mem::align_of::<Test>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Test ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Test ) ) . helper as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Test ) , "::" , + stringify ! ( helper ) )); } impl Clone for Test { fn clone(&self) -> Self { *self } diff --git a/tests/headers/layout.h b/tests/headers/layout.h new file mode 100644 index 00000000..d1822a04 --- /dev/null +++ b/tests/headers/layout.h @@ -0,0 +1,6 @@ +struct header +{ + char proto; + unsigned int size __attribute__ ((packed)); + unsigned char data[] __attribute__ ((aligned(8))); +} __attribute__ ((aligned, packed));
\ No newline at end of file diff --git a/tests/headers/layout_align.h b/tests/headers/layout_align.h new file mode 100644 index 00000000..0201877e --- /dev/null +++ b/tests/headers/layout_align.h @@ -0,0 +1,20 @@ +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +struct rte_kni_fifo { + volatile unsigned write; /**< Next position to be written*/ + volatile unsigned read; /**< Next position to be read */ + unsigned len; /**< Circular buffer length */ + unsigned elem_size; /**< Pointer size - for 32/64 bit OS */ + void *volatile buffer[]; /**< The buffer contains mbuf pointers */ +}; + +__extension__ +struct rte_eth_link { + uint32_t link_speed; /**< ETH_SPEED_NUM_ */ + uint16_t link_duplex : 1; /**< ETH_LINK_[HALF/FULL]_DUPLEX */ + uint16_t link_autoneg : 1; /**< ETH_LINK_SPEED_[AUTONEG/FIXED] */ + uint16_t link_status : 1; /**< ETH_LINK_[DOWN/UP] */ +} __attribute__((aligned(8))); /**< aligned for atomic64 read/write */
\ No newline at end of file diff --git a/tests/headers/layout_arp.h b/tests/headers/layout_arp.h new file mode 100644 index 00000000..8682cbe0 --- /dev/null +++ b/tests/headers/layout_arp.h @@ -0,0 +1,52 @@ +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +#define ETHER_ADDR_LEN 6 /**< Length of Ethernet address. */ + +/** + * Ethernet address: + * A universally administered address is uniquely assigned to a device by its + * manufacturer. The first three octets (in transmission order) contain the + * Organizationally Unique Identifier (OUI). The following three (MAC-48 and + * EUI-48) octets are assigned by that organization with the only constraint + * of uniqueness. + * A locally administered address is assigned to a device by a network + * administrator and does not contain OUIs. + * See http://standards.ieee.org/regauth/groupmac/tutorial.html + */ +struct ether_addr { + uint8_t addr_bytes[ETHER_ADDR_LEN]; /**< Addr bytes in tx order */ +} __attribute__((__packed__)); + +/** + * ARP header IPv4 payload. + */ +struct arp_ipv4 { + struct ether_addr arp_sha; /**< sender hardware address */ + uint32_t arp_sip; /**< sender IP address */ + struct ether_addr arp_tha; /**< target hardware address */ + uint32_t arp_tip; /**< target IP address */ +} __attribute__((__packed__)); + +/** + * ARP header. + */ +struct arp_hdr { + uint16_t arp_hrd; /* format of hardware address */ +#define ARP_HRD_ETHER 1 /* ARP Ethernet address format */ + + uint16_t arp_pro; /* format of protocol address */ + uint8_t arp_hln; /* length of hardware address */ + uint8_t arp_pln; /* length of protocol address */ + uint16_t arp_op; /* ARP opcode (command) */ +#define ARP_OP_REQUEST 1 /* request to resolve address */ +#define ARP_OP_REPLY 2 /* response to previous request */ +#define ARP_OP_REVREQUEST 3 /* request proto addr given hardware */ +#define ARP_OP_REVREPLY 4 /* response giving protocol address */ +#define ARP_OP_INVREQUEST 8 /* request to identify peer */ +#define ARP_OP_INVREPLY 9 /* response identifying peer */ + + struct arp_ipv4 arp_data; +} __attribute__((__packed__));
\ No newline at end of file diff --git a/tests/headers/layout_array.h b/tests/headers/layout_array.h new file mode 100644 index 00000000..4b99e0ed --- /dev/null +++ b/tests/headers/layout_array.h @@ -0,0 +1,109 @@ +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +typedef long long size_t; + +#define RTE_CACHE_LINE_SIZE 64 + +/** + * Force alignment + */ +#define __rte_aligned(a) __attribute__((__aligned__(a))) + +/** + * Force alignment to cache line. + */ +#define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE) + +#define RTE_MEMPOOL_OPS_NAMESIZE 32 /**< Max length of ops struct name. */ + +/** + * Prototype for implementation specific data provisioning function. + * + * The function should provide the implementation specific memory for + * for use by the other mempool ops functions in a given mempool ops struct. + * E.g. the default ops provides an instance of the rte_ring for this purpose. + * it will most likely point to a different type of data structure, and + * will be transparent to the application programmer. + * This function should set mp->pool_data. + */ +typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp); + +/** + * Free the opaque private data pointed to by mp->pool_data pointer. + */ +typedef void (*rte_mempool_free_t)(struct rte_mempool *mp); + +/** + * Enqueue an object into the external pool. + */ +typedef int (*rte_mempool_enqueue_t)(struct rte_mempool *mp, + void * const *obj_table, unsigned int n); + +/** + * Dequeue an object from the external pool. + */ +typedef int (*rte_mempool_dequeue_t)(struct rte_mempool *mp, + void **obj_table, unsigned int n); + +/** + * Return the number of available objects in the external pool. + */ +typedef unsigned (*rte_mempool_get_count)(const struct rte_mempool *mp); +/** Structure defining mempool operations structure */ +struct rte_mempool_ops { + char name[RTE_MEMPOOL_OPS_NAMESIZE]; /**< Name of mempool ops struct. */ + rte_mempool_alloc_t alloc; /**< Allocate private data. */ + rte_mempool_free_t free; /**< Free the external pool. */ + rte_mempool_enqueue_t enqueue; /**< Enqueue an object. */ + rte_mempool_dequeue_t dequeue; /**< Dequeue an object. */ + rte_mempool_get_count get_count; /**< Get qty of available objs. */ +} __rte_cache_aligned; + +#define RTE_MEMPOOL_MAX_OPS_IDX 16 /**< Max registered ops structs */ + +/** + * The rte_spinlock_t type. + */ +typedef struct { + volatile int locked; /**< lock status 0 = unlocked, 1 = locked */ +} rte_spinlock_t; + +/** + * Structure storing the table of registered ops structs, each of which contain + * the function pointers for the mempool ops functions. + * Each process has its own storage for this ops struct array so that + * the mempools can be shared across primary and secondary processes. + * The indices used to access the array are valid across processes, whereas + * any function pointers stored directly in the mempool struct would not be. + * This results in us simply having "ops_index" in the mempool struct. + */ +struct rte_mempool_ops_table { + rte_spinlock_t sl; /**< Spinlock for add/delete. */ + uint32_t num_ops; /**< Number of used ops structs in the table. */ + /** + * Storage for all possible ops structs. + */ + struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX]; +} __rte_cache_aligned; + + +/* Number of free lists per heap, grouped by size. */ +#define RTE_HEAP_NUM_FREELISTS 13 + +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +/** + * Structure to hold malloc heap + */ +struct malloc_heap { + rte_spinlock_t lock; + LIST_HEAD(, malloc_elem) free_head[RTE_HEAP_NUM_FREELISTS]; + unsigned alloc_count; + size_t total_size; +} __rte_cache_aligned; diff --git a/tests/headers/layout_cmdline_token.h b/tests/headers/layout_cmdline_token.h new file mode 100644 index 00000000..34ebd017 --- /dev/null +++ b/tests/headers/layout_cmdline_token.h @@ -0,0 +1,63 @@ + +/** + * Stores a pointer to the ops struct, and the offset: the place to + * write the parsed result in the destination structure. + */ +struct cmdline_token_hdr { + struct cmdline_token_ops *ops; + unsigned int offset; +}; +typedef struct cmdline_token_hdr cmdline_parse_token_hdr_t; + +/** + * A token is defined by this structure. + * + * parse() takes the token as first argument, then the source buffer + * starting at the token we want to parse. The 3rd arg is a pointer + * where we store the parsed data (as binary). It returns the number of + * parsed chars on success and a negative value on error. + * + * complete_get_nb() returns the number of possible values for this + * token if completion is possible. If it is NULL or if it returns 0, + * no completion is possible. + * + * complete_get_elt() copy in dstbuf (the size is specified in the + * parameter) the i-th possible completion for this token. returns 0 + * on success or and a negative value on error. + * + * get_help() fills the dstbuf with the help for the token. It returns + * -1 on error and 0 on success. + */ +struct cmdline_token_ops { + /** parse(token ptr, buf, res pts, buf len) */ + int (*parse)(cmdline_parse_token_hdr_t *, const char *, void *, + unsigned int); + /** return the num of possible choices for this token */ + int (*complete_get_nb)(cmdline_parse_token_hdr_t *); + /** return the elt x for this token (token, idx, dstbuf, size) */ + int (*complete_get_elt)(cmdline_parse_token_hdr_t *, int, char *, + unsigned int); + /** get help for this token (token, dstbuf, size) */ + int (*get_help)(cmdline_parse_token_hdr_t *, char *, unsigned int); +}; + +enum cmdline_numtype { + UINT8 = 0, + UINT16, + UINT32, + UINT64, + INT8, + INT16, + INT32, + INT64 +}; + +struct cmdline_token_num_data { + enum cmdline_numtype type; +}; + +struct cmdline_token_num { + struct cmdline_token_hdr hdr; + struct cmdline_token_num_data num_data; +}; +typedef struct cmdline_token_num cmdline_parse_token_num_t;
\ No newline at end of file diff --git a/tests/headers/layout_eth_conf.h b/tests/headers/layout_eth_conf.h new file mode 100644 index 00000000..a742ee5f --- /dev/null +++ b/tests/headers/layout_eth_conf.h @@ -0,0 +1,427 @@ +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +/** + * Simple flags are used for rte_eth_conf.rxmode.mq_mode. + */ +#define ETH_MQ_RX_RSS_FLAG 0x1 +#define ETH_MQ_RX_DCB_FLAG 0x2 +#define ETH_MQ_RX_VMDQ_FLAG 0x4 + +/* Definitions used for VMDQ and DCB functionality */ +#define ETH_VMDQ_MAX_VLAN_FILTERS 64 /**< Maximum nb. of VMDQ vlan filters. */ +#define ETH_DCB_NUM_USER_PRIORITIES 8 /**< Maximum nb. of DCB priorities. */ +#define ETH_VMDQ_DCB_NUM_QUEUES 128 /**< Maximum nb. of VMDQ DCB queues. */ +#define ETH_DCB_NUM_QUEUES 128 /**< Maximum nb. of DCB queues. */ + +/** + * A set of values to identify what method is to be used to route + * packets to multiple queues. + */ +enum rte_eth_rx_mq_mode { + /** None of DCB,RSS or VMDQ mode */ + ETH_MQ_RX_NONE = 0, + + /** For RX side, only RSS is on */ + ETH_MQ_RX_RSS = ETH_MQ_RX_RSS_FLAG, + /** For RX side,only DCB is on. */ + ETH_MQ_RX_DCB = ETH_MQ_RX_DCB_FLAG, + /** Both DCB and RSS enable */ + ETH_MQ_RX_DCB_RSS = ETH_MQ_RX_RSS_FLAG | ETH_MQ_RX_DCB_FLAG, + + /** Only VMDQ, no RSS nor DCB */ + ETH_MQ_RX_VMDQ_ONLY = ETH_MQ_RX_VMDQ_FLAG, + /** RSS mode with VMDQ */ + ETH_MQ_RX_VMDQ_RSS = ETH_MQ_RX_RSS_FLAG | ETH_MQ_RX_VMDQ_FLAG, + /** Use VMDQ+DCB to route traffic to queues */ + ETH_MQ_RX_VMDQ_DCB = ETH_MQ_RX_VMDQ_FLAG | ETH_MQ_RX_DCB_FLAG, + /** Enable both VMDQ and DCB in VMDq */ + ETH_MQ_RX_VMDQ_DCB_RSS = ETH_MQ_RX_RSS_FLAG | ETH_MQ_RX_DCB_FLAG | + ETH_MQ_RX_VMDQ_FLAG, +}; + +/** + * A structure used to configure the RX features of an Ethernet port. + */ +struct rte_eth_rxmode { + /** The multi-queue packet distribution mode to be used, e.g. RSS. */ + enum rte_eth_rx_mq_mode mq_mode; + uint32_t max_rx_pkt_len; /**< Only used if jumbo_frame enabled. */ + uint16_t split_hdr_size; /**< hdr buf size (header_split enabled).*/ + __extension__ + uint16_t header_split : 1, /**< Header Split enable. */ + hw_ip_checksum : 1, /**< IP/UDP/TCP checksum offload enable. */ + hw_vlan_filter : 1, /**< VLAN filter enable. */ + hw_vlan_strip : 1, /**< VLAN strip enable. */ + hw_vlan_extend : 1, /**< Extended VLAN enable. */ + jumbo_frame : 1, /**< Jumbo Frame Receipt enable. */ + hw_strip_crc : 1, /**< Enable CRC stripping by hardware. */ + enable_scatter : 1, /**< Enable scatter packets rx handler */ + enable_lro : 1; /**< Enable LRO */ +}; + +/** + * A set of values to identify what method is to be used to transmit + * packets using multi-TCs. + */ +enum rte_eth_tx_mq_mode { + ETH_MQ_TX_NONE = 0, /**< It is in neither DCB nor VT mode. */ + ETH_MQ_TX_DCB, /**< For TX side,only DCB is on. */ + ETH_MQ_TX_VMDQ_DCB, /**< For TX side,both DCB and VT is on. */ + ETH_MQ_TX_VMDQ_ONLY, /**< Only VT on, no DCB */ +}; + +/** + * A structure used to configure the TX features of an Ethernet port. + */ +struct rte_eth_txmode { + enum rte_eth_tx_mq_mode mq_mode; /**< TX multi-queues mode. */ + + /* For i40e specifically */ + uint16_t pvid; + __extension__ + uint8_t hw_vlan_reject_tagged : 1, + /**< If set, reject sending out tagged pkts */ + hw_vlan_reject_untagged : 1, + /**< If set, reject sending out untagged pkts */ + hw_vlan_insert_pvid : 1; + /**< If set, enable port based VLAN insertion */ +}; + +/** + * A structure used to configure the Receive Side Scaling (RSS) feature + * of an Ethernet port. + * If not NULL, the *rss_key* pointer of the *rss_conf* structure points + * to an array holding the RSS key to use for hashing specific header + * fields of received packets. The length of this array should be indicated + * by *rss_key_len* below. Otherwise, a default random hash key is used by + * the device driver. + * + * The *rss_key_len* field of the *rss_conf* structure indicates the length + * in bytes of the array pointed by *rss_key*. To be compatible, this length + * will be checked in i40e only. Others assume 40 bytes to be used as before. + * + * The *rss_hf* field of the *rss_conf* structure indicates the different + * types of IPv4/IPv6 packets to which the RSS hashing must be applied. + * Supplying an *rss_hf* equal to zero disables the RSS feature. + */ +struct rte_eth_rss_conf { + uint8_t *rss_key; /**< If not NULL, 40-byte hash key. */ + uint8_t rss_key_len; /**< hash key length in bytes. */ + uint64_t rss_hf; /**< Hash functions to apply - see below. */ +}; + +/** + * This enum indicates the possible number of traffic classes + * in DCB configratioins + */ +enum rte_eth_nb_tcs { + ETH_4_TCS = 4, /**< 4 TCs with DCB. */ + ETH_8_TCS = 8 /**< 8 TCs with DCB. */ +}; + +/** + * This enum indicates the possible number of queue pools + * in VMDQ configurations. + */ +enum rte_eth_nb_pools { + ETH_8_POOLS = 8, /**< 8 VMDq pools. */ + ETH_16_POOLS = 16, /**< 16 VMDq pools. */ + ETH_32_POOLS = 32, /**< 32 VMDq pools. */ + ETH_64_POOLS = 64 /**< 64 VMDq pools. */ +}; + +/** + * A structure used to configure the VMDQ+DCB feature + * of an Ethernet port. + * + * Using this feature, packets are routed to a pool of queues, based + * on the vlan id in the vlan tag, and then to a specific queue within + * that pool, using the user priority vlan tag field. + * + * A default pool may be used, if desired, to route all traffic which + * does not match the vlan filter rules. + */ +struct rte_eth_vmdq_dcb_conf { + enum rte_eth_nb_pools nb_queue_pools; /**< With DCB, 16 or 32 pools */ + uint8_t enable_default_pool; /**< If non-zero, use a default pool */ + uint8_t default_pool; /**< The default pool, if applicable */ + uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */ + struct { + uint16_t vlan_id; /**< The vlan id of the received frame */ + uint64_t pools; /**< Bitmask of pools for packet rx */ + } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */ + uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES]; + /**< Selects a queue in a pool */ +}; + +/* This structure may be extended in future. */ +struct rte_eth_dcb_rx_conf { + enum rte_eth_nb_tcs nb_tcs; /**< Possible DCB TCs, 4 or 8 TCs */ + /** Traffic class each UP mapped to. */ + uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES]; +}; + +struct rte_eth_vmdq_dcb_tx_conf { + enum rte_eth_nb_pools nb_queue_pools; /**< With DCB, 16 or 32 pools. */ + /** Traffic class each UP mapped to. */ + uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES]; +}; + +struct rte_eth_dcb_tx_conf { + enum rte_eth_nb_tcs nb_tcs; /**< Possible DCB TCs, 4 or 8 TCs. */ + /** Traffic class each UP mapped to. */ + uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES]; +}; + +struct rte_eth_vmdq_tx_conf { + enum rte_eth_nb_pools nb_queue_pools; /**< VMDq mode, 64 pools. */ +}; + +struct rte_eth_vmdq_rx_conf { + enum rte_eth_nb_pools nb_queue_pools; /**< VMDq only mode, 8 or 64 pools */ + uint8_t enable_default_pool; /**< If non-zero, use a default pool */ + uint8_t default_pool; /**< The default pool, if applicable */ + uint8_t enable_loop_back; /**< Enable VT loop back */ + uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */ + uint32_t rx_mode; /**< Flags from ETH_VMDQ_ACCEPT_* */ + struct { + uint16_t vlan_id; /**< The vlan id of the received frame */ + uint64_t pools; /**< Bitmask of pools for packet rx */ + } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */ +}; + +/** + * Flow Director setting modes: none, signature or perfect. + */ +enum rte_fdir_mode { + RTE_FDIR_MODE_NONE = 0, /**< Disable FDIR support. */ + RTE_FDIR_MODE_SIGNATURE, /**< Enable FDIR signature filter mode. */ + RTE_FDIR_MODE_PERFECT, /**< Enable FDIR perfect filter mode. */ + RTE_FDIR_MODE_PERFECT_MAC_VLAN, /**< Enable FDIR filter mode - MAC VLAN. */ + RTE_FDIR_MODE_PERFECT_TUNNEL, /**< Enable FDIR filter mode - tunnel. */ +}; + +/** + * Memory space that can be configured to store Flow Director filters + * in the board memory. + */ +enum rte_fdir_pballoc_type { + RTE_FDIR_PBALLOC_64K = 0, /**< 64k. */ + RTE_FDIR_PBALLOC_128K, /**< 128k. */ + RTE_FDIR_PBALLOC_256K, /**< 256k. */ +}; + +/** + * Select report mode of FDIR hash information in RX descriptors. + */ +enum rte_fdir_status_mode { + RTE_FDIR_NO_REPORT_STATUS = 0, /**< Never report FDIR hash. */ + RTE_FDIR_REPORT_STATUS, /**< Only report FDIR hash for matching pkts. */ + RTE_FDIR_REPORT_STATUS_ALWAYS, /**< Always report FDIR hash. */ +}; + +/** + * A structure used to define the input for IPV4 flow + */ +struct rte_eth_ipv4_flow { + uint32_t src_ip; /**< IPv4 source address in big endian. */ + uint32_t dst_ip; /**< IPv4 destination address in big endian. */ + uint8_t tos; /**< Type of service to match. */ + uint8_t ttl; /**< Time to live to match. */ + uint8_t proto; /**< Protocol, next header in big endian. */ +}; + +/** + * A structure used to define the input for IPV6 flow + */ +struct rte_eth_ipv6_flow { + uint32_t src_ip[4]; /**< IPv6 source address in big endian. */ + uint32_t dst_ip[4]; /**< IPv6 destination address in big endian. */ + uint8_t tc; /**< Traffic class to match. */ + uint8_t proto; /**< Protocol, next header to match. */ + uint8_t hop_limits; /**< Hop limits to match. */ +}; + +/** + * A structure used to configure FDIR masks that are used by the device + * to match the various fields of RX packet headers. + */ +struct rte_eth_fdir_masks { + uint16_t vlan_tci_mask; /**< Bit mask for vlan_tci in big endian */ + /** Bit mask for ipv4 flow in big endian. */ + struct rte_eth_ipv4_flow ipv4_mask; + /** Bit maks for ipv6 flow in big endian. */ + struct rte_eth_ipv6_flow ipv6_mask; + /** Bit mask for L4 source port in big endian. */ + uint16_t src_port_mask; + /** Bit mask for L4 destination port in big endian. */ + uint16_t dst_port_mask; + /** 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the + first byte on the wire */ + uint8_t mac_addr_byte_mask; + /** Bit mask for tunnel ID in big endian. */ + uint32_t tunnel_id_mask; + uint8_t tunnel_type_mask; /**< 1 - Match tunnel type, + 0 - Ignore tunnel type. */ +}; + +/** + * Payload type + */ +enum rte_eth_payload_type { + RTE_ETH_PAYLOAD_UNKNOWN = 0, + RTE_ETH_RAW_PAYLOAD, + RTE_ETH_L2_PAYLOAD, + RTE_ETH_L3_PAYLOAD, + RTE_ETH_L4_PAYLOAD, + RTE_ETH_PAYLOAD_MAX = 8, +}; + +#define RTE_ETH_FDIR_MAX_FLEXLEN 16 /**< Max length of flexbytes. */ +#define RTE_ETH_INSET_SIZE_MAX 128 /**< Max length of input set. */ + +/** + * A structure used to select bytes extracted from the protocol layers to + * flexible payload for filter + */ +struct rte_eth_flex_payload_cfg { + enum rte_eth_payload_type type; /**< Payload type */ + uint16_t src_offset[RTE_ETH_FDIR_MAX_FLEXLEN]; + /**< Offset in bytes from the beginning of packet's payload + src_offset[i] indicates the flexbyte i's offset in original + packet payload. This value should be less than + flex_payload_limit in struct rte_eth_fdir_info.*/ +}; + +/** + * A structure used to define FDIR masks for flexible payload + * for each flow type + */ +struct rte_eth_fdir_flex_mask { + uint16_t flow_type; + uint8_t mask[RTE_ETH_FDIR_MAX_FLEXLEN]; + /**< Mask for the whole flexible payload */ +}; + + +/* + * A packet can be identified by hardware as different flow types. Different + * NIC hardwares may support different flow types. + * Basically, the NIC hardware identifies the flow type as deep protocol as + * possible, and exclusively. For example, if a packet is identified as + * 'RTE_ETH_FLOW_NONFRAG_IPV4_TCP', it will not be any of other flow types, + * though it is an actual IPV4 packet. + * Note that the flow types are used to define RSS offload types in + * rte_ethdev.h. + */ +#define RTE_ETH_FLOW_UNKNOWN 0 +#define RTE_ETH_FLOW_RAW 1 +#define RTE_ETH_FLOW_IPV4 2 +#define RTE_ETH_FLOW_FRAG_IPV4 3 +#define RTE_ETH_FLOW_NONFRAG_IPV4_TCP 4 +#define RTE_ETH_FLOW_NONFRAG_IPV4_UDP 5 +#define RTE_ETH_FLOW_NONFRAG_IPV4_SCTP 6 +#define RTE_ETH_FLOW_NONFRAG_IPV4_OTHER 7 +#define RTE_ETH_FLOW_IPV6 8 +#define RTE_ETH_FLOW_FRAG_IPV6 9 +#define RTE_ETH_FLOW_NONFRAG_IPV6_TCP 10 +#define RTE_ETH_FLOW_NONFRAG_IPV6_UDP 11 +#define RTE_ETH_FLOW_NONFRAG_IPV6_SCTP 12 +#define RTE_ETH_FLOW_NONFRAG_IPV6_OTHER 13 +#define RTE_ETH_FLOW_L2_PAYLOAD 14 +#define RTE_ETH_FLOW_IPV6_EX 15 +#define RTE_ETH_FLOW_IPV6_TCP_EX 16 +#define RTE_ETH_FLOW_IPV6_UDP_EX 17 +#define RTE_ETH_FLOW_PORT 18 + /**< Consider device port number as a flow differentiator */ +#define RTE_ETH_FLOW_VXLAN 19 /**< VXLAN protocol based flow */ +#define RTE_ETH_FLOW_GENEVE 20 /**< GENEVE protocol based flow */ +#define RTE_ETH_FLOW_NVGRE 21 /**< NVGRE protocol based flow */ +#define RTE_ETH_FLOW_MAX 22 + +/** + * A structure used to define all flexible payload related setting + * include flex payload and flex mask + */ +struct rte_eth_fdir_flex_conf { + uint16_t nb_payloads; /**< The number of following payload cfg */ + uint16_t nb_flexmasks; /**< The number of following mask */ + struct rte_eth_flex_payload_cfg flex_set[RTE_ETH_PAYLOAD_MAX]; + /**< Flex payload configuration for each payload type */ + struct rte_eth_fdir_flex_mask flex_mask[RTE_ETH_FLOW_MAX]; + /**< Flex mask configuration for each flow type */ +}; + +/** + * A structure used to configure the Flow Director (FDIR) feature + * of an Ethernet port. + * + * If mode is RTE_FDIR_DISABLE, the pballoc value is ignored. + */ +struct rte_fdir_conf { + enum rte_fdir_mode mode; /**< Flow Director mode. */ + enum rte_fdir_pballoc_type pballoc; /**< Space for FDIR filters. */ + enum rte_fdir_status_mode status; /**< How to report FDIR hash. */ + /** RX queue of packets matching a "drop" filter in perfect mode. */ + uint8_t drop_queue; + struct rte_eth_fdir_masks mask; + struct rte_eth_fdir_flex_conf flex_conf; + /**< Flex payload configuration. */ +}; + +/** + * A structure used to enable/disable specific device interrupts. + */ +struct rte_intr_conf { + /** enable/disable lsc interrupt. 0 (default) - disable, 1 enable */ + uint16_t lsc; + /** enable/disable rxq interrupt. 0 (default) - disable, 1 enable */ + uint16_t rxq; +}; + +/** + * A structure used to configure an Ethernet port. + * Depending upon the RX multi-queue mode, extra advanced + * configuration settings may be needed. + */ +struct rte_eth_conf { + uint32_t link_speeds; /**< bitmap of ETH_LINK_SPEED_XXX of speeds to be + used. ETH_LINK_SPEED_FIXED disables link + autonegotiation, and a unique speed shall be + set. Otherwise, the bitmap defines the set of + speeds to be advertised. If the special value + ETH_LINK_SPEED_AUTONEG (0) is used, all speeds + supported are advertised. */ + struct rte_eth_rxmode rxmode; /**< Port RX configuration. */ + struct rte_eth_txmode txmode; /**< Port TX configuration. */ + uint32_t lpbk_mode; /**< Loopback operation mode. By default the value + is 0, meaning the loopback mode is disabled. + Read the datasheet of given ethernet controller + for details. The possible values of this field + are defined in implementation of each driver. */ + struct { + struct rte_eth_rss_conf rss_conf; /**< Port RSS configuration */ + struct rte_eth_vmdq_dcb_conf vmdq_dcb_conf; + /**< Port vmdq+dcb configuration. */ + struct rte_eth_dcb_rx_conf dcb_rx_conf; + /**< Port dcb RX configuration. */ + struct rte_eth_vmdq_rx_conf vmdq_rx_conf; + /**< Port vmdq RX configuration. */ + } rx_adv_conf; /**< Port RX filtering configuration (union). */ + union { + struct rte_eth_vmdq_dcb_tx_conf vmdq_dcb_tx_conf; + /**< Port vmdq+dcb TX configuration. */ + struct rte_eth_dcb_tx_conf dcb_tx_conf; + /**< Port dcb TX configuration. */ + struct rte_eth_vmdq_tx_conf vmdq_tx_conf; + /**< Port vmdq TX configuration. */ + } tx_adv_conf; /**< Port TX DCB configuration (union). */ + /** Currently,Priority Flow Control(PFC) are supported,if DCB with PFC + is needed,and the variable must be set ETH_DCB_PFC_SUPPORT. */ + uint32_t dcb_capability_en; + struct rte_fdir_conf fdir_conf; /**< FDIR configuration. */ + struct rte_intr_conf intr_conf; /**< Interrupt mode configuration. */ +};
\ No newline at end of file diff --git a/tests/headers/layout_kni_mbuf.h b/tests/headers/layout_kni_mbuf.h new file mode 100644 index 00000000..ff161144 --- /dev/null +++ b/tests/headers/layout_kni_mbuf.h @@ -0,0 +1,32 @@ + +#define RTE_CACHE_LINE_MIN_SIZE 64 /**< Minimum Cache line size. */ + +#define RTE_CACHE_LINE_SIZE 64 + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +/* + * The kernel image of the rte_mbuf struct, with only the relevant fields. + * Padding is necessary to assure the offsets of these fields + */ +struct rte_kni_mbuf { + void *buf_addr __attribute__((__aligned__(RTE_CACHE_LINE_SIZE))); + uint64_t buf_physaddr; + char pad0[2]; + uint16_t data_off; /**< Start address of data in segment buffer. */ + char pad1[2]; + uint8_t nb_segs; /**< Number of segments. */ + char pad4[1]; + uint64_t ol_flags; /**< Offload features. */ + char pad2[4]; + uint32_t pkt_len; /**< Total pkt len: sum of all segment data_len. */ + uint16_t data_len; /**< Amount of data in segment buffer. */ + + /* fields on second cache line */ + char pad3[8] __attribute__((__aligned__(RTE_CACHE_LINE_MIN_SIZE))); + void *pool; + void *next; +}; diff --git a/tests/headers/layout_mbuf.h b/tests/headers/layout_mbuf.h new file mode 100644 index 00000000..dc1c1b24 --- /dev/null +++ b/tests/headers/layout_mbuf.h @@ -0,0 +1,187 @@ + +#define RTE_CACHE_LINE_MIN_SIZE 64 /**< Minimum Cache line size. */ + +#define RTE_CACHE_LINE_SIZE 64 + +typedef char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long long int64_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +typedef uint64_t phys_addr_t; + +/** + * Force alignment + */ +#define __rte_aligned(a) __attribute__((__aligned__(a))) + +/** + * Force alignment to cache line. + */ +#define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE) + +/** + * Force minimum cache line alignment. + */ +#define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE) + +/* define a set of marker types that can be used to refer to set points in the + * mbuf */ +__extension__ +typedef void *MARKER[0]; /**< generic marker for a point in a structure */ +__extension__ +typedef uint8_t MARKER8[0]; /**< generic marker with 1B alignment */ +__extension__ +typedef uint64_t MARKER64[0]; /**< marker that allows us to overwrite 8 bytes + * with a single assignment */ + +/** C extension macro for environments lacking C11 features. */ +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L +#define RTE_STD_C11 __extension__ +#else +#define RTE_STD_C11 +#endif + +/** + * The atomic counter structure. + */ +typedef struct { + volatile int16_t cnt; /**< An internal counter value. */ +} rte_atomic16_t; + +/** + * The generic rte_mbuf, containing a packet mbuf. + */ +struct rte_mbuf { + MARKER cacheline0; + + void *buf_addr; /**< Virtual address of segment buffer. */ + phys_addr_t buf_physaddr; /**< Physical address of segment buffer. */ + + uint16_t buf_len; /**< Length of segment buffer. */ + + /* next 6 bytes are initialised on RX descriptor rearm */ + MARKER8 rearm_data; + uint16_t data_off; + + /** + * 16-bit Reference counter. + * It should only be accessed using the following functions: + * rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and + * rte_mbuf_refcnt_set(). The functionality of these functions (atomic, + * or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC + * config option. + */ + RTE_STD_C11 + union { + rte_atomic16_t refcnt_atomic; /**< Atomically accessed refcnt */ + uint16_t refcnt; /**< Non-atomically accessed refcnt */ + }; + uint8_t nb_segs; /**< Number of segments. */ + uint8_t port; /**< Input port. */ + + uint64_t ol_flags; /**< Offload features. */ + + /* remaining bytes are set on RX when pulling packet from descriptor */ + MARKER rx_descriptor_fields1; + + /* + * The packet type, which is the combination of outer/inner L2, L3, L4 + * and tunnel types. The packet_type is about data really present in the + * mbuf. Example: if vlan stripping is enabled, a received vlan packet + * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the + * vlan is stripped from the data. + */ + RTE_STD_C11 + union { + uint32_t packet_type; /**< L2/L3/L4 and tunnel information. */ + struct { + uint32_t l2_type:4; /**< (Outer) L2 type. */ + uint32_t l3_type:4; /**< (Outer) L3 type. */ + uint32_t l4_type:4; /**< (Outer) L4 type. */ + uint32_t tun_type:4; /**< Tunnel type. */ + uint32_t inner_l2_type:4; /**< Inner L2 type. */ + uint32_t inner_l3_type:4; /**< Inner L3 type. */ + uint32_t inner_l4_type:4; /**< Inner L4 type. */ + }; + }; + + uint32_t pkt_len; /**< Total pkt len: sum of all segments. */ + uint16_t data_len; /**< Amount of data in segment buffer. */ + /** VLAN TCI (CPU order), valid if PKT_RX_VLAN_STRIPPED is set. */ + uint16_t vlan_tci; + + union { + uint32_t rss; /**< RSS hash result if RSS enabled */ + struct { + RTE_STD_C11 + union { + struct { + uint16_t hash; + uint16_t id; + }; + uint32_t lo; + /**< Second 4 flexible bytes */ + }; + uint32_t hi; + /**< First 4 flexible bytes or FD ID, dependent on + PKT_RX_FDIR_* flag in ol_flags. */ + } fdir; /**< Filter identifier if FDIR enabled */ + struct { + uint32_t lo; + uint32_t hi; + } sched; /**< Hierarchical scheduler */ + uint32_t usr; /**< User defined tags. See rte_distributor_process() */ + } hash; /**< hash information */ + + uint32_t seqn; /**< Sequence number. See also rte_reorder_insert() */ + + /** Outer VLAN TCI (CPU order), valid if PKT_RX_QINQ_STRIPPED is set. */ + uint16_t vlan_tci_outer; + + /* second cache line - fields only used in slow path or on TX */ + MARKER cacheline1 __rte_cache_min_aligned; + + RTE_STD_C11 + union { + void *userdata; /**< Can be used for external metadata */ + uint64_t udata64; /**< Allow 8-byte userdata on 32-bit */ + }; + + struct rte_mempool *pool; /**< Pool from which mbuf was allocated. */ + struct rte_mbuf *next; /**< Next segment of scattered packet. */ + + /* fields to support TX offloads */ + RTE_STD_C11 + union { + uint64_t tx_offload; /**< combined for easy fetch */ + __extension__ + struct { + uint64_t l2_len:7; + /**< L2 (MAC) Header Length for non-tunneling pkt. + * Outer_L4_len + ... + Inner_L2_len for tunneling pkt. + */ + uint64_t l3_len:9; /**< L3 (IP) Header Length. */ + uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */ + uint64_t tso_segsz:16; /**< TCP TSO segment size */ + + /* fields for TX offloading of tunnels */ + uint64_t outer_l3_len:9; /**< Outer L3 (IP) Hdr Length. */ + uint64_t outer_l2_len:7; /**< Outer L2 (MAC) Hdr Length. */ + + /* uint64_t unused:8; */ + }; + }; + + /** Size of the application private data. In case of an indirect + * mbuf, it stores the direct mbuf private data size. */ + uint16_t priv_size; + + /** Timesync flags for use with IEEE1588. */ + uint16_t timesync; +} __rte_cache_aligned;
\ No newline at end of file diff --git a/tests/headers/objc_method.h b/tests/headers/objc_method.h index 91645f16..7a22e8e4 100644 --- a/tests/headers/objc_method.h +++ b/tests/headers/objc_method.h @@ -3,5 +3,9 @@ @interface Foo - (void)method; -// TODO: argument methods +- (void)methodWithInt:(int)foo; +- (void)methodWithFoo:(Foo*)foo; +- (int)methodReturningInt; +- (Foo*)methodReturningFoo; +- (void)methodWithArg1:(int)intvalue andArg2:(char*)ptr andArg3:(float)floatvalue; @end diff --git a/tests/headers/template-fun-ty.hpp b/tests/headers/template-fun-ty.hpp new file mode 100644 index 00000000..1e8e1c25 --- /dev/null +++ b/tests/headers/template-fun-ty.hpp @@ -0,0 +1,16 @@ +template <typename T> +class Foo +{ + typedef T (FunctionPtr)(); +}; + +template<typename T> +class RefPtr { + template<typename R, typename... Args> + class Proxy { + typedef R (T::*member_function)(Args...); + }; +}; + +template<typename T> +using Returner = T(*)(); diff --git a/tests/tests.rs b/tests/tests.rs index 81f3e15c..bc853a33 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -68,8 +68,7 @@ fn compare_generated_header(header: &PathBuf, Err(Error::new(ErrorKind::Other, "Header and binding differ!")) } -fn create_bindgen_builder(header: &PathBuf) - -> Result<Option<Builder>, Error> { +fn create_bindgen_builder(header: &PathBuf) -> Result<Option<Builder>, Error> { let source = try!(fs::File::open(header)); let reader = BufReader::new(source); |