* Add basic GuestString support to wiggle This commit adds basic `GuestString` support to `wiggle`. `GuestString` is a wrapper around `GuestArray<'_, u8>` array type which itself can be made into either an owned (cloned) Rust `String` or borrowed as a reference `&str`. In both cases, `GuestString` ensures that the underlying bytes are valid Unicode code units, throwing a `InvalidUtf8` error if not. This commit adds support *only* for passing in strings as arguments in WASI. Marshalling of the return arg has not yet been implemented. I'm not even sure it's possible without multi-value return args feature of Wasm. It's not a major setback especially since the WASI spec (and this includes even the `ephemeral` snapshot) doesn't return strings anywhere. They are only ever passed in as arguments to interface functions. It should be noted that error returned in case of invalid UTF-8 requires a lot more love as it doesn't include anything besides flagging an event that the string contained an invalid Unicode code unit. * Borrow all of string's memory including nul-byte Borrow all of string's underlying memory including the nul-byte. This perhaps might not have a tremendous impact on anything, but since the nul-byte is technically part of the WASI string, we should include it in the borrow as well. * Fill in wiggle-generate blanks for strings * Print to screen passed string in proptest * Strings are PointerLengthPairs! * Fix generation of strings in compound types * Update test with simple string strategy * Generate better test strings * Finalise proptest for strings * Fix formatting * Update crates/runtime/src/memory/string.rs Removes unnecessary comment in code * Apply Pat's suggestion to wrap Utf8Error as error
33 lines
916 B
Rust
33 lines
916 B
Rust
use crate::Region;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Debug, Error, PartialEq, Eq)]
|
|
pub enum GuestError {
|
|
#[error("Invalid flag value {0}")]
|
|
InvalidFlagValue(&'static str),
|
|
#[error("Invalid enum value {0}")]
|
|
InvalidEnumValue(&'static str),
|
|
#[error("Pointer out of bounds: {0:?}")]
|
|
PtrOutOfBounds(Region),
|
|
#[error("Pointer not aligned to {1}: {0:?}")]
|
|
PtrNotAligned(Region, u32),
|
|
#[error("Pointer already borrowed: {0:?}")]
|
|
PtrBorrowed(Region),
|
|
#[error("In func {funcname}:{location}:")]
|
|
InFunc {
|
|
funcname: &'static str,
|
|
location: &'static str,
|
|
#[source]
|
|
err: Box<GuestError>,
|
|
},
|
|
#[error("In data {typename}.{field}:")]
|
|
InDataField {
|
|
typename: String,
|
|
field: String,
|
|
#[source]
|
|
err: Box<GuestError>,
|
|
},
|
|
#[error("Invalid UTF-8 encountered")]
|
|
InvalidUtf8(#[from] std::str::Utf8Error),
|
|
}
|