review feedback
This commit is contained in:
@@ -97,10 +97,10 @@ impl StorePtr {
|
||||
self.0.clone()
|
||||
}
|
||||
/// Use the StorePtr as a mut ref to the Store.
|
||||
// XXX should this be an unsafe fn? is it always safe at a use site?
|
||||
pub(crate) fn get(&mut self) -> Option<&mut dyn Store> {
|
||||
/// Safety: must not be used outside the original lifetime of the borrow.
|
||||
pub(crate) unsafe fn get(&mut self) -> Option<&mut dyn Store> {
|
||||
match self.0 {
|
||||
Some(ptr) => Some(unsafe { &mut *ptr }),
|
||||
Some(ptr) => Some(&mut *ptr),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
@@ -630,12 +630,11 @@ impl OnDemandInstanceAllocator {
|
||||
PrimaryMap::with_capacity(module.table_plans.len() - num_imports);
|
||||
for table in &module.table_plans.values().as_slice()[num_imports..] {
|
||||
tables.push(
|
||||
Table::new_dynamic(
|
||||
table,
|
||||
Table::new_dynamic(table, unsafe {
|
||||
store
|
||||
.get()
|
||||
.expect("if module has table plans, store is not empty"),
|
||||
)
|
||||
.expect("if module has table plans, store is not empty")
|
||||
})
|
||||
.map_err(InstantiationError::Resource)?,
|
||||
);
|
||||
}
|
||||
@@ -656,13 +655,11 @@ impl OnDemandInstanceAllocator {
|
||||
PrimaryMap::with_capacity(module.memory_plans.len() - num_imports);
|
||||
for plan in &module.memory_plans.values().as_slice()[num_imports..] {
|
||||
memories.push(
|
||||
Memory::new_dynamic(
|
||||
plan,
|
||||
creator,
|
||||
Memory::new_dynamic(plan, creator, unsafe {
|
||||
store
|
||||
.get()
|
||||
.expect("if module has memory plans, store is not empty"),
|
||||
)
|
||||
.expect("if module has memory plans, store is not empty")
|
||||
})
|
||||
.map_err(InstantiationError::Resource)?,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -378,6 +378,9 @@ impl Memory {
|
||||
///
|
||||
/// Generally, prefer using `InstanceHandle::memory_grow`, which encapsulates
|
||||
/// this unsafety.
|
||||
///
|
||||
/// Ensure that the provided Store is not used to get access any Memory
|
||||
/// which lives inside it.
|
||||
pub unsafe fn grow(
|
||||
&mut self,
|
||||
delta_pages: u64,
|
||||
|
||||
@@ -223,8 +223,12 @@ impl Memory {
|
||||
Memory::_new(store.as_context_mut().0, ty)
|
||||
}
|
||||
|
||||
/// Async variant of [`Memory::new`]. You must use this variant with Stores which have a
|
||||
/// Async variant of [`Memory::new`]. You must use this variant with [`Store`]s which have a
|
||||
/// [`ResourceLimiterAsync`].
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic when used with a non-async [`Store`].
|
||||
#[cfg(feature = "async")]
|
||||
pub async fn new_async<T>(
|
||||
mut store: impl AsContextMut<Data = T>,
|
||||
@@ -491,6 +495,10 @@ impl Memory {
|
||||
}
|
||||
|
||||
/// Async variant of [`Memory::grow`]. Required when using a [`ResourceLimiterAsync`].
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic when used with a non-async [`Store`].
|
||||
#[cfg(feature = "async")]
|
||||
pub async fn grow_async<T>(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user