MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / into_data

Method into_data

crates/wasmtime/src/runtime/store.rs:870–902  ·  view source on GitHub ↗

Consumes this [`Store`], destroying it, and returns the underlying data.

(mut self)

Source from the content-addressed store, hash-verified

868
869 /// Consumes this [`Store`], destroying it, and returns the underlying data.
870 pub fn into_data(mut self) -> T {
871 self.run_manual_drop_routines();
872
873 // This is an unsafe operation because we want to avoid having a runtime
874 // check or boolean for whether the data is actually contained within a
875 // `Store`. The data itself is stored as `ManuallyDrop` since we're
876 // manually managing the memory here, and there's also a `ManuallyDrop`
877 // around the `Box<StoreInner<T>>`. The way this works though is a bit
878 // tricky, so here's how things get dropped appropriately:
879 //
880 // * When a `Store<T>` is normally dropped, the custom destructor for
881 // `Store<T>` will drop `T`, then the `self.inner` field. The
882 // rustc-glue destructor runs for `Box<StoreInner<T>>` which drops
883 // `StoreInner<T>`. This cleans up all internal fields and doesn't
884 // touch `T` because it's wrapped in `ManuallyDrop`.
885 //
886 // * When calling this method we skip the top-level destructor for
887 // `Store<T>` with `mem::forget`. This skips both the destructor for
888 // `T` and the destructor for `StoreInner<T>`. We do, however, run the
889 // destructor for `Box<StoreInner<T>>` which, like above, will skip
890 // the destructor for `T` since it's `ManuallyDrop`.
891 //
892 // In both cases all the other fields of `StoreInner<T>` should all get
893 // dropped, and the manual management of destructors is basically
894 // between this method and `Drop for Store<T>`. Note that this also
895 // means that `Drop for StoreInner<T>` cannot access `self.data`, so
896 // there is a comment indicating this as well.
897 unsafe {
898 let mut inner = ManuallyDrop::take(&mut self.inner);
899 core::mem::forget(self);
900 ManuallyDrop::take(&mut inner.data_no_provenance)
901 }
902 }
903
904 /// Configures the [`ResourceLimiter`] used to limit resource creation
905 /// within this [`Store`].

Callers 12

trappingFunction · 0.80
total_stacks_limitFunction · 0.80
into_innerFunction · 0.80
call_wrapped_funcFunction · 0.80
call_func_with_reallocFunction · 0.80
call_wrapped_async_funcFunction · 0.80
trappingFunction · 0.80
timeout_async_hookFunction · 0.80
runFunction · 0.80
record_frameMethod · 0.80
poll_produceMethod · 0.80

Calls 1

Tested by 6

trappingFunction · 0.64
into_innerFunction · 0.64
call_wrapped_funcFunction · 0.64
call_func_with_reallocFunction · 0.64
trappingFunction · 0.64