Tidy up pointer casting to avoid casts that change mutability.
This commit is contained in:
@@ -190,7 +190,7 @@ impl InstanceContents {
|
|||||||
/// Return the indexed `VMTableDefinition`.
|
/// Return the indexed `VMTableDefinition`.
|
||||||
fn table_mut(&mut self, index: DefinedTableIndex) -> &mut VMTableDefinition {
|
fn table_mut(&mut self, index: DefinedTableIndex) -> &mut VMTableDefinition {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = (&self.vmctx as *const VMContext as *mut u8)
|
let ptr = (&mut self.vmctx as *mut VMContext as *mut u8)
|
||||||
.add(cast::usize(self.offsets.vmctx_vmtable_definition(index)));
|
.add(cast::usize(self.offsets.vmctx_vmtable_definition(index)));
|
||||||
&mut *(ptr as *mut VMTableDefinition)
|
&mut *(ptr as *mut VMTableDefinition)
|
||||||
}
|
}
|
||||||
@@ -199,7 +199,7 @@ impl InstanceContents {
|
|||||||
/// Return a pointer to the `VMTableDefinition`s.
|
/// Return a pointer to the `VMTableDefinition`s.
|
||||||
fn tables_ptr(&mut self) -> *mut VMTableDefinition {
|
fn tables_ptr(&mut self) -> *mut VMTableDefinition {
|
||||||
unsafe {
|
unsafe {
|
||||||
(&self.vmctx as *const VMContext as *mut u8)
|
(&mut self.vmctx as *mut VMContext as *mut u8)
|
||||||
.add(cast::usize(self.offsets.vmctx_tables_begin()))
|
.add(cast::usize(self.offsets.vmctx_tables_begin()))
|
||||||
as *mut VMTableDefinition
|
as *mut VMTableDefinition
|
||||||
}
|
}
|
||||||
@@ -217,7 +217,7 @@ impl InstanceContents {
|
|||||||
/// Return the indexed `VMMemoryDefinition`.
|
/// Return the indexed `VMMemoryDefinition`.
|
||||||
fn memory_mut(&mut self, index: DefinedMemoryIndex) -> &mut VMMemoryDefinition {
|
fn memory_mut(&mut self, index: DefinedMemoryIndex) -> &mut VMMemoryDefinition {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = (&self.vmctx as *const VMContext as *mut u8)
|
let ptr = (&mut self.vmctx as *mut VMContext as *mut u8)
|
||||||
.add(cast::usize(self.offsets.vmctx_vmmemory_definition(index)));
|
.add(cast::usize(self.offsets.vmctx_vmmemory_definition(index)));
|
||||||
&mut *(ptr as *mut VMMemoryDefinition)
|
&mut *(ptr as *mut VMMemoryDefinition)
|
||||||
}
|
}
|
||||||
@@ -226,7 +226,7 @@ impl InstanceContents {
|
|||||||
/// Return a pointer to the `VMMemoryDefinition`s.
|
/// Return a pointer to the `VMMemoryDefinition`s.
|
||||||
fn memories_ptr(&mut self) -> *mut VMMemoryDefinition {
|
fn memories_ptr(&mut self) -> *mut VMMemoryDefinition {
|
||||||
unsafe {
|
unsafe {
|
||||||
(&self.vmctx as *const VMContext as *mut u8)
|
(&mut self.vmctx as *mut VMContext as *mut u8)
|
||||||
.add(cast::usize(self.offsets.vmctx_memories_begin()))
|
.add(cast::usize(self.offsets.vmctx_memories_begin()))
|
||||||
as *mut VMMemoryDefinition
|
as *mut VMMemoryDefinition
|
||||||
}
|
}
|
||||||
@@ -245,7 +245,7 @@ impl InstanceContents {
|
|||||||
/// Return the indexed `VMGlobalDefinition`.
|
/// Return the indexed `VMGlobalDefinition`.
|
||||||
fn global_mut(&mut self, index: DefinedGlobalIndex) -> &mut VMGlobalDefinition {
|
fn global_mut(&mut self, index: DefinedGlobalIndex) -> &mut VMGlobalDefinition {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = (&self.vmctx as *const VMContext as *mut u8)
|
let ptr = (&mut self.vmctx as *mut VMContext as *mut u8)
|
||||||
.add(cast::usize(self.offsets.vmctx_vmglobal_definition(index)));
|
.add(cast::usize(self.offsets.vmctx_vmglobal_definition(index)));
|
||||||
&mut *(ptr as *mut VMGlobalDefinition)
|
&mut *(ptr as *mut VMGlobalDefinition)
|
||||||
}
|
}
|
||||||
@@ -312,13 +312,13 @@ impl InstanceContents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return the table index for the given `VMTableDefinition`.
|
/// Return the table index for the given `VMTableDefinition`.
|
||||||
pub(crate) fn table_index(&self, table: &mut VMTableDefinition) -> DefinedTableIndex {
|
pub(crate) fn table_index(&self, table: &VMTableDefinition) -> DefinedTableIndex {
|
||||||
let offsets = &self.offsets;
|
let offsets = &self.offsets;
|
||||||
let begin = unsafe {
|
let begin = unsafe {
|
||||||
(&self.vmctx as *const VMContext as *mut u8)
|
(&self.vmctx as *const VMContext as *const u8)
|
||||||
.add(cast::usize(offsets.vmctx_tables_begin()))
|
.add(cast::usize(offsets.vmctx_tables_begin()))
|
||||||
} as *mut VMTableDefinition;
|
} as *const VMTableDefinition;
|
||||||
let end: *mut VMTableDefinition = table;
|
let end: *const VMTableDefinition = table;
|
||||||
// TODO: Use `offset_from` once it stablizes.
|
// TODO: Use `offset_from` once it stablizes.
|
||||||
let index = DefinedTableIndex::new(
|
let index = DefinedTableIndex::new(
|
||||||
(end as usize - begin as usize) / mem::size_of::<VMTableDefinition>(),
|
(end as usize - begin as usize) / mem::size_of::<VMTableDefinition>(),
|
||||||
@@ -328,13 +328,13 @@ impl InstanceContents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return the memory index for the given `VMMemoryDefinition`.
|
/// Return the memory index for the given `VMMemoryDefinition`.
|
||||||
pub(crate) fn memory_index(&self, memory: &mut VMMemoryDefinition) -> DefinedMemoryIndex {
|
pub(crate) fn memory_index(&self, memory: &VMMemoryDefinition) -> DefinedMemoryIndex {
|
||||||
let offsets = &self.offsets;
|
let offsets = &self.offsets;
|
||||||
let begin = unsafe {
|
let begin = unsafe {
|
||||||
(&self.vmctx as *const VMContext as *mut u8)
|
(&self.vmctx as *const VMContext as *const u8)
|
||||||
.add(cast::usize(offsets.vmctx_memories_begin()))
|
.add(cast::usize(offsets.vmctx_memories_begin()))
|
||||||
} as *mut VMMemoryDefinition;
|
} as *const VMMemoryDefinition;
|
||||||
let end: *mut VMMemoryDefinition = memory;
|
let end: *const VMMemoryDefinition = memory;
|
||||||
// TODO: Use `offset_from` once it stablizes.
|
// TODO: Use `offset_from` once it stablizes.
|
||||||
let index = DefinedMemoryIndex::new(
|
let index = DefinedMemoryIndex::new(
|
||||||
(end as usize - begin as usize) / mem::size_of::<VMMemoryDefinition>(),
|
(end as usize - begin as usize) / mem::size_of::<VMMemoryDefinition>(),
|
||||||
|
|||||||
Reference in New Issue
Block a user