@@ -15,8 +15,8 @@ pub fn authorize(args: AuthorizeArgs) -> Result<Executed> {
1515 len : encoded. len ( ) ,
1616 } ;
1717
18- let output = unsafe { abi:: authorize ( input) } ;
19- codec:: decode ( output. as_slice ( ) ) . map_err ( Into :: into)
18+ let output: Buffer = unsafe { abi:: authorize ( input) } ;
19+ codec:: decode ( & output. to_vec ( ) ) . map_err ( Into :: into)
2020}
2121
2222/// Run the refine invocation
@@ -28,7 +28,7 @@ pub fn refine(args: RefineArgs) -> Result<Refined> {
2828 } ;
2929
3030 let output = unsafe { abi:: refine ( input) } ;
31- codec:: decode ( output. as_slice ( ) ) . map_err ( Into :: into)
31+ codec:: decode ( & output. to_vec ( ) ) . map_err ( Into :: into)
3232}
3333
3434/// Run the accumulate invocation
@@ -40,7 +40,7 @@ pub fn accumulate(args: AccumulateArgs) -> Result<Accumulated> {
4040 } ;
4141
4242 let output = unsafe { abi:: accumulate ( input) } ;
43- codec:: decode ( output. as_slice ( ) ) . map_err ( Into :: into)
43+ codec:: decode ( & output. to_vec ( ) ) . map_err ( Into :: into)
4444}
4545
4646mod abi {
@@ -53,16 +53,21 @@ mod abi {
5353 pub use { comp_accumulate as accumulate, comp_authorize as authorize, comp_refine as refine} ;
5454
5555 #[ repr( C ) ]
56- #[ derive( Copy , Clone ) ]
56+ #[ derive( Copy , Clone , Debug ) ]
5757 pub struct Buffer {
5858 pub ptr : * const u8 ,
5959 pub len : usize ,
6060 }
6161
6262 impl Buffer {
6363 /// Get the buffer as a byte slice
64- pub fn as_slice ( & self ) -> & [ u8 ] {
65- unsafe { std:: slice:: from_raw_parts ( self . ptr , self . len ) }
64+ pub fn to_vec ( & self ) -> Vec < u8 > {
65+ let result = unsafe { core:: slice:: from_raw_parts ( self . ptr , self . len ) . to_vec ( ) } ;
66+ unsafe {
67+ let layout = std:: alloc:: Layout :: from_size_align ( self . len , 1 ) . unwrap ( ) ;
68+ std:: alloc:: dealloc ( self . ptr as * mut _ , layout) ;
69+ }
70+ result
6671 }
6772 }
6873
0 commit comments