Skip to content

Commit

Permalink
Add support for transparent and packed(N) types
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Jun 30, 2019
1 parent 81bae5a commit 6e1f066
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Automated tests of FFI bindings.
"""

[dependencies]
syntex_syntax2 = "0.0.1"
syntex_syntax2 = "0.0.2"
cc = "1.0.1"
rustc_version = "0.2"

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,7 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
let is_c = i.attrs.iter().any(|a| {
attr::find_repr_attrs(self.sh, a)
.iter()
.any(|a| *a == ReprAttr::ReprExtern /*|| *a == ReprAttr::ReprTransparent*/)
.any(|a| *a == ReprAttr::ReprExtern || *a == ReprAttr::ReprTransparent)
});
if !is_c && !(self.opts.skip_struct)(&i.ident.to_string()) {
panic!("{} is not marked #[repr(C)]", i.ident);
Expand Down
2 changes: 2 additions & 0 deletions testcrate/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn main() {
.fn_cname(|a, b| b.unwrap_or(a).to_string())
.type_name(move |ty, is_struct, is_union| match ty {
"T1Union" => ty.to_string(),
"Transparent" => ty.to_string(),
t if is_struct => format!("struct {}", t),
t if is_union => format!("union {}", t),
t => t.to_string(),
Expand All @@ -46,6 +47,7 @@ fn main() {
.fn_cname(|a, b| b.unwrap_or(a).to_string())
.type_name(move |ty, is_struct, is_union| match ty {
"T1Union" => ty.to_string(),
"Transparent" => ty.to_string(),
t if is_struct => format!("struct {}", t),
t if is_union => format!("union {}", t),
t => t.to_string(),
Expand Down
1 change: 1 addition & 0 deletions testcrate/src/t1.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void T1o(int32_t (*a)[4]);
void T1p(int32_t (*const a)[4]);

typedef int32_t (Arr)[4];
typedef int32_t Transparent;

void T1r(Arr a);
void T1s(const Arr a);
Expand Down
4 changes: 2 additions & 2 deletions testcrate/src/t1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pub struct T1StructWithUnion {
pub u: T1NoTypedefUnion,
}

// #[repr(transparent)]
// pub struct Transparent(i32);
#[repr(transparent)]
pub struct Transparent(i32);

pub type T1TypedefDouble = c_double;
pub type T1TypedefPtr = *mut c_int;
Expand Down

0 comments on commit 6e1f066

Please sign in to comment.