diff --git a/src/bindgen/ir/ty.rs b/src/bindgen/ir/ty.rs index 63e7d71b8..a95c41303 100644 --- a/src/bindgen/ir/ty.rs +++ b/src/bindgen/ir/ty.rs @@ -433,6 +433,16 @@ impl Type { is_nullable: false, is_ref: false, }), + "Box" + if config.language == Language::C && config.function.swift_name_macro.is_none() => + { + Some(Type::Ptr { + ty: Box::new(generic), + is_const: false, + is_nullable: false, + is_ref: false, + }) + } "Cell" => Some(generic), "ManuallyDrop" | "MaybeUninit" if config.language == Language::C => Some(generic), _ => None, diff --git a/tests/expectations/both/box.c b/tests/expectations/both/box.c new file mode 100644 index 000000000..6468f86ed --- /dev/null +++ b/tests/expectations/both/box.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +typedef struct NotReprC_Box_i32 NotReprC_Box_i32; + +typedef NotReprC_Box_i32 Foo; + +typedef struct MyStruct { + int32_t *number; +} MyStruct; + +void delete(int32_t *x); + +void root(const Foo *a, const MyStruct *with_box); diff --git a/tests/expectations/both/box.compat.c b/tests/expectations/both/box.compat.c new file mode 100644 index 000000000..31f5d7a8f --- /dev/null +++ b/tests/expectations/both/box.compat.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +typedef struct NotReprC_Box_i32 NotReprC_Box_i32; + +typedef NotReprC_Box_i32 Foo; + +typedef struct MyStruct { + int32_t *number; +} MyStruct; + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +void delete(int32_t *x); + +void root(const Foo *a, const MyStruct *with_box); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/tests/expectations/box.c b/tests/expectations/box.c new file mode 100644 index 000000000..967f4b7fe --- /dev/null +++ b/tests/expectations/box.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +typedef struct NotReprC_Box_i32 NotReprC_Box_i32; + +typedef NotReprC_Box_i32 Foo; + +typedef struct { + int32_t *number; +} MyStruct; + +void delete(int32_t *x); + +void root(const Foo *a, const MyStruct *with_box); diff --git a/tests/expectations/box.compat.c b/tests/expectations/box.compat.c new file mode 100644 index 000000000..4a31ac943 --- /dev/null +++ b/tests/expectations/box.compat.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +typedef struct NotReprC_Box_i32 NotReprC_Box_i32; + +typedef NotReprC_Box_i32 Foo; + +typedef struct { + int32_t *number; +} MyStruct; + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +void delete(int32_t *x); + +void root(const Foo *a, const MyStruct *with_box); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/tests/expectations/tag/box.c b/tests/expectations/tag/box.c new file mode 100644 index 000000000..1667e37b2 --- /dev/null +++ b/tests/expectations/tag/box.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +struct NotReprC_Box_i32; + +typedef struct NotReprC_Box_i32 Foo; + +struct MyStruct { + int32_t *number; +}; + +void delete(int32_t *x); + +void root(const Foo *a, const struct MyStruct *with_box); diff --git a/tests/expectations/tag/box.compat.c b/tests/expectations/tag/box.compat.c new file mode 100644 index 000000000..3bf1324ec --- /dev/null +++ b/tests/expectations/tag/box.compat.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +struct NotReprC_Box_i32; + +typedef struct NotReprC_Box_i32 Foo; + +struct MyStruct { + int32_t *number; +}; + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +void delete(int32_t *x); + +void root(const Foo *a, const struct MyStruct *with_box); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/tests/rust/box.skip_cpp.rs b/tests/rust/box.skip_cpp.rs new file mode 100644 index 000000000..11cc49aef --- /dev/null +++ b/tests/rust/box.skip_cpp.rs @@ -0,0 +1,16 @@ +#[repr(C)] +pub struct MyStruct { + number: Box, +} + +pub struct NotReprC { + inner: T, +} + +pub type Foo = NotReprC>; + +#[no_mangle] +pub extern "C" fn root(a: &Foo, with_box: &MyStruct) {} + +#[no_mangle] +pub extern "C" fn delete(x: Box) {}