|
1 | 1 | use crate::prelude::*; |
2 | | -use crate::runtime::Memory as RuntimeMemory; |
3 | 2 | use crate::runtime::externals::Global as RuntimeGlobal; |
4 | 3 | use crate::runtime::externals::Table as RuntimeTable; |
5 | 4 | use crate::runtime::externals::Tag as RuntimeTag; |
@@ -1526,7 +1525,7 @@ impl ExternType { |
1526 | 1525 | ExternType::Func(func_ty) => func_ty.default_value(store).map(Extern::Func), |
1527 | 1526 | ExternType::Global(global_ty) => global_ty.default_value(store).map(Extern::Global), |
1528 | 1527 | ExternType::Table(table_ty) => table_ty.default_value(store).map(Extern::Table), |
1529 | | - ExternType::Memory(mem_ty) => mem_ty.default_value(store).map(Extern::Memory), |
| 1528 | + ExternType::Memory(mem_ty) => mem_ty.default_value(store), |
1530 | 1529 | ExternType::Tag(tag_ty) => tag_ty.default_value(store).map(Extern::Tag), |
1531 | 1530 | } |
1532 | 1531 | } |
@@ -3494,12 +3493,26 @@ impl MemoryType { |
3494 | 3493 | pub(crate) fn wasmtime_memory(&self) -> &Memory { |
3495 | 3494 | &self.ty |
3496 | 3495 | } |
3497 | | - /// Construct a new memory import initialized to this memory type’s default state |
| 3496 | + /// Construct a new memory import initialized to this memory type’s default |
| 3497 | + /// state. |
3498 | 3498 | /// |
3499 | | - /// Returns a host `Memory` in the given store with the configured initial |
3500 | | - /// page size and zeroed contents. |
3501 | | - pub fn default_value(&self, store: impl AsContextMut) -> Result<RuntimeMemory> { |
3502 | | - RuntimeMemory::new(store, self.clone()) |
| 3499 | + /// Returns a host `Memory` or `SharedMemory` depending on if this is a |
| 3500 | + /// shared memory type or not. The memory's type will have the same type as |
| 3501 | + /// `self` and the initial contents of the memory, if any, will be all zero. |
| 3502 | + pub fn default_value(&self, store: impl AsContextMut) -> Result<Extern> { |
| 3503 | + Ok(if self.is_shared() { |
| 3504 | + #[cfg(feature = "threads")] |
| 3505 | + { |
| 3506 | + let store = store.as_context(); |
| 3507 | + Extern::SharedMemory(crate::SharedMemory::new(store.engine(), self.clone())?) |
| 3508 | + } |
| 3509 | + #[cfg(not(feature = "threads"))] |
| 3510 | + { |
| 3511 | + bail!("creation of shared memories disabled at compile time") |
| 3512 | + } |
| 3513 | + } else { |
| 3514 | + Extern::Memory(crate::Memory::new(store, self.clone())?) |
| 3515 | + }) |
3503 | 3516 | } |
3504 | 3517 | } |
3505 | 3518 |
|
|
0 commit comments