@@ -6,21 +6,36 @@ use std::io::prelude::*;
66use std:: io:: { Read , Seek , Write } ;
77use std:: os:: fd:: AsFd ;
88use std:: rc:: { Rc , Weak } ;
9+ #[ repr( C ) ]
910#[ derive( Default ) ]
1011pub struct NonCopy {
11- pub data : Value < Vec < i32 > > ,
12- pub tag : Value < i32 > ,
12+ pub data : Vec < i32 > ,
13+ pub tag : i32 ,
1314}
1415impl Clone for NonCopy {
1516 fn clone ( & self ) -> Self {
1617 let mut this = Self {
17- data : Rc :: new ( RefCell :: new ( ( * self . data . borrow ( ) ) . clone ( ) ) ) ,
18- tag : Rc :: new ( RefCell :: new ( ( * self . tag . borrow ( ) ) ) ) ,
18+ data : ( self . data ) . clone ( ) ,
19+ tag : self . tag ,
1920 } ;
2021 this
2122 }
2223}
23- impl ByteRepr for NonCopy { }
24+ impl ByteRepr for NonCopy {
25+ fn byte_size ( ) -> usize {
26+ 32
27+ }
28+ fn to_bytes ( & self , buf : & mut [ u8 ] ) {
29+ self . data . to_bytes ( & mut buf[ 0 ..24 ] ) ;
30+ self . tag . to_bytes ( & mut buf[ 24 ..28 ] ) ;
31+ }
32+ fn from_bytes ( buf : & [ u8 ] ) -> Self {
33+ Self {
34+ data : <Vec < i32 > >:: from_bytes ( & buf[ 0 ..24 ] ) ,
35+ tag : <i32 >:: from_bytes ( & buf[ 24 ..28 ] ) ,
36+ }
37+ }
38+ }
2439pub fn main ( ) {
2540 std:: process:: exit ( main_0 ( ) ) ;
2641}
@@ -30,17 +45,21 @@ fn main_0() -> i32 {
3045 . map ( |_| <NonCopy >:: default ( ) )
3146 . collect :: < Box < [ NonCopy ] > > ( ) ,
3247 ) ) ;
33- ( * ( * arr. borrow ( ) ) [ ( 0 ) as usize ] . tag . borrow_mut ( ) ) = 7 ;
34- ( * ( * arr. borrow ( ) ) [ ( 1 ) as usize ] . data . borrow_mut ( ) ) . push ( 42 ) ;
35- assert ! ( ( ( * ( * arr. borrow( ) ) [ ( 0 ) as usize ] . tag. borrow ( ) ) == 7 ) ) ;
36- assert ! ( ( ( * ( * arr. borrow( ) ) [ ( 1 ) as usize ] . data. borrow ( ) ) . len( ) == 1_usize ) ) ;
48+ ( * arr. borrow_mut ( ) ) [ ( 0 ) as usize ] . tag = 7 ;
49+ ( * arr. borrow_mut ( ) ) [ ( 1 ) as usize ] . data . push ( 42 ) ;
50+ assert ! ( ( ( * arr. borrow( ) ) [ ( 0 ) as usize ] . tag == 7 ) ) ;
51+ assert ! ( ( ( * arr. borrow( ) ) [ ( 1 ) as usize ] . data. len( ) == 1_usize ) ) ;
3752 assert ! (
38- ( ( ( ( * arr. borrow( ) ) [ ( 1 ) as usize ] . data. as_pointer( ) as Ptr <i32 >)
53+ ( ( ( ( arr. as_pointer( ) as Ptr <NonCopy >) . offset( 1 ) . field_ptr(
54+ 0 ,
55+ |__v: & NonCopy | & __v. data[ ..] ,
56+ |__v: & mut NonCopy | & mut __v. data[ ..]
57+ ) as Ptr <i32 >)
3958 . offset( 0_usize )
4059 . read( ) )
4160 == 42 )
4261 ) ;
43- assert ! ( ( ( * ( * arr. borrow( ) ) [ ( 2 ) as usize ] . tag. borrow ( ) ) == 0 ) ) ;
44- assert ! ( ( ( * ( * arr. borrow( ) ) [ ( 2 ) as usize ] . data. borrow ( ) ) . len( ) == 0_usize ) ) ;
62+ assert ! ( ( ( * arr. borrow( ) ) [ ( 2 ) as usize ] . tag == 0 ) ) ;
63+ assert ! ( ( ( * arr. borrow( ) ) [ ( 2 ) as usize ] . data. len( ) == 0_usize ) ) ;
4564 return 0 ;
4665}
0 commit comments