File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < cassert>
2+ #include < vector>
3+
4+ struct NonCopy {
5+ std::vector<int > data;
6+ int tag = 0 ;
7+ };
8+
9+ int main () {
10+ NonCopy arr[3 ];
11+ arr[0 ].tag = 7 ;
12+ arr[1 ].data .push_back (42 );
13+ assert (arr[0 ].tag == 7 );
14+ assert (arr[1 ].data .size () == 1 );
15+ assert (arr[1 ].data [0 ] == 42 );
16+ assert (arr[2 ].tag == 0 );
17+ assert (arr[2 ].data .size () == 0 );
18+ return 0 ;
19+ }
Original file line number Diff line number Diff line change 1+ extern crate libcc2rs;
2+ use libcc2rs:: * ;
3+ use std:: cell:: RefCell ;
4+ use std:: collections:: BTreeMap ;
5+ use std:: io:: prelude:: * ;
6+ use std:: io:: { Read , Seek , Write } ;
7+ use std:: os:: fd:: AsFd ;
8+ use std:: rc:: { Rc , Weak } ;
9+ #[ derive( Default ) ]
10+ pub struct NonCopy {
11+ pub data : Value < Vec < i32 > > ,
12+ pub tag : Value < i32 > ,
13+ }
14+ impl Clone for NonCopy {
15+ fn clone ( & self ) -> Self {
16+ let mut this = Self {
17+ data : Rc :: new ( RefCell :: new ( ( * self . data . borrow ( ) ) . clone ( ) ) ) ,
18+ tag : Rc :: new ( RefCell :: new ( ( * self . tag . borrow ( ) ) ) ) ,
19+ } ;
20+ this
21+ }
22+ }
23+ impl ByteRepr for NonCopy { }
24+ pub fn main ( ) {
25+ std:: process:: exit ( main_0 ( ) ) ;
26+ }
27+ fn main_0 ( ) -> i32 {
28+ let arr: Value < Box < [ NonCopy ] > > = Rc :: new ( RefCell :: new (
29+ ( 0 ..3 )
30+ . map ( |_| <NonCopy >:: default ( ) )
31+ . collect :: < Box < [ NonCopy ] > > ( ) ,
32+ ) ) ;
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 ) ) ;
37+ assert ! (
38+ ( ( ( ( * arr. borrow( ) ) [ ( 1 ) as usize ] . data. as_pointer( ) as Ptr <i32 >)
39+ . offset( 0_usize as isize )
40+ . read( ) )
41+ == 42 )
42+ ) ;
43+ assert ! ( ( ( * ( * arr. borrow( ) ) [ ( 2 ) as usize ] . tag. borrow( ) ) == 0 ) ) ;
44+ assert ! ( ( ( * ( * arr. borrow( ) ) [ ( 2 ) as usize ] . data. borrow( ) ) . len( ) == 0_usize ) ) ;
45+ return 0 ;
46+ }
Original file line number Diff line number Diff line change 1+ extern crate libc;
2+ use libc:: * ;
3+ extern crate libcc2rs;
4+ use libcc2rs:: * ;
5+ use std:: collections:: BTreeMap ;
6+ use std:: io:: { Read , Seek , Write } ;
7+ use std:: os:: fd:: { AsFd , FromRawFd , IntoRawFd } ;
8+ use std:: rc:: Rc ;
9+ #[ repr( C ) ]
10+ #[ derive( Clone , Default ) ]
11+ pub struct NonCopy {
12+ pub data : Vec < i32 > ,
13+ pub tag : i32 ,
14+ }
15+ pub fn main ( ) {
16+ unsafe {
17+ std:: process:: exit ( main_0 ( ) as i32 ) ;
18+ }
19+ }
20+ unsafe fn main_0 ( ) -> i32 {
21+ let mut arr: [ NonCopy ; 3 ] = std:: array:: from_fn :: < _ , 3 , _ > ( |_| <NonCopy >:: default ( ) ) ;
22+ arr[ ( 0 ) as usize ] . tag = 7 ;
23+ arr[ ( 1 ) as usize ] . data . push ( 42 ) ;
24+ assert ! ( ( ( arr[ ( 0 ) as usize ] . tag) == ( 7 ) ) ) ;
25+ assert ! ( ( ( arr[ ( 1 ) as usize ] . data. len( ) ) == ( 1_usize ) ) ) ;
26+ assert ! ( ( ( arr[ ( 1 ) as usize ] . data[ ( 0_usize ) ] ) == ( 42 ) ) ) ;
27+ assert ! ( ( ( arr[ ( 2 ) as usize ] . tag) == ( 0 ) ) ) ;
28+ assert ! ( ( ( arr[ ( 2 ) as usize ] . data. len( ) ) == ( 0_usize ) ) ) ;
29+ return 0 ;
30+ }
You can’t perform that action at this time.
0 commit comments