Commit Graph

765 Commits

Author SHA1 Message Date
Emilio Cobos Álvarez
4faaf9a5f3 codegen: Deal with overloads in method code generation.
Fixes #2019
2021-04-03 13:05:04 +02:00
Emilio Cobos Álvarez
b21086cc3b codegen: Don't use a sym temporary in dynamic library code.
Fixes #2014.
2021-04-03 13:05:04 +02:00
Dr. Chat
2c5a1ea6b1 Add a flag to ensure all symbols are resolved when a library is loaded 2021-04-03 12:24:15 +02:00
Emilio Cobos Álvarez
de94b48756
Merge pull request #2007 from jethrogb/jb/issue-1454-alt
Add callback to check derives for blocklisted types
2021-03-22 20:07:03 +01:00
Wang, Chi
5a055fde1d
Add from_library for generated dynamic library structs (#2011) 2021-03-22 20:04:59 +01:00
Jethro Beekman
0780f804a8 Add callback to check derives for blocklisted types
Fixes #1454 #2003
2021-03-22 12:10:28 +01:00
Jethro Beekman
2a46e29242 Use original name when checking allowlist for anonymous enum variants 2021-03-22 12:05:11 +01:00
Jethro Beekman
af98fd47c7 Add test infrastructure for ParseCallbacks 2021-03-22 12:05:11 +01:00
Jethro Beekman
dedbea5bc0 Add option to translate enum integer types to native Rust integer types
Fixes #430
2021-03-14 09:37:26 +01:00
Emilio Cobos Álvarez
fb931bd6c1
Revert "Add flag to ignore type blocklist when computing derive information"
This reverts commit 7286c815f8, because it
was not intended to be merged after all, see
https://github.com/rust-lang/rust-bindgen/pull/2003#issuecomment-796160427.
2021-03-11 12:52:18 +01:00
Jethro Beekman
7286c815f8 Add flag to ignore type blocklist when computing derive information
Fixes #1454
2021-03-11 12:36:52 +01:00
Jethro Beekman
af87a859ac Fix typo in roundtrip test error message 2021-03-11 12:36:52 +01:00
Marcel Hlopko
0e25962c4e Rename whitelist -> allowlist and blacklist -> blocklist
For the commandline arguments I added undocumented aliases to old flags,
to stay backwards compatible.
2021-02-18 17:25:13 +01:00
Emilio Cobos Álvarez
e59aa9218b tests: Guess modern libclang version when we fail to parse a version.
Should fix the test failures described in #1991 and #1975 on modern Mac.
2021-02-15 14:06:29 +01:00
Emilio Cobos Álvarez
8ac787a9b4 codegen: Track union layout more accurately.
Instead of always generating the _bindgen_union_align method (which
shouldn't be needed at all for Rust structs, since the struct layout
tracker already deals with adding repr(align) as necessary) make sure to
visit all fields appropriately to generate the correct alignment.
2021-02-07 23:10:28 +01:00
Weston Carvalho
e0f06c7fb2 Generate fields as non-pub if they would be access restricted in C++. 2021-01-29 13:18:25 +01:00
Andrey Pushkar
51778893c4
Use absolute paths for unsaved files passed to clang and prepend -include directives to them.
Fixes #1771
Closes #1857
2021-01-10 15:39:20 +01:00
Emilio Cobos Álvarez
fde75f68e7 ci: Switch most CI to GitHub actions. 2020-12-26 19:01:53 +01:00
Emilio Cobos Álvarez
669dc1b628 comp: Fix bitfields to allow underaligned fields after them to take padding space.
Fixes #1947.

There are two separate issues here: First, the change in comp.rs ensures
that we don't round up the amount of storage to the alignment of the
bitfield. That generates the "expected" output in #1947
(`__BindgenBitfieldUnit<[u8; 3], u16>`).

But that's still not enough to fix that test-case because
__BindgenBitfieldUnit would be aligned and have padding, and Rust won't
put the extra field in the padding.

In order to ensure the bitfield starts at the right alignment, but that
Rust can put stuff in the extra field, we need to make a breaking change
and split the generated fields in two: One preceding that guarantees
alignment, and the actual storage, bit-aligned.

This keeps the existing behavior while fixing that test-case.
2020-12-20 21:29:47 +01:00
Emilio Cobos Álvarez
98841b32ed context: Escape the dyn keyword properly.
Fixes #1946
2020-12-20 20:36:03 +01:00
Emilio Cobos Álvarez
4ce4b934fd tests: Add another fit-macro-constant-types test. 2020-12-19 19:28:24 +01:00
Antoni Simka
ea4164c85c Add option to fit macro consts into smaller types
Add a `--fit-macro-constant-types` option to make bindgen try to fit
macro integer constants into types smaller than u32/i32.
Useful especially when dealing with 8/16-bit architectures.

Closes #1945
2020-12-19 19:28:24 +01:00
Emilio Cobos Álvarez
caec44a0b4 dyngen: Pass null-terminated byte strings to libloading.
Fixes #1938.
2020-12-02 12:00:38 +01:00
Emilio Cobos Álvarez
460ae847d2 cli: Expose module_raw_lines to the CLI.
This makes command_line_args properly return them, instead of dropping
them on the floor.
2020-12-02 01:08:05 +01:00
Emilio Cobos Álvarez
19142ac6b3 struct_layout: Fix field offset computation for packed(n) structs.
This can cause unnecessary padding to be computed otherwise at the end
of the struct.

With repr(packed(n)), a field can have padding to adjacent fields as
long as its alignment is less than n. So reuse the code we have to align
to a field layout, aligning to the struct layout instead.

Fixes #1934
2020-11-28 03:14:51 +01:00
Varphone Wong
d8082613e2 Add --no-default <regex> flag
Sometimes, we need customize the implement of `Default` for certain types,
In these cases, the `nodefault` annotation can be used to prevent bindgen
to autoderive the `Default` traits for a type.
2020-11-26 11:12:02 +01:00
Emilio Cobos Álvarez
01cbe44683 dyngen: Handle variadic functions.
Right now trying to generate a dynamic library with variadic functions
panics because we don't account for the extra `...` in the arguments.

Keeping the current interface for variadic functions is tricky, as we
cannot "wrap" a variadic function (VaList[1] is nightly-only).

However, we don't need to. We're already exposing the libloading error,
so exposing the function pointer field as public is just fine and allows
consumers to call the variadic function.

At that point the can_call() / CheckFoo libraries become pointless (you
can just do library.function.is_ok() or such), so we can simplify the
code as well removing those.

[1]: https://doc.rust-lang.org/std/ffi/struct.VaList.html
2020-11-25 17:25:49 +01:00
Joe Ellis
c2b5c46ef4
Add tests for dynamic binding generation 2020-11-25 14:39:31 +01:00
Volker Weißmann
db3d170d3b tests: Added option to hand check test differences. 2020-11-25 14:33:05 +01:00
Emilio Cobos Álvarez
84b5455f88
Keep dependencies up-to-date.
A few tests change some formatting, but that's fine.
2020-11-13 20:02:30 +01:00
Emilio Cobos Álvarez
a467d3efc6 codegen: Allow to not derive Debug on enums.
Fixes #1899.

This code predated all the derive machinery, and always hardcoded its
derives.

We could avoid hard-coding the other traits, but those seem
usually-useful, so leave them there for backwards compat for now.
2020-10-16 12:12:17 +02:00
Sebastian Imlay
4f714ab79e Fix test for CI 2020-09-16 12:26:24 +02:00
Sebastian Imlay
4a51c4552c Update to fix CI 2020-09-16 12:26:24 +02:00
Sebastian Imlay
59a4c18b17 Updates for CI 2020-09-16 12:26:24 +02:00
Sebastian Imlay
d4e84650c8 Updates from PR comments 2020-09-16 12:26:24 +02:00
Sebastian Imlay
0dff6d65d5 Fix spacing issue 2020-09-16 12:26:24 +02:00
Sebastian Imlay
c24626993d First attempt to fix CI 2020-09-16 12:26:24 +02:00
Sebastian Imlay
81d323d8b1 Updates base on comments
* Added TryInto trait implementation from parent to child interfaces.
* Added HashSet for protocols so that the protocol inheritance works as
well.
2020-09-16 12:26:24 +02:00
Sebastian Imlay
840b738ecf Initial stuff for changing ownership and adding inheritance 2020-09-16 12:26:24 +02:00
Emilio Cobos Álvarez
4608a11b5c
Added constructor return type for wasm32 target (#1877) 2020-08-25 02:15:18 +02:00
Emilio Cobos Álvarez
428189cb41 tests: Improve enum tests to avoid duplication, and add a test for #1880 2020-08-25 00:38:57 +02:00
Audrius
d446a4f6f1 Added expectation test files for clang 3.9 and 4 2020-08-24 21:50:18 +03:00
Audrius
b1cefe2395 Optimized condition order, added regression test 2020-08-24 16:29:43 +03:00
Sebastian Imlay
4299255c8a Added Bindgen names to objective-c pointer return types
* Took advantage of the repr transparent to use Bindgen return type
  names.
* Updated unit tests and book
2020-08-15 13:56:25 +02:00
Chih-Hung Hsieh
53290e8f35 Add --default-macro-constant-type
* --default-macro-constant-type could be 'signed' or 'unsigned'
  * Its default value is 'unsigned' to use u32/u64
    for C macro constants that fit into the u32/u64 ranges.
  * For old C libraries that use macros as int/long parameter
    and/or return value types, their macros are better declared
    as i32/i64 if the values fit the i32/i64 ranges,
    to be compatible with c_int/c_long types.
    They can use "--default-macro-constant-type signed"
2020-08-09 13:01:46 +02:00
Varphone Wong
dfeff8992e Add --anon-fields-prefix option
Allow to use the given prefix for the anon fields instead of `__bindgen_anon_`.
2020-08-04 12:08:11 +02:00
Joseph Angelo
87b2bc033f Fixed const-ness of multidimensional arrays 2020-08-04 12:06:02 +02:00
Emilio Cobos Álvarez
48808ed9d3 tests: Add a test for bool enum with an alias. 2020-08-03 20:17:57 +02:00
Varphone Wong
ff3698189c Add --no-debug <regex> flag 2020-08-03 18:29:07 +02:00
Cameron Mulhern
f56fbcef78 Improves bindings for typed and anonymous enums 2020-08-03 18:11:57 +02:00