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

Simplify Pin<T> to T #697

Merged
merged 1 commit into from
Jun 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ cbindgen contains the following hardcoded mappings (again completely ignoring na
* PhantomData => *evaporates*, can only appear as the field of a type
* PhantomPinned => *evaporates*, can only appear as the field of a type
* () => *evaporates*, can only appear as the field of a type
* MaybeUninit<T>, ManuallyDrop<T>, and Pin<T> => T




Expand Down
2 changes: 1 addition & 1 deletion src/bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ impl Type {
is_ref: false,
}),
"Cell" => Some(generic.into_owned()),
"ManuallyDrop" | "MaybeUninit" if config.language != Language::Cxx => {
"ManuallyDrop" | "MaybeUninit" | "Pin" if config.language != Language::Cxx => {
Some(generic.into_owned())
}
_ => None,
Expand Down
27 changes: 27 additions & 0 deletions tests/expectations/pin.both.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if 0
''' '
#endif

#ifdef __cplusplus
template <typename T>
using Pin = T;
template <typename T>
using Box = T*;
#endif

#if 0
' '''
#endif


#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct PinTest {
int32_t *pinned_box;
int32_t *pinned_ref;
} PinTest;

void root(int32_t *s, struct PinTest p);
35 changes: 35 additions & 0 deletions tests/expectations/pin.both.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#if 0
''' '
#endif

#ifdef __cplusplus
template <typename T>
using Pin = T;
template <typename T>
using Box = T*;
#endif

#if 0
' '''
#endif


#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct PinTest {
int32_t *pinned_box;
int32_t *pinned_ref;
} PinTest;

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

void root(int32_t *s, struct PinTest p);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
27 changes: 27 additions & 0 deletions tests/expectations/pin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if 0
''' '
#endif

#ifdef __cplusplus
template <typename T>
using Pin = T;
template <typename T>
using Box = T*;
#endif

#if 0
' '''
#endif


#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct {
int32_t *pinned_box;
int32_t *pinned_ref;
} PinTest;

void root(int32_t *s, PinTest p);
35 changes: 35 additions & 0 deletions tests/expectations/pin.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#if 0
''' '
#endif

#ifdef __cplusplus
template <typename T>
using Pin = T;
template <typename T>
using Box = T*;
#endif

#if 0
' '''
#endif


#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct {
int32_t *pinned_box;
int32_t *pinned_ref;
} PinTest;

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

void root(int32_t *s, PinTest p);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
32 changes: 32 additions & 0 deletions tests/expectations/pin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#if 0
''' '
#endif

#ifdef __cplusplus
template <typename T>
using Pin = T;
template <typename T>
using Box = T*;
#endif

#if 0
' '''
#endif


#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

struct PinTest {
Pin<Box<int32_t>> pinned_box;
Pin<int32_t*> pinned_ref;
};

extern "C" {

void root(Pin<int32_t*> s, PinTest p);

} // extern "C"
29 changes: 29 additions & 0 deletions tests/expectations/pin.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#if 0
''' '
#endif

#ifdef __cplusplus
template <typename T>
using Pin = T;
template <typename T>
using Box = T*;
#endif

#if 0
' '''
#endif


from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list

cdef extern from *:

ctypedef struct PinTest:
int32_t *pinned_box;
int32_t *pinned_ref;

void root(int32_t *s, PinTest p);
27 changes: 27 additions & 0 deletions tests/expectations/pin.tag.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if 0
''' '
#endif

#ifdef __cplusplus
template <typename T>
using Pin = T;
template <typename T>
using Box = T*;
#endif

#if 0
' '''
#endif


#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

struct PinTest {
int32_t *pinned_box;
int32_t *pinned_ref;
};

void root(int32_t *s, struct PinTest p);
35 changes: 35 additions & 0 deletions tests/expectations/pin.tag.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#if 0
''' '
#endif

#ifdef __cplusplus
template <typename T>
using Pin = T;
template <typename T>
using Box = T*;
#endif

#if 0
' '''
#endif


#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

struct PinTest {
int32_t *pinned_box;
int32_t *pinned_ref;
};

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

void root(int32_t *s, struct PinTest p);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
29 changes: 29 additions & 0 deletions tests/expectations/pin.tag.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#if 0
''' '
#endif

#ifdef __cplusplus
template <typename T>
using Pin = T;
template <typename T>
using Box = T*;
#endif

#if 0
' '''
#endif


from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list

cdef extern from *:

cdef struct PinTest:
int32_t *pinned_box;
int32_t *pinned_ref;

void root(int32_t *s, PinTest p);
8 changes: 8 additions & 0 deletions tests/rust/pin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[repr(C)]
struct PinTest {
pinned_box: Pin<Box<i32>>,
pinned_ref: Pin<&mut i32>
}

#[no_mangle]
pub extern "C" fn root(s: Pin<&mut i32>, p: PinTest) {}
21 changes: 21 additions & 0 deletions tests/rust/pin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
header = """
#if 0
''' '
#endif

#ifdef __cplusplus
template <typename T>
using Pin = T;
template <typename T>
using Box = T*;
#endif

#if 0
' '''
#endif
"""
[export]
exclude = [
"Pin",
"Box"
]