@@ -6,6 +6,36 @@ use std::io::prelude::*;
66use std:: io:: { Read , Seek , Write } ;
77use std:: os:: fd:: AsFd ;
88use std:: rc:: { Rc , Weak } ;
9+ #[ derive( Default ) ]
10+ pub struct Pair {
11+ pub x : Value < i32 > ,
12+ pub y : Value < i32 > ,
13+ }
14+ impl Clone for Pair {
15+ fn clone ( & self ) -> Self {
16+ let __this: Value < Pair > = Rc :: new ( RefCell :: new ( Self {
17+ x : Rc :: new ( RefCell :: new ( ( * self . x . borrow ( ) ) ) ) ,
18+ y : Rc :: new ( RefCell :: new ( ( * self . y . borrow ( ) ) ) ) ,
19+ } ) ) ;
20+ let this: Ptr < Pair > = __this. as_pointer ( ) ;
21+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
22+ }
23+ }
24+ impl ByteRepr for Pair {
25+ fn byte_size ( ) -> usize {
26+ 8
27+ }
28+ fn to_bytes ( & self , buf : & mut [ u8 ] ) {
29+ ( * self . x . borrow ( ) ) . to_bytes ( & mut buf[ 0 ..4 ] ) ;
30+ ( * self . y . borrow ( ) ) . to_bytes ( & mut buf[ 4 ..8 ] ) ;
31+ }
32+ fn from_bytes ( buf : & [ u8 ] ) -> Self {
33+ Self {
34+ x : Rc :: new ( RefCell :: new ( <i32 >:: from_bytes ( & buf[ 0 ..4 ] ) ) ) ,
35+ y : Rc :: new ( RefCell :: new ( <i32 >:: from_bytes ( & buf[ 4 ..8 ] ) ) ) ,
36+ }
37+ }
38+ }
939pub fn main ( ) {
1040 __cpp2rust_init_globals ( ) ;
1141 std:: process:: exit ( main_0 ( ) ) ;
@@ -15,6 +45,20 @@ fn main_0() -> i32 {
1545 let out: Value < i32 > = Rc :: new ( RefCell :: new ( ( ( * x. borrow ( ) ) . read ( ) ) ) ) ;
1646 ( * x. borrow ( ) ) . delete ( ) ;
1747 assert ! ( ( ( * out. borrow( ) ) == 5 ) ) ;
48+ let y: Value < Ptr < i32 > > = Rc :: new ( RefCell :: new ( Ptr :: alloc ( Default :: default ( ) ) ) ) ;
49+ ( * y. borrow ( ) ) . write ( 9 ) ;
50+ assert ! ( ( ( ( * y. borrow( ) ) . read( ) ) == 9 ) ) ;
51+ ( * y. borrow ( ) ) . delete ( ) ;
52+ let p: Value < Ptr < Pair > > = Rc :: new ( RefCell :: new ( Ptr :: alloc ( <Pair >:: default ( ) ) ) ) ;
53+ ( * ( * ( * p. borrow ( ) ) . upgrade ( ) . deref ( ) ) . x . borrow_mut ( ) ) = 1 ;
54+ ( * ( * ( * p. borrow ( ) ) . upgrade ( ) . deref ( ) ) . y . borrow_mut ( ) ) = 2 ;
55+ assert ! (
56+ ( {
57+ let _lhs = ( * ( * ( * p. borrow( ) ) . upgrade( ) . deref( ) ) . x. borrow( ) ) ;
58+ _lhs + ( * ( * ( * p. borrow( ) ) . upgrade( ) . deref( ) ) . y. borrow( ) )
59+ } == 3 )
60+ ) ;
61+ ( * p. borrow ( ) ) . delete ( ) ;
1862 return 0 ;
1963}
2064pub fn __cpp2rust_init_globals ( ) { }
0 commit comments