diff options
23 files changed, 307 insertions, 139 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bab631d6..c1ec96d1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,28 +1,35 @@ -# Contributing to `servo/rust-bindgen` +# Contributing to `bindgen` Hi! We'd love to have your contributions! If you want help or mentorship, reach -out to us in a GitHub issue, or stop by #servo on irc.mozilla.org and introduce -yourself. - -* [Code of Conduct](#coc) -* [Filing an Issue](#issue) -* [Building](#building) -* [Testing](#tests) - * [Overview](#tests-overview) - * [Running All Tests](#tests-all) - * [Running a Single, Specific Test](#tests-one) - * [Authoring New Tests](#tests-new) -* [Automatic Code Formatting](#formatting) -* [Debug Logging](#logs) -* [Using `creduce` to Minimize Test Cases](#creduce) - -## Code of Conduct <span id="coc"/> +out to us in a GitHub issue, or stop by +[#servo on irc.mozilla.org](irc://irc.mozilla.org#servo) and introduce yourself. + +<!-- START doctoc generated TOC please keep comment here to allow auto update --> +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> + + +- [Code of Conduct](#code-of-conduct) +- [Filing an Issue](#filing-an-issue) +- [Building](#building) +- [Testing](#testing) + - [Overview](#overview) + - [Running All Tests](#running-all-tests) + - [Authoring New Tests](#authoring-new-tests) +- [Automatic code formatting](#automatic-code-formatting) +- [Debug Logging](#debug-logging) +- [Using `creduce` to Minimize Test Cases](#using-creduce-to-minimize-test-cases) + - [Isolating Your Test Case](#isolating-your-test-case) + - [Writing a Predicate Script](#writing-a-predicate-script) + +<!-- END doctoc generated TOC please keep comment here to allow auto update --> + +## Code of Conduct We abide by the [Rust Code of Conduct][coc] and ask that you do as well. [coc]: https://www.rust-lang.org/en-US/conduct.html -## Filing an Issue <span id="issue"/> +## Filing an Issue Think you've found a bug? File an issue! To help us understand and reproduce the issue, provide us with: @@ -33,11 +40,39 @@ issue, provide us with: * The actual `bindgen` output * The [debugging logs](#logs) generated when running `bindgen` on this testcase -## Building <span id="building"/> +## Building + +To build `libbindgen`: + +``` +$ cd bindgen/libbindgen +$ cargo build +``` + +To build the `bindgen` executable: -Build instructions are in the [README](./README.md). +``` +$ cd bindgen/bindgen +$ cargo build +``` + +If you installed multiple versions of llvm, it may not be able to locate the +latest version of libclang. In that case, you may want to either uninstall other +versions of llvm, or specify the path of the desired libclang explicitly: + +``` +$ export LIBCLANG_PATH=path/to/clang-3.9/lib +``` + +On Linux and macOS, you may also need to add a path to `libclang.so` (usually +the same path as above) to library search path. This can be done as below: + +``` +$ export LD_LIBRARY_PATH=path/to/clang-3.9/lib # for Linux +$ export DYLD_LIBRARY_PATH=path/to/clang-3.9/lib # for macOS +``` -Additionally, you may want to build and test with the `_docs` feature to ensure +Additionally, you may want to build and test with the `docs_` feature to ensure that you aren't forgetting to document types and functions. CI will catch it if you forget, but the turn around will be a lot slower ;) @@ -45,27 +80,28 @@ you forget, but the turn around will be a lot slower ;) $ cd libbindgen && cargo build --features "llvm_stable _docs" ``` -## Testing <span id="tests"/> +## Testing Code for binding generation and testing thereof is in the `libbindgen` crate. The following sections assume you are working in that subdirectory. -### Overview <span id="tests-overview"/> +### Overview -Input C/C++ test headers reside in the `tests/headers` directory. Expected -output Rust bindings live in `tests/expectations/tests`. For example, -`tests/headers/my_header.h`'s expected generated Rust bindings would be -`tests/expectations/tests/my_header.rs`. +Input C/C++ test headers reside in the `libbindgen/tests/headers` +directory. Expected output Rust bindings live in +`libbindgen/tests/expectations/tests`. For example, +`libbindgen/tests/headers/my_header.h`'s expected generated Rust bindings would +be `libbindgen/tests/expectations/tests/my_header.rs`. Run `cargo test` to compare generated Rust bindings to the expectations. -### Running All Tests <span id="tests-all"/> +### Running All Tests ``` $ cargo test [--features llvm_stable] ``` -### Authoring New Tests <span id="tests-new"/> +### Authoring New Tests To add a new test header to the suite, simply put it in the `tests/headers` directory. Next, run `bindgen` to generate the initial expected output Rust @@ -84,7 +120,7 @@ Then verify the new Rust bindings compile and pass some basic tests: $ cargo test -p tests_expectations ``` -## Automatic code formatting <span id="formatting"/> +## 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. @@ -105,10 +141,10 @@ $ cargo install rustfmt And ensure `~/.cargo/bin` is on your path. -## Debug Logging <span id="logs"/> +## Debug Logging To help debug what `bindgen` is doing, you can define the environment variable -`RUST_LOG=bindgen` to get a bunch of debugging log spew. +`RUST_LOG=libbindgen` to get a bunch of debugging log spew. ``` $ RUST_LOG=libbindgen ./target/debug/bindgen [flags...] ~/path/to/some/header.h @@ -117,10 +153,11 @@ $ RUST_LOG=libbindgen ./target/debug/bindgen [flags...] ~/path/to/some/header.h This logging can also be used when debugging failing tests: ``` -$ RUST_LOG=libbindgen cd libbindgen && cargo test +$ cd libbindgen +$ RUST_LOG=libbindgen cargo test ``` -## Using `creduce` to Minimize Test Cases <span id="creduce"/> +## Using `creduce` to Minimize Test Cases If you are hacking on `bindgen` and find a test case that causes an unexpected panic, results in bad Rust bindings, or some other incorrectness in `bindgen`, @@ -1,38 +1,63 @@ -# Servo's rust-bindgen +# `bindgen` -A binding generator for the Rust language. +Automatically generates Rust FFI bindings to C and C++ libraries. -This is a fork of [crabtw/rust-bindgen](https://github.com/crabtw/rust-bindgen) -designed to work on C++ code as well. +<!-- START doctoc generated TOC please keep comment here to allow auto update --> +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> -Currently this is being used for Servo's SpiderMonkey bindings, and also for -the [Stylo](https://public.etherpad-mozilla.org/p/stylo) project. -## Requirements +- [Usage](#usage) + - [Requirements](#requirements) + - [Installing Clang 3.9](#installing-clang-39) + - [Windows](#windows) + - [OSX](#osx) + - [Debian-based Linuxes](#debian-based-linuxes) + - [Arch](#arch) + - [From source](#from-source) + - [Library usage with `build.rs`](#library-usage-with-buildrs) + - [`build.rs` Tutorial](#buildrs-tutorial) + - [Simple Example: `./bindgen-integration`](#simple-example-bindgen-integration) + - [Real World Example: Stylo](#real-world-example-stylo) + - [Command Line Usage](#command-line-usage) + - [C++](#c) + - [Annotations](#annotations) + - [`opaque`](#opaque) + - [`hide`](#hide) + - [`replaces`](#replaces) + - [`nocopy`](#nocopy) +- [Building From Source](#building-from-source) -It is recommended to use clang 3.9 with the current generator. It can run with -clang 3.8 with some features disabled. +<!-- END doctoc generated TOC please keep comment here to allow auto update --> -### Installing Clang 3.9 +## Usage -#### Windows +### Requirements + +It is recommended to use Clang 3.9 or greater, however `bindgen` can run with +older Clangs with some features disabled. + +#### Installing Clang 3.9 + +##### Windows Download and install the official pre-built binary from [LLVM download page](http://releases.llvm.org/download.html). -#### OSX +##### OSX If you use Homebrew: + ``` $ brew install llvm ``` If you use MacPorts: + ``` $ port install clang-3.9 ``` -#### Debian-based Linuxes +##### Debian-based Linuxes ``` # apt-get install llvm-3.9-dev libclang-3.9-dev @@ -42,13 +67,13 @@ Ubuntu 16.10 provides the necessary packages directly. If you are using older version of Ubuntu or other Debian-based distros, you may need to add the LLVM repos to get version 3.9. See http://apt.llvm.org/. -#### Arch +##### Arch ``` # pacman -S clang ``` -#### From source +##### From source If your package manager doesn't yet offer Clang 3.9, you'll need to build from source. For that, follow the instructions @@ -61,31 +86,26 @@ Those instructions list optional steps. For bindgen: * Checkout and build the compiler-rt * You do not need to checkout or build libcxx -## Building +### Library usage with `build.rs` -``` -$ cd bindgen -$ cargo build -``` +#### `build.rs` Tutorial -If you installed multiple versions of llvm, it may not be able to locate the -latest version of libclang. In that case, you may want to either uninstall -other versions of llvm, or specify the path of the desired libclang explicitly: -``` -$ export LIBCLANG_PATH=path/to/clang-3.9/lib -``` +[Here is a step-by-step tutorial for generating FFI bindings to the `bzip2` C library.][tutorial] -On Linux and macOS, you may also need to add a path to `libclang.so` (usually -the same path as above) to library search path. This can be done as below: -``` -$ export LD_LIBRARY_PATH=path/to/clang-3.9/lib # for Linux -$ export DYLD_LIBRARY_PATH=path/to/clang-3.9/lib # for macOS -``` +[tutorial]: http://fitzgeraldnick.com/2016/12/14/using-libbindgen-in-build-rs.html + +#### Simple Example: `./bindgen-integration` -# Library usage with `build.rs` +The [`./bindgen-integration`][integration] directory has an example crate that +generates FFI bindings in `build.rs` and can be used a template for new +projects. -See [the Stylo build script][stylo-script] to see how it is used inside the -Servo organisation. +[integration]: ./bindgen-integration + +#### Real World Example: Stylo + +A real world example is [the Stylo build script][stylo-script] used for +integrating Servo's layout system into Gecko. [stylo-script]: https://github.com/servo/servo/blob/master/components/style/build_gecko.rs @@ -124,28 +144,28 @@ In `src/main.rs`: include!(concat!(env!("OUT_DIR"), "/example.rs")); ``` -# Command Line Usage +### Command Line Usage -There are a few options documented when running `./bindgen --help`. Other -options might exist (see [the SpiderMonkey script][sm-script] to see how it -is used inside the Servo organisation. +``` +$ cargo install bindgen +``` -[sm-script]: https://github.com/servo/rust-mozjs/blob/master/etc/bindings.sh +There are a few options documented when running `./bindgen --help`. -## C++ Usage +### C++ This fork of rust-bindgen can handle a number of C++ features. When passing in header files, the file will automatically be treated as C++ if it ends in ``.hpp``. If it doesn't, ``-x c++`` can be used to force C++ mode. -## Annotations +### Annotations The translation of classes, structs, enums, and typedefs can be adjusted using annotations. Annotations are specifically formatted html tags inside doxygen style comments. -### `opaque` +#### `opaque` The `opaque` annotation instructs bindgen to ignore all fields defined in a struct/class. @@ -154,7 +174,7 @@ a struct/class. /// <div rustbindgen opaque></div> ``` -### `hide` +#### `hide` The `hide` annotation instructs bindgen to ignore the struct/class/field/enum completely. @@ -163,7 +183,7 @@ completely. /// <div rustbindgen hide></div> ``` -### `replaces` +#### `replaces` The `replaces` annotation can be used to use a type as a replacement for other (presumably more complex) type. This is used in Stylo to generate bindings for @@ -188,7 +208,7 @@ public: That way, after code generation, the bindings for the `nsTArray` type are the ones that would be generated for `nsTArray_Simple`. -### `nocopy` +#### `nocopy` The `nocopy` annotation is used to prevent bindgen to autoderive the `Copy` and `Clone` traits for a type. diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index 21f6d1a7..ebd58649 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -8,3 +8,5 @@ public: Test(int foo); Test(double foo); }; + +typedef Test TypeAlias; diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 22e31ba6..a445df69 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -11,7 +11,7 @@ license = "BSD-3-Clause" name = "bindgen" readme = "README.md" repository = "https://github.com/servo/rust-bindgen" -version = "0.17.0" +version = "0.17.1" workspace = ".." [dependencies] @@ -19,7 +19,7 @@ clang-sys = "0.12" clap = "2" libbindgen = { path = "../libbindgen" } log = "0.3" -env_logger = "0.3" +env_logger = "0.4" rustc-serialize = "0.3.19" [features] diff --git a/libbindgen/Cargo.toml b/libbindgen/Cargo.toml index f5498bc9..2615b822 100644 --- a/libbindgen/Cargo.toml +++ b/libbindgen/Cargo.toml @@ -12,7 +12,7 @@ license = "BSD-3-Clause" name = "libbindgen" readme = "README.md" repository = "https://github.com/servo/rust-bindgen" -version = "0.1.6" +version = "0.1.7" workspace = ".." [dev-dependencies] @@ -29,16 +29,16 @@ cfg-if = "0.1.0" clang-sys = { version = "0.12", features = ["runtime", "clang_3_9"] } lazy_static = "0.2.1" rustc-serialize = "0.3.19" -syntex_syntax = "0.50" +syntex_syntax = "0.54" regex = "0.2" [dependencies.aster] features = ["with-syntex"] -version = "0.34" +version = "0.38" [dependencies.env_logger] optional = true -version = "0.3" +version = "0.4" [dependencies.log] optional = true @@ -46,7 +46,7 @@ version = "0.3" [dependencies.quasi] features = ["with-syntex"] -version = "0.26" +version = "0.29" [features] assert_no_dangling_items = [] diff --git a/libbindgen/src/codegen/helpers.rs b/libbindgen/src/codegen/helpers.rs index 78fd7b69..06dadab0 100644 --- a/libbindgen/src/codegen/helpers.rs +++ b/libbindgen/src/codegen/helpers.rs @@ -155,7 +155,7 @@ pub mod ast_ty { } pub fn float_expr(f: f64) -> P<ast::Expr> { - use aster::str::ToInternedString; + use aster::symbol::ToSymbol; let mut string = f.to_string(); // So it gets properly recognised as a floating point constant. @@ -163,8 +163,7 @@ pub mod ast_ty { string.push('.'); } - let interned_str = string.as_str().to_interned_string(); - let kind = ast::LitKind::FloatUnsuffixed(interned_str); + let kind = ast::LitKind::FloatUnsuffixed(string.as_str().to_symbol()); aster::AstBuilder::new().expr().lit().build_lit(kind) } diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs index f8352cc8..7451dd11 100644 --- a/libbindgen/src/codegen/mod.rs +++ b/libbindgen/src/codegen/mod.rs @@ -523,22 +523,46 @@ impl CodeGenerator for Type { typedef = typedef.attr().doc(comment); } - let mut generics = typedef.type_(rust_name).generics(); - for template_arg in applicable_template_args.iter() { - let template_arg = ctx.resolve_type(*template_arg); - if template_arg.is_named() { - let name = template_arg.name().unwrap(); - if name.contains("typename ") { - warn!("Item contained `typename`'d template \ - parameter: {:?}", item); - return; + // We prefer using `pub use` over `pub type` because of: + // https://github.com/rust-lang/rust/issues/26264 + 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_builtin_or_named() && + p.segments.iter().all(|p| p.parameters.is_none()) { + Some(p.clone()) + } else { + None } - generics = - generics.ty_param_id(template_arg.name().unwrap()); - } - } + }, + _ => None, + }; - let typedef = generics.build().build_ty(inner_rust_type); + let typedef = if let Some(mut p) = simple_enum_path { + if p.segments.len() == 1 { + p.segments.insert(0, ast::PathSegment { + identifier: ctx.ext_cx().ident_of("self"), + parameters: None, + }); + } + typedef.use_().build(p).as_(rust_name) + } else { + let mut generics = typedef.type_(rust_name).generics(); + for template_arg in applicable_template_args.iter() { + let template_arg = ctx.resolve_type(*template_arg); + if template_arg.is_named() { + let name = template_arg.name().unwrap(); + if name.contains("typename ") { + warn!("Item contained `typename`'d template \ + parameter: {:?}", item); + return; + } + generics = + generics.ty_param_id(template_arg.name().unwrap()); + } + } + generics.build().build_ty(inner_rust_type) + }; result.push(typedef) } TypeKind::Enum(ref ei) => { @@ -1295,6 +1319,12 @@ impl MethodCodegen for Method { _ => panic!("How in the world?"), }; + // Do not generate variadic methods, since rust does not allow + // implementing them, and we don't do a good job at it anyway. + if signature.is_variadic() { + return; + } + let count = { let mut count = method_names.entry(name.clone()) .or_insert(0); @@ -1863,16 +1893,19 @@ impl ToRustTy for Type { if let ast::TyKind::Path(_, ref mut path) = inner_ty.node { let template_args = template_args.iter() .map(|arg| arg.to_rust_ty(ctx)) - .collect(); + .collect::<Vec<_>>(); - path.segments.last_mut().unwrap().parameters = - ast::PathParameters::AngleBracketed( + path.segments.last_mut().unwrap().parameters = if template_args.is_empty() { + None + } else { + Some(P(ast::PathParameters::AngleBracketed( ast::AngleBracketedParameterData { lifetimes: vec![], types: P::from_vec(template_args), bindings: P::from_vec(vec![]), } - ); + ))) + } } P(inner_ty) diff --git a/libbindgen/src/ir/comp.rs b/libbindgen/src/ir/comp.rs index ac41b929..968bf879 100644 --- a/libbindgen/src/ir/comp.rs +++ b/libbindgen/src/ir/comp.rs @@ -652,29 +652,6 @@ impl CompInfo { ci.has_destructor |= cur.kind() == CXCursor_Destructor; ci.has_vtable |= is_virtual; - let linkage = cur.linkage(); - if linkage != CXLinkage_External { - return CXChildVisit_Continue; - } - - if cur.access_specifier() == CX_CXXPrivate { - return CXChildVisit_Continue; - } - - let visibility = cur.visibility(); - if visibility != CXVisibility_Default { - return CXChildVisit_Continue; - } - - if cur.is_inlined_function() { - return CXChildVisit_Continue; - } - - let spelling = cur.spelling(); - if spelling.starts_with("operator") { - return CXChildVisit_Continue; - } - // This used to not be here, but then I tried generating // stylo bindings with this (without path filters), and // cried a lot with a method in gfx/Point.h @@ -691,8 +668,10 @@ impl CompInfo { // NB: This gets us an owned `Function`, not a // `FunctionSig`. - let signature = Item::parse(cur, Some(potential_id), ctx) - .expect("CXXMethod"); + 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 => { diff --git a/libbindgen/src/ir/context.rs b/libbindgen/src/ir/context.rs index 4d20c053..b0143bd5 100644 --- a/libbindgen/src/ir/context.rs +++ b/libbindgen/src/ir/context.rs @@ -461,6 +461,7 @@ impl<'ctx> BindgenContext<'ctx> { pub fn gen<F, Out>(&mut self, cb: F) -> Out where F: FnOnce(&Self) -> Out, { + use aster::symbol::ToSymbol; use syntax::ext::expand::ExpansionConfig; use syntax::codemap::{ExpnInfo, MacroBang, NameAndSpan}; use syntax::ext::base; @@ -475,7 +476,7 @@ impl<'ctx> BindgenContext<'ctx> { ctx.0.bt_push(ExpnInfo { call_site: self.span, callee: NameAndSpan { - format: MacroBang(parse::token::intern("")), + format: MacroBang("".to_symbol()), allow_internal_unstable: false, span: None, }, diff --git a/libbindgen/src/ir/function.rs b/libbindgen/src/ir/function.rs index 88ab861d..50c442db 100644 --- a/libbindgen/src/ir/function.rs +++ b/libbindgen/src/ir/function.rs @@ -150,6 +150,7 @@ impl FunctionSig { } else { ty.declaration() }; + let mut args: Vec<_> = match cursor.kind() { CXCursor_FunctionDecl | CXCursor_Constructor | @@ -262,6 +263,24 @@ impl ClangSubItemParser for Function { debug!("Function::parse({:?}, {:?})", cursor, cursor.cur_type()); + let visibility = cursor.visibility(); + if visibility != CXVisibility_Default { + return Err(ParseError::Continue); + } + + if cursor.access_specifier() == CX_CXXPrivate { + return Err(ParseError::Continue); + } + + if cursor.is_inlined_function() { + return Err(ParseError::Continue); + } + + let linkage = cursor.linkage(); + if linkage != CXLinkage_External && linkage != CXLinkage_UniqueExternal { + return Err(ParseError::Continue); + } + // Grab the signature using Item::from_ty. let sig = try!(Item::from_ty(&cursor.cur_type(), Some(cursor), diff --git a/libbindgen/src/ir/ty.rs b/libbindgen/src/ir/ty.rs index e83ef4fd..c1ed5b64 100644 --- a/libbindgen/src/ir/ty.rs +++ b/libbindgen/src/ir/ty.rs @@ -123,6 +123,14 @@ impl Type { } } + /// Is this an enum type? + pub fn is_enum(&self) -> bool { + match self.kind { + TypeKind::Enum(..) => true, + _ => false, + } + } + /// Is this either a builtin or named type? pub fn is_builtin_or_named(&self) -> bool { match self.kind { diff --git a/libbindgen/tests/expectations/tests/anon_enum.rs b/libbindgen/tests/expectations/tests/anon_enum.rs index 075830e6..3b05eab8 100644 --- a/libbindgen/tests/expectations/tests/anon_enum.rs +++ b/libbindgen/tests/expectations/tests/anon_enum.rs @@ -22,3 +22,9 @@ fn bindgen_test_layout_Test() { impl Clone for Test { fn clone(&self) -> Self { *self } } +pub const Foo: _bindgen_ty_1 = _bindgen_ty_1::Foo; +pub const Bar: _bindgen_ty_1 = _bindgen_ty_1::Bar; +#[repr(u32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum _bindgen_ty_1 { Foo = 0, Bar = 1, } +pub use self::_bindgen_ty_1 as Baz; diff --git a/libbindgen/tests/expectations/tests/bitfield_method_mangling.rs b/libbindgen/tests/expectations/tests/bitfield_method_mangling.rs index 5aba8abb..b650a38f 100644 --- a/libbindgen/tests/expectations/tests/bitfield_method_mangling.rs +++ b/libbindgen/tests/expectations/tests/bitfield_method_mangling.rs @@ -46,4 +46,4 @@ impl _bindgen_ty_1 { ((val as u32 as u32) << 24u32) & (4278190080usize as u32); } } -pub type mach_msg_type_descriptor_t = _bindgen_ty_1; +pub use self::_bindgen_ty_1 as mach_msg_type_descriptor_t; diff --git a/libbindgen/tests/expectations/tests/inherit_typedef.rs b/libbindgen/tests/expectations/tests/inherit_typedef.rs index ca9041e2..2b974223 100644 --- a/libbindgen/tests/expectations/tests/inherit_typedef.rs +++ b/libbindgen/tests/expectations/tests/inherit_typedef.rs @@ -17,7 +17,7 @@ fn bindgen_test_layout_Foo() { impl Clone for Foo { fn clone(&self) -> Self { *self } } -pub type TypedefedFoo = Foo; +pub use self::Foo as TypedefedFoo; #[repr(C)] #[derive(Debug, Copy)] pub struct Bar { diff --git a/libbindgen/tests/expectations/tests/inline-function.rs b/libbindgen/tests/expectations/tests/inline-function.rs new file mode 100644 index 00000000..b4b7b2bc --- /dev/null +++ b/libbindgen/tests/expectations/tests/inline-function.rs @@ -0,0 +1,7 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + + diff --git a/libbindgen/tests/expectations/tests/namespace.rs b/libbindgen/tests/expectations/tests/namespace.rs index 3d6e5974..ece4e341 100644 --- a/libbindgen/tests/expectations/tests/namespace.rs +++ b/libbindgen/tests/expectations/tests/namespace.rs @@ -37,9 +37,22 @@ pub mod root { assert_eq!(::std::mem::size_of::<A>() , 4usize); assert_eq!(::std::mem::align_of::<A>() , 4usize); } + extern "C" { + #[link_name = "_ZN12_GLOBAL__N_11A20lets_hope_this_worksEv"] + pub fn A_lets_hope_this_works(this: + *mut root::_bindgen_mod_id_13::A) + -> ::std::os::raw::c_int; + } impl Clone for A { fn clone(&self) -> Self { *self } } + impl A { + #[inline] + pub unsafe fn lets_hope_this_works(&mut self) + -> ::std::os::raw::c_int { + A_lets_hope_this_works(&mut *self) + } + } } #[repr(C)] #[derive(Debug)] diff --git a/libbindgen/tests/expectations/tests/reparented_replacement.rs b/libbindgen/tests/expectations/tests/reparented_replacement.rs index 74ee229c..e8ccc931 100644 --- a/libbindgen/tests/expectations/tests/reparented_replacement.rs +++ b/libbindgen/tests/expectations/tests/reparented_replacement.rs @@ -25,5 +25,5 @@ pub mod root { fn clone(&self) -> Self { *self } } } - pub type ReferencesBar = root::foo::Bar; + pub use root::foo::Bar as ReferencesBar; } diff --git a/libbindgen/tests/expectations/tests/union_fields.rs b/libbindgen/tests/expectations/tests/union_fields.rs index 495e80f9..21d87919 100644 --- a/libbindgen/tests/expectations/tests/union_fields.rs +++ b/libbindgen/tests/expectations/tests/union_fields.rs @@ -44,4 +44,4 @@ fn bindgen_test_layout__bindgen_ty_1() { impl Clone for _bindgen_ty_1 { fn clone(&self) -> Self { *self } } -pub type nsStyleUnion = _bindgen_ty_1; +pub use self::_bindgen_ty_1 as nsStyleUnion; diff --git a/libbindgen/tests/expectations/tests/unknown_attr.rs b/libbindgen/tests/expectations/tests/unknown_attr.rs index fd9cce45..541bee5d 100644 --- a/libbindgen/tests/expectations/tests/unknown_attr.rs +++ b/libbindgen/tests/expectations/tests/unknown_attr.rs @@ -13,4 +13,4 @@ pub struct _bindgen_ty_1 { impl Clone for _bindgen_ty_1 { fn clone(&self) -> Self { *self } } -pub type max_align_t = _bindgen_ty_1; +pub use self::_bindgen_ty_1 as max_align_t; diff --git a/libbindgen/tests/expectations/tests/variadic-method.rs b/libbindgen/tests/expectations/tests/variadic-method.rs new file mode 100644 index 00000000..34301069 --- /dev/null +++ b/libbindgen/tests/expectations/tests/variadic-method.rs @@ -0,0 +1,27 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +extern "C" { + #[link_name = "_Z3fooPKcz"] + pub fn foo(fmt: *const ::std::os::raw::c_char, ...); +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct Bar { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_Bar() { + assert_eq!(::std::mem::size_of::<Bar>() , 1usize); + assert_eq!(::std::mem::align_of::<Bar>() , 1usize); +} +extern "C" { + #[link_name = "_ZN3Bar3fooEPKcz"] + pub fn Bar_foo(this: *mut Bar, fmt: *const ::std::os::raw::c_char, ...); +} +impl Clone for Bar { + fn clone(&self) -> Self { *self } +} diff --git a/libbindgen/tests/headers/anon_enum.hpp b/libbindgen/tests/headers/anon_enum.hpp index c7405202..1961fe6c 100644 --- a/libbindgen/tests/headers/anon_enum.hpp +++ b/libbindgen/tests/headers/anon_enum.hpp @@ -3,3 +3,8 @@ struct Test { float bar; enum { T_NONE }; }; + +typedef enum { + Foo, + Bar, +} Baz; diff --git a/libbindgen/tests/headers/inline-function.h b/libbindgen/tests/headers/inline-function.h new file mode 100644 index 00000000..02cb7c08 --- /dev/null +++ b/libbindgen/tests/headers/inline-function.h @@ -0,0 +1,6 @@ +// bindgen-unstable + +/** The point of this test is to _not_ generate these functions. */ + +inline static int myadd(const int x, const int y) { return x + y; } +static int mysub(const int x, const int y) { return x - y; } diff --git a/libbindgen/tests/headers/variadic-method.hpp b/libbindgen/tests/headers/variadic-method.hpp new file mode 100644 index 00000000..78a8eb45 --- /dev/null +++ b/libbindgen/tests/headers/variadic-method.hpp @@ -0,0 +1,6 @@ + +void foo(const char* fmt, ...); + +struct Bar { + void foo(const char* fmt, ...); +}; |