rename the pointer read/write methods to read and write
these names were artifacts of some early confusion / bad design i made in the traits. read and write are much simpler names! also, change a ptr_mut to ptr where we just read the contents in the argument marshalling for structs. this has no effect, but it is more correct.
This commit is contained in:
@@ -262,8 +262,8 @@ fn marshal_arg(
|
|||||||
let arg_name = names.func_ptr_binding(¶m.name);
|
let arg_name = names.func_ptr_binding(¶m.name);
|
||||||
let name = names.func_param(¶m.name);
|
let name = names.func_param(¶m.name);
|
||||||
quote! {
|
quote! {
|
||||||
let #name = match memory.ptr_mut::<#pointee_type>(#arg_name as u32) {
|
let #name = match memory.ptr::<#pointee_type>(#arg_name as u32) {
|
||||||
Ok(p) => match p.read_ptr_from_guest() {
|
Ok(p) => match p.read() {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
#error_handling
|
#error_handling
|
||||||
@@ -335,7 +335,7 @@ where
|
|||||||
// trait binding returns func_param name.
|
// trait binding returns func_param name.
|
||||||
let val_name = names.func_param(&result.name);
|
let val_name = names.func_param(&result.name);
|
||||||
let post = quote! {
|
let post = quote! {
|
||||||
#ptr_name.write_ptr_to_guest(&#val_name);
|
#ptr_name.write(&#val_name);
|
||||||
};
|
};
|
||||||
(pre, post)
|
(pre, post)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -225,19 +225,19 @@ mod test {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
let ptr = guest_memory.ptr_mut(12).expect("ptr mut to first el");
|
let ptr = guest_memory.ptr_mut(12).expect("ptr mut to first el");
|
||||||
ptr.write_ptr_to_guest(
|
ptr.write(
|
||||||
&guest_memory
|
&guest_memory
|
||||||
.ptr::<GuestPtr<u8>>(0)
|
.ptr::<GuestPtr<u8>>(0)
|
||||||
.expect("ptr to the first value"),
|
.expect("ptr to the first value"),
|
||||||
);
|
);
|
||||||
let ptr = guest_memory.ptr_mut(16).expect("ptr mut to first el");
|
let ptr = guest_memory.ptr_mut(16).expect("ptr mut to first el");
|
||||||
ptr.write_ptr_to_guest(
|
ptr.write(
|
||||||
&guest_memory
|
&guest_memory
|
||||||
.ptr::<GuestPtr<u8>>(4)
|
.ptr::<GuestPtr<u8>>(4)
|
||||||
.expect("ptr to the second value"),
|
.expect("ptr to the second value"),
|
||||||
);
|
);
|
||||||
let ptr = guest_memory.ptr_mut(20).expect("ptr mut to first el");
|
let ptr = guest_memory.ptr_mut(20).expect("ptr mut to first el");
|
||||||
ptr.write_ptr_to_guest(
|
ptr.write(
|
||||||
&guest_memory
|
&guest_memory
|
||||||
.ptr::<GuestPtr<u8>>(8)
|
.ptr::<GuestPtr<u8>>(8)
|
||||||
.expect("ptr to the third value"),
|
.expect("ptr to the third value"),
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ impl<'a, T> GuestPtr<'a, T>
|
|||||||
where
|
where
|
||||||
T: GuestTypeClone<'a>,
|
T: GuestTypeClone<'a>,
|
||||||
{
|
{
|
||||||
pub fn clone_from_guest(&self) -> Result<T, GuestError> {
|
pub fn read(&self) -> Result<T, GuestError> {
|
||||||
T::read_from_guest(self)
|
T::read_from_guest(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,11 +210,11 @@ impl<'a, T> GuestPtrMut<'a, T>
|
|||||||
where
|
where
|
||||||
T: GuestTypeClone<'a>,
|
T: GuestTypeClone<'a>,
|
||||||
{
|
{
|
||||||
pub fn read_ptr_from_guest(&self) -> Result<T, GuestError> {
|
pub fn read(&self) -> Result<T, GuestError> {
|
||||||
T::read_from_guest(&self.as_immut())
|
T::read_from_guest(&self.as_immut())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_ptr_to_guest(&self, ptr: &T) {
|
pub fn write(&self, ptr: &T) {
|
||||||
T::write_to_guest(ptr, &self);
|
T::write_to_guest(ptr, &self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ impl ReduceExcusesExcercise {
|
|||||||
.ptr_mut(self.array_ptr_loc.ptr)
|
.ptr_mut(self.array_ptr_loc.ptr)
|
||||||
.expect("ptr to array mut");
|
.expect("ptr to array mut");
|
||||||
for ptr in &self.excuse_ptr_locs {
|
for ptr in &self.excuse_ptr_locs {
|
||||||
next.write_ptr_to_guest(
|
next.write(
|
||||||
&guest_memory
|
&guest_memory
|
||||||
.ptr::<types::Excuse>(ptr.ptr)
|
.ptr::<types::Excuse>(ptr.ptr)
|
||||||
.expect("ptr to Excuse value"),
|
.expect("ptr to Excuse value"),
|
||||||
@@ -203,7 +203,7 @@ impl PopulateExcusesExcercise {
|
|||||||
.ptr_mut(self.array_ptr_loc.ptr)
|
.ptr_mut(self.array_ptr_loc.ptr)
|
||||||
.expect("ptr mut to the first element of array");
|
.expect("ptr mut to the first element of array");
|
||||||
for ptr in &self.elements {
|
for ptr in &self.elements {
|
||||||
next.write_ptr_to_guest(
|
next.write(
|
||||||
&guest_memory
|
&guest_memory
|
||||||
.ptr_mut::<types::Excuse>(ptr.ptr)
|
.ptr_mut::<types::Excuse>(ptr.ptr)
|
||||||
.expect("ptr mut to Excuse value"),
|
.expect("ptr mut to Excuse value"),
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ impl pointers::Pointers for WasiCtx {
|
|||||||
println!("input4 {:?}", input4);
|
println!("input4 {:?}", input4);
|
||||||
|
|
||||||
// Write ptr value to mutable ptr:
|
// Write ptr value to mutable ptr:
|
||||||
input4_ptr_ptr.write_ptr_to_guest(&input2_ptr.as_immut());
|
input4_ptr_ptr.write(&input2_ptr.as_immut());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -428,12 +428,12 @@ impl ReturnPairPtrsExercise {
|
|||||||
let ret_first_ptr: GuestPtr<i32> = ptr_pair_int_ptrs
|
let ret_first_ptr: GuestPtr<i32> = ptr_pair_int_ptrs
|
||||||
.cast::<GuestPtr<i32>>(0u32)
|
.cast::<GuestPtr<i32>>(0u32)
|
||||||
.expect("extract ptr to first element in struct")
|
.expect("extract ptr to first element in struct")
|
||||||
.clone_from_guest()
|
.read()
|
||||||
.expect("read ptr to first element in struct");
|
.expect("read ptr to first element in struct");
|
||||||
let ret_second_ptr: GuestPtr<i32> = ptr_pair_int_ptrs
|
let ret_second_ptr: GuestPtr<i32> = ptr_pair_int_ptrs
|
||||||
.cast::<GuestPtr<i32>>(4u32)
|
.cast::<GuestPtr<i32>>(4u32)
|
||||||
.expect("extract ptr to second element in struct")
|
.expect("extract ptr to second element in struct")
|
||||||
.clone_from_guest()
|
.read()
|
||||||
.expect("read ptr to second element in struct");
|
.expect("read ptr to second element in struct");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
self.input_first,
|
self.input_first,
|
||||||
|
|||||||
Reference in New Issue
Block a user