Skip to content

Commit

Permalink
Merge pull request #86 from ZettaScaleLabs/v36.1.1-rc5
Browse files Browse the repository at this point in the history
Refine repr support
  • Loading branch information
p-avital authored Jul 6, 2024
2 parents caeccb0 + d99de71 commit c71e794
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 36.1.1-rc5 (api=2.0.0, abi=2.0.0)
- Refine support for `#[repr(transparent)]` and `#[repr(align(n))]` in `#[stabby::stabby]` structs up to n=64kiB.

# 36.1.1-rc4 (api=2.0.0, abi=2.0.0)
- Add support for `#[repr(transparent)]` and `#[repr(align(n))]` in `#[stabby::stabby]` structs up to n=64kiB.

Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ license = " EPL-2.0 OR Apache-2.0"
categories = ["development-tools::ffi", "no-std::no-alloc"]
repository = "https://github.com/ZettaScaleLabs/stabby"
readme = "stabby/README.md"
version = "36.1.1-rc4" # Track
version = "36.1.1-rc5" # Track

[workspace.dependencies]
stabby-macros = { path = "./stabby-macros/", version = "36.1.1-rc4", default-features = false } # Track
stabby-abi = { path = "./stabby-abi/", version = "36.1.1-rc4", default-features = false } # Track
stabby = { path = "./stabby/", version = "36.1.1-rc4", default-features = false } # Track
stabby-macros = { path = "./stabby-macros/", version = "36.1.1-rc5", default-features = false } # Track
stabby-abi = { path = "./stabby-abi/", version = "36.1.1-rc5", default-features = false } # Track
stabby = { path = "./stabby/", version = "36.1.1-rc5", default-features = false } # Track

abi_stable = "0.11.0"
libc = "0.2"
Expand Down
28 changes: 13 additions & 15 deletions stabby-macros/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,15 @@ pub fn stabby(
let clauses = where_clause.as_ref().map(|w| &w.predicates);
let mut layout = None;
let mut report = crate::Report::r#struct(ident.to_string(), version, module);
let repr = attrs
.iter()
.find_map(|attr| {
if attr.path.is_ident("repr") {
syn::parse2::<AllowedRepr>(attr.tokens.clone()).ok()
} else {
None
}
})
.unwrap_or(AllowedRepr::C);
optimize &= !matches!(repr, AllowedRepr::Align(_));
let repr = attrs.iter().find_map(|attr| {
if attr.path.is_ident("repr") {
syn::parse2::<AllowedRepr>(attr.tokens.clone()).ok()
} else {
None
}
});
let repr_attr = repr.is_none().then(|| quote! {#[repr(C)]});
optimize &= !matches!(repr, Some(AllowedRepr::Align(_)));
let struct_code = match &fields {
syn::Fields::Named(fields) => {
let fields = &fields.named;
Expand All @@ -146,7 +144,7 @@ pub fn stabby(
}
quote! {
#(#attrs)*
#repr
#repr_attr
#vis struct #ident #generics #where_clause {
#fields
}
Expand All @@ -164,22 +162,22 @@ pub fn stabby(
}
quote! {
#(#attrs)*
#repr
#repr_attr
#vis struct #ident #generics #where_clause (#fields);
}
}
syn::Fields::Unit => {
quote! {
#(#attrs)*
#repr
#repr_attr
#vis struct #ident #generics #where_clause;
}
}
};
let layout = layout.map_or_else(
|| quote!(()),
|layout| {
if let AllowedRepr::Align(mut n) = repr {
if let Some(AllowedRepr::Align(mut n)) = repr {
let mut align = quote!(#st::U1);
while n > 1 {
n /= 2;
Expand Down
8 changes: 8 additions & 0 deletions stabby/src/tests/layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ pub struct EndPadding {
a: usize,
b: u8,
}
#[allow(dead_code)]
#[stabby::stabby]
#[repr(transparent)]
pub struct Transparent {
a: usize,
}

#[test]
fn layouts() {
Expand Down Expand Up @@ -255,6 +261,8 @@ fn layouts() {
3 * 16
);
let _ = Align1024::ID;
let _: U1024 = <Align1024 as IStable>::Align::default();
let _: U1024 = <Align1024 as IStable>::Size::default();
}

#[allow(dead_code)]
Expand Down

0 comments on commit c71e794

Please sign in to comment.