File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -1946,6 +1946,8 @@ impl ConversionContext {
1946
1946
let name = expect_opt_str ( & node. extras [ 0 ] ) . unwrap ( ) . map ( str:: to_string) ;
1947
1947
let has_def = from_value ( node. extras [ 1 ] . clone ( ) )
1948
1948
. expect ( "Expected has_def flag on struct" ) ;
1949
+ let attrs = from_value :: < Vec < Value > > ( node. extras [ 2 ] . clone ( ) )
1950
+ . expect ( "Expected attribute array on record" ) ;
1949
1951
let fields: Option < Vec < CDeclId > > = if has_def {
1950
1952
Some (
1951
1953
node. children
@@ -1962,7 +1964,18 @@ impl ConversionContext {
1962
1964
None
1963
1965
} ;
1964
1966
1965
- let record = CDeclKind :: Union { name, fields } ;
1967
+ let mut is_packed = false ;
1968
+ for attr in attrs {
1969
+ match from_value :: < String > ( attr. clone ( ) )
1970
+ . expect ( "Records attributes should be strings" )
1971
+ . as_str ( )
1972
+ {
1973
+ "packed" => is_packed = true ,
1974
+ _ => { }
1975
+ }
1976
+ }
1977
+
1978
+ let record = CDeclKind :: Union { name, fields, is_packed } ;
1966
1979
1967
1980
self . add_decl ( new_id, located ( node, record) ) ;
1968
1981
self . processed_nodes . insert ( new_id, RECORD_DECL ) ;
Original file line number Diff line number Diff line change @@ -933,6 +933,7 @@ pub enum CDeclKind {
933
933
Union {
934
934
name : Option < String > ,
935
935
fields : Option < Vec < CFieldId > > ,
936
+ is_packed : bool ,
936
937
} ,
937
938
938
939
// Field
Original file line number Diff line number Diff line change @@ -1614,6 +1614,7 @@ impl<'c> Translation<'c> {
1614
1614
1615
1615
CDeclKind :: Union {
1616
1616
fields : Some ( ref fields) ,
1617
+ is_packed,
1617
1618
..
1618
1619
} => {
1619
1620
let name = self
@@ -1642,21 +1643,26 @@ impl<'c> Translation<'c> {
1642
1643
}
1643
1644
}
1644
1645
1646
+ let mut repr = vec ! [ "C" ] ;
1647
+ if is_packed {
1648
+ repr. push ( "packed" ) ;
1649
+ }
1650
+
1645
1651
Ok ( if field_syns. is_empty ( ) {
1646
1652
// Empty unions are a GNU extension, but Rust doesn't allow empty unions.
1647
1653
ConvertedDecl :: Item (
1648
1654
mk ( ) . span ( s)
1649
1655
. pub_ ( )
1650
1656
. call_attr ( "derive" , vec ! [ "Copy" , "Clone" ] )
1651
- . call_attr ( "repr" , vec ! [ "C" ] )
1657
+ . call_attr ( "repr" , repr )
1652
1658
. struct_item ( name, vec ! [ ] , false ) ,
1653
1659
)
1654
1660
} else {
1655
1661
ConvertedDecl :: Item (
1656
1662
mk ( ) . span ( s)
1657
1663
. pub_ ( )
1658
1664
. call_attr ( "derive" , vec ! [ "Copy" , "Clone" ] )
1659
- . call_attr ( "repr" , vec ! [ "C" ] )
1665
+ . call_attr ( "repr" , repr )
1660
1666
. union_item ( name, field_syns) ,
1661
1667
)
1662
1668
} )
You can’t perform that action at this time.
0 commit comments