Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support ManuallyDrop, MaybeUninit and Box as simplified types for C only #578

Closed
wants to merge 10 commits into from
10 changes: 10 additions & 0 deletions src/bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the swift_name_macro check is not correct... Can you elaborate on why you added it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure it was correct. I had no idea what swift_name_macro is used for!

{
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,
Expand Down
16 changes: 16 additions & 0 deletions tests/expectations/both/box.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

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);
24 changes: 24 additions & 0 deletions tests/expectations/both/box.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

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
16 changes: 16 additions & 0 deletions tests/expectations/box.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

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);
24 changes: 24 additions & 0 deletions tests/expectations/box.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

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
16 changes: 16 additions & 0 deletions tests/expectations/tag/box.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

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);
24 changes: 24 additions & 0 deletions tests/expectations/tag/box.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

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
16 changes: 16 additions & 0 deletions tests/rust/box.skip_cpp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[repr(C)]
pub struct MyStruct {
number: Box<i32>,
}

pub struct NotReprC<T> {
inner: T,
}

pub type Foo = NotReprC<Box<i32>>;

#[no_mangle]
pub extern "C" fn root(a: &Foo, with_box: &MyStruct) {}

#[no_mangle]
pub extern "C" fn delete(x: Box<i32>) {}