Squashed 'third_party/autocxx/' changes from fdfb26e26..69eb3d8d2
69eb3d8d2 Merge pull request #1353 from EdmundGoodman/main
e0923cfdf Merge pull request #1354 from google/remove-unused-fields
b78edbaf0 Remove redundant fields.
585d5c1cd Add integration tests for functions taking array parameters
2f84e49f2 Merge pull request #1352 from google/clippy-5
efa122b50 More clippy fixes.
4eeeeb873 Further fix.
d6bf45456 Clippy fix.
d223b2f4a Merge pull request #1345 from google/allow-unused
2dcdff106 Merge pull request #1344 from google/missing-headers
5dd9a002d Fix unused import warnings.
f7bcbc75d Merge pull request #1338 from google/dependabot/cargo/rustix-0.37.25
65afd59d0 Add some missing headers.
ce7f49fd6 Merge pull request #1340 from google/fix-ci-probs
c9e274f68 Missing stdints.
2ebe0b557 Bump rustix from 0.37.23 to 0.37.25
6daf52209 Merge pull request #1335 from google/clippy-4
c25b46565 Clippy fix.
e8012a011 Merge pull request #1330 from google/subclass-opaque
2e8430026 Test for #1328.
762dbf397 Merge pull request #1324 from google/clippy5
c8e5e72d5 Merge pull request #1323 from google/fix-1318
354cec9f8 Clippy fixes.
2ef099dca Fix badly named alloc function - fixes #1318
b9550bda7 Merge pull request #1313 from google/bitfieldthing
748119f2c Merge branch 'main' of github.com:google/autocxx into bitfieldthing
366f3f430 Fix test.
a354a5d95 Better diagnostics on why these types are ignored.
b624e9cdc Adding diagnostics about bitfields.
648f47782 Add bitfield test kindly submitted for #1303
git-subtree-dir: third_party/autocxx
git-subtree-split: 69eb3d8d283c5cceb3829b5f200370353de2bd63
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
Change-Id: If2569977170bda9cda3ab3f3ee9ccbdc099ad9da
diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs
index 2335ee5..02d672f 100644
--- a/integration-tests/src/lib.rs
+++ b/integration-tests/src/lib.rs
@@ -459,7 +459,7 @@
let generated_rs_files = build_results.1;
if let Some(code_checker) = &rust_code_checker {
- let mut file = File::open(generated_rs_files.get(0).ok_or(TestError::NoRs)?)
+ let mut file = File::open(generated_rs_files.first().ok_or(TestError::NoRs)?)
.map_err(TestError::RsFileOpen)?;
let mut content = String::new();
file.read_to_string(&mut content)
diff --git a/integration-tests/tests/cpprefs_test.rs b/integration-tests/tests/cpprefs_test.rs
index 9cc6d39..820e67a 100644
--- a/integration-tests/tests/cpprefs_test.rs
+++ b/integration-tests/tests/cpprefs_test.rs
@@ -52,6 +52,7 @@
indoc! {"
#include <string>
#include <sstream>
+ #include <cstdint>
class Goat {
public:
@@ -80,6 +81,7 @@
indoc! {"
#include <string>
#include <sstream>
+ #include <cstdint>
class Goat {
public:
diff --git a/integration-tests/tests/integration_test.rs b/integration-tests/tests/integration_test.rs
index ec2b1e7..0939cae 100644
--- a/integration-tests/tests/integration_test.rs
+++ b/integration-tests/tests/integration_test.rs
@@ -4490,6 +4490,7 @@
fn test_typedef_to_std() {
let hdr = indoc! {"
#include <string>
+ #include <cstdint>
typedef std::string my_string;
inline uint32_t take_str(my_string a) {
return a.size();
@@ -4523,6 +4524,7 @@
fn test_typedef_in_pod_struct() {
let hdr = indoc! {"
#include <string>
+ #include <cstdint>
typedef uint32_t my_int;
struct A {
my_int a;
@@ -4544,6 +4546,7 @@
fn test_cint_in_pod_struct() {
let hdr = indoc! {"
#include <string>
+ #include <cstdint>
struct A {
int a;
};
@@ -4613,6 +4616,7 @@
fn test_typedef_to_std_in_struct() {
let hdr = indoc! {"
#include <string>
+ #include <cstdint>
typedef std::string my_string;
struct A {
my_string a;
@@ -4998,6 +5002,43 @@
}
#[test]
+fn test_take_struct_built_array_in_function() {
+ let hdr = indoc! {"
+ #include <cstdint>
+ struct data {
+ char a[4];
+ };
+ uint32_t take_array(char a[4]) {
+ return a[0] + a[2];
+ }
+ "};
+ let rs = quote! {
+ let mut c = ffi::data { a: [ 10, 20, 30, 40 ] };
+ unsafe {
+ assert_eq!(ffi::take_array(c.a.as_mut_ptr()), 40);
+ }
+ };
+ run_test("", hdr, rs, &["take_array"], &["data"]);
+}
+
+#[test]
+fn test_take_array_in_function() {
+ let hdr = indoc! {"
+ #include <cstdint>
+ uint32_t take_array(char a[4]) {
+ return a[0] + a[2];
+ }
+ "};
+ let rs = quote! {
+ let mut a: [i8; 4] = [ 10, 20, 30, 40 ];
+ unsafe {
+ assert_eq!(ffi::take_array(a.as_mut_ptr()), 40);
+ }
+ };
+ run_test("", hdr, rs, &["take_array"], &[]);
+}
+
+#[test]
fn test_union_ignored() {
let hdr = indoc! {"
#include <cstdint>
@@ -7772,6 +7813,58 @@
}
#[test]
+fn test_pv_subclass_opaque_param() {
+ let hdr = indoc! {"
+ #include <cstdint>
+
+ typedef uint32_t MyUnsupportedType[4];
+
+ struct MySupportedType {
+ uint32_t a;
+ };
+
+ class MySuperType {
+ public:
+ virtual void foo(const MyUnsupportedType* foo, const MySupportedType* bar) const = 0;
+ virtual ~MySuperType() = default;
+ };
+ "};
+ run_test_ex(
+ "",
+ hdr,
+ quote! {
+ MySubType::new_rust_owned(MySubType { a: 3, cpp_peer: Default::default() });
+ },
+ quote! {
+ subclass!("MySuperType",MySubType)
+ extern_cpp_opaque_type!("MyUnsupportedType", crate::ffi2::MyUnsupportedType)
+ },
+ None,
+ None,
+ Some(quote! {
+
+ #[cxx::bridge]
+ pub mod ffi2 {
+ unsafe extern "C++" {
+ include!("input.h");
+ type MyUnsupportedType;
+ }
+ }
+ use autocxx::subclass::CppSubclass;
+ use ffi::MySuperType_methods;
+ #[autocxx::subclass::subclass]
+ pub struct MySubType {
+ a: u32
+ }
+ impl MySuperType_methods for MySubType {
+ unsafe fn foo(&self, _foo: *const ffi2::MyUnsupportedType, _bar: *const ffi::MySupportedType) {
+ }
+ }
+ }),
+ );
+}
+
+#[test]
fn test_pv_subclass_return() {
let hdr = indoc! {"
#include <cstdint>
@@ -12241,6 +12334,58 @@
run_test("", hdr, rs, &["A"], &[]);
}
+#[test]
+fn test_badly_named_alloc() {
+ let hdr = indoc! {"
+ #include <stdarg.h>
+ class A {
+ public:
+ void alloc();
+ };
+ "};
+ let rs = quote! {};
+ run_test("", hdr, rs, &["A"], &[]);
+}
+
+#[test]
+fn test_cpp_union_pod() {
+ let hdr = indoc! {"
+ typedef unsigned long long UInt64_t;
+ struct ManagedPtr_t_;
+ typedef struct ManagedPtr_t_ ManagedPtr_t;
+
+ typedef int (*ManagedPtr_ManagerFunction_t)(
+ ManagedPtr_t *managedPtr,
+ const ManagedPtr_t *srcPtr,
+ int operation);
+
+ typedef union {
+ int intValue;
+ void *ptr;
+ } ManagedPtr_t_data_;
+
+ struct ManagedPtr_t_ {
+ void *pointer;
+ ManagedPtr_t_data_ userData[4];
+ ManagedPtr_ManagerFunction_t manager;
+ };
+
+ typedef struct CorrelationId_t_ {
+ unsigned int size : 8;
+ unsigned int valueType : 4;
+ unsigned int classId : 16;
+ unsigned int reserved : 4;
+
+ union {
+ UInt64_t intValue;
+ ManagedPtr_t ptrValue;
+ } value;
+ } CorrelationId_t;
+ "};
+ run_test("", hdr, quote! {}, &["CorrelationId_t_"], &[]);
+ run_test_expect_fail("", hdr, quote! {}, &[], &["CorrelationId_t_"]);
+}
+
// Yet to test:
// - Ifdef
// - Out param pointers