Skip to content
Closed
2 changes: 1 addition & 1 deletion src/bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ impl Type {
is_nullable: false,
is_ref: false,
}),
"Cell" => Some(generic),
"Cell" | "ManuallyDrop" | "MaybeUninit" => Some(generic),
_ => None,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/bindgen/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ impl Parse {
add_opaque("BTreeSet", vec!["T"]);
add_opaque("LinkedList", vec!["T"]);
add_opaque("VecDeque", vec!["T"]);
add_opaque("ManuallyDrop", vec!["T"]);
add_opaque("MaybeUninit", vec!["T"]);
}

pub fn extend_with(&mut self, other: &Parse) {
Expand Down
21 changes: 21 additions & 0 deletions tests/expectations/both/manuallydrop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_ManuallyDrop_Point NotReprC_ManuallyDrop_Point;

typedef NotReprC_ManuallyDrop_Point Foo;

typedef struct Point {
int32_t x;
int32_t y;
} Point;

typedef struct MyStruct {
Point point;
} MyStruct;

void root(const Foo *a, const MyStruct *with_manual_drop);

void take(Point with_manual_drop);
29 changes: 29 additions & 0 deletions tests/expectations/both/manuallydrop.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_ManuallyDrop_Point NotReprC_ManuallyDrop_Point;

typedef NotReprC_ManuallyDrop_Point Foo;

typedef struct Point {
int32_t x;
int32_t y;
} Point;

typedef struct MyStruct {
Point point;
} MyStruct;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(const Foo *a, const MyStruct *with_manual_drop);

void take(Point with_manual_drop);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
14 changes: 14 additions & 0 deletions tests/expectations/both/maybeuninit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_MaybeUninit______i32 NotReprC_MaybeUninit______i32;

typedef NotReprC_MaybeUninit______i32 Foo;

typedef struct MyStruct {
const int32_t *number;
} MyStruct;

void root(const Foo *a, const MyStruct *with_maybe_uninit);
22 changes: 22 additions & 0 deletions tests/expectations/both/maybeuninit.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_MaybeUninit______i32 NotReprC_MaybeUninit______i32;

typedef NotReprC_MaybeUninit______i32 Foo;

typedef struct MyStruct {
const int32_t *number;
} MyStruct;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(const Foo *a, const MyStruct *with_maybe_uninit);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
21 changes: 21 additions & 0 deletions tests/expectations/manuallydrop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_ManuallyDrop_Point NotReprC_ManuallyDrop_Point;

typedef NotReprC_ManuallyDrop_Point Foo;

typedef struct {
int32_t x;
int32_t y;
} Point;

typedef struct {
Point point;
} MyStruct;

void root(const Foo *a, const MyStruct *with_manual_drop);

void take(Point with_manual_drop);
29 changes: 29 additions & 0 deletions tests/expectations/manuallydrop.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_ManuallyDrop_Point NotReprC_ManuallyDrop_Point;

typedef NotReprC_ManuallyDrop_Point Foo;

typedef struct {
int32_t x;
int32_t y;
} Point;

typedef struct {
Point point;
} MyStruct;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(const Foo *a, const MyStruct *with_manual_drop);

void take(Point with_manual_drop);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
29 changes: 29 additions & 0 deletions tests/expectations/manuallydrop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <new>

template<typename T = void>
struct ManuallyDrop;

template<typename T = void>
struct NotReprC;

struct Point {
int32_t x;
int32_t y;
};

using Foo = NotReprC<ManuallyDrop<Point>>;

struct MyStruct {
Point point;
};

extern "C" {

void root(const Foo *a, const MyStruct *with_manual_drop);

void take(Point with_manual_drop);

} // extern "C"
14 changes: 14 additions & 0 deletions tests/expectations/maybeuninit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_MaybeUninit______i32 NotReprC_MaybeUninit______i32;

typedef NotReprC_MaybeUninit______i32 Foo;

typedef struct {
const int32_t *number;
} MyStruct;

void root(const Foo *a, const MyStruct *with_maybe_uninit);
22 changes: 22 additions & 0 deletions tests/expectations/maybeuninit.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_MaybeUninit______i32 NotReprC_MaybeUninit______i32;

typedef NotReprC_MaybeUninit______i32 Foo;

typedef struct {
const int32_t *number;
} MyStruct;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(const Foo *a, const MyStruct *with_maybe_uninit);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
22 changes: 22 additions & 0 deletions tests/expectations/maybeuninit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <new>

template<typename T = void>
struct MaybeUninit;

template<typename T = void>
struct NotReprC;

using Foo = NotReprC<MaybeUninit<const int32_t*>>;

struct MyStruct {
const int32_t *number;
};

extern "C" {

void root(const Foo *a, const MyStruct *with_maybe_uninit);

} // extern "C"
21 changes: 21 additions & 0 deletions tests/expectations/tag/manuallydrop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

struct NotReprC_ManuallyDrop_Point;

typedef struct NotReprC_ManuallyDrop_Point Foo;

struct Point {
int32_t x;
int32_t y;
};

struct MyStruct {
struct Point point;
};

void root(const Foo *a, const struct MyStruct *with_manual_drop);

void take(struct Point with_manual_drop);
29 changes: 29 additions & 0 deletions tests/expectations/tag/manuallydrop.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

struct NotReprC_ManuallyDrop_Point;

typedef struct NotReprC_ManuallyDrop_Point Foo;

struct Point {
int32_t x;
int32_t y;
};

struct MyStruct {
struct Point point;
};

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(const Foo *a, const struct MyStruct *with_manual_drop);

void take(struct Point with_manual_drop);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
14 changes: 14 additions & 0 deletions tests/expectations/tag/maybeuninit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

struct NotReprC_MaybeUninit______i32;

typedef struct NotReprC_MaybeUninit______i32 Foo;

struct MyStruct {
const int32_t *number;
};

void root(const Foo *a, const struct MyStruct *with_maybe_uninit);
22 changes: 22 additions & 0 deletions tests/expectations/tag/maybeuninit.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

struct NotReprC_MaybeUninit______i32;

typedef struct NotReprC_MaybeUninit______i32 Foo;

struct MyStruct {
const int32_t *number;
};

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void root(const Foo *a, const struct MyStruct *with_maybe_uninit);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
22 changes: 22 additions & 0 deletions tests/rust/manuallydrop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#[repr(C)]
pub struct Point {
x: i32,
y: i32,
}

#[repr(C)]
pub struct MyStruct {
point: std::mem::ManuallyDrop<Point>,
}

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

pub type Foo = NotReprC<std::mem::ManuallyDrop<Point>>;

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

#[no_mangle]
pub extern "C" fn take(with_manual_drop: std::mem::ManuallyDrop<Point>) {}
13 changes: 13 additions & 0 deletions tests/rust/maybeuninit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[repr(C)]
pub struct MyStruct {
number: std::mem::MaybeUninit<&i32>,
Comment thread
Hywan marked this conversation as resolved.
Outdated
}

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

pub type Foo = NotReprC<std::mem::MaybeUninit<&i32>>;
Comment thread
Hywan marked this conversation as resolved.
Outdated

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