Skip to content

Commit

Permalink
feat: Simplify Box<T> to *T for C only.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan authored and emilio committed Sep 29, 2020
1 parent eefce50 commit 4ce324c
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 0 deletions.
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() =>
{
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>) {}

0 comments on commit 4ce324c

Please sign in to comment.