File tree Expand file tree Collapse file tree 5 files changed +49
-7
lines changed
Expand file tree Collapse file tree 5 files changed +49
-7
lines changed Original file line number Diff line number Diff line change 11[package ]
22name = " extism-pdk"
3- version = " 1.3 .0"
3+ version = " 1.4 .0"
44edition = " 2021"
55authors = [" The Extism Authors" , " oss@extism.org" ]
66license = " BSD-3-Clause"
@@ -12,9 +12,9 @@ description = "Extism Plug-in Development Kit (PDK) for Rust"
1212anyhow = " 1"
1313serde = { version = " 1" , features = [" derive" ] }
1414serde_json = " 1"
15- extism-pdk-derive = { path = " ./derive" , version = " 1.3 .0" }
16- extism-manifest = { version = " 1.2 .0" , optional = true }
17- extism-convert = { version = " 1.2 .0" , features = [" extism-pdk-path" ] }
15+ extism-pdk-derive = { path = " ./derive" , version = " 1.4 .0" }
16+ extism-manifest = { version = " 1.10 .0" , optional = true }
17+ extism-convert = { version = " 1.10 .0" , features = [" extism-pdk-path" ] }
1818base64 = " 0.22.1"
1919
2020[features ]
Original file line number Diff line number Diff line change 11[package ]
22name = " extism-pdk-derive"
3- version = " 1.3 .0"
3+ version = " 1.4 .0"
44edition = " 2021"
55authors = [" The Extism Authors" , " oss@extism.org" ]
66license = " BSD-3-Clause"
Original file line number Diff line number Diff line change @@ -296,7 +296,9 @@ pub fn host_fn(
296296 match & * t. pat {
297297 syn:: Pat :: Ident ( i) => {
298298 into_inputs
299- . push ( quote ! ( extism_pdk:: ToMemory :: to_memory( &&#i) ?. offset( ) ) ) ;
299+ . push ( quote ! (
300+ extism_pdk:: ManagedMemory :: from( extism_pdk:: ToMemory :: to_memory( &&#i) ?) . offset( )
301+ ) ) ;
300302 }
301303 _ => panic ! ( "invalid host function argument" ) ,
302304 }
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ pub use anyhow::Error;
2323pub use extism_convert:: * ;
2424pub use extism_convert:: { FromBytes , FromBytesOwned , ToBytes } ;
2525pub use extism_pdk_derive:: { host_fn, plugin_fn, shared_fn} ;
26- pub use memory:: { Memory , MemoryPointer } ;
26+ pub use memory:: { ManagedMemory , Memory , MemoryPointer } ;
2727pub use to_memory:: ToMemory ;
2828
2929#[ cfg( feature = "http" ) ]
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ use crate::*;
22
33pub struct Memory ( pub MemoryHandle ) ;
44
5+ pub struct ManagedMemory ( pub Memory ) ;
6+
57pub mod internal {
68 use super :: * ;
79
@@ -195,3 +197,41 @@ impl<T: FromBytesOwned> MemoryPointer<T> {
195197 }
196198 }
197199}
200+
201+ impl Drop for ManagedMemory {
202+ fn drop ( & mut self ) {
203+ internal:: memory_free ( ( self . 0 ) . 0 )
204+ }
205+ }
206+
207+ impl ManagedMemory {
208+ pub fn new ( mem : Memory ) -> Self {
209+ ManagedMemory ( mem)
210+ }
211+
212+ pub fn offset ( & self ) -> u64 {
213+ self . 0 . offset ( )
214+ }
215+
216+ pub fn len ( & self ) -> usize {
217+ self . 0 . len ( )
218+ }
219+ }
220+
221+ impl From < Memory > for ManagedMemory {
222+ fn from ( value : Memory ) -> Self {
223+ ManagedMemory ( value)
224+ }
225+ }
226+
227+ impl AsRef < Memory > for ManagedMemory {
228+ fn as_ref ( & self ) -> & Memory {
229+ & self . 0
230+ }
231+ }
232+
233+ impl AsMut < Memory > for ManagedMemory {
234+ fn as_mut ( & mut self ) -> & mut Memory {
235+ & mut self . 0
236+ }
237+ }
You can’t perform that action at this time.
0 commit comments