wiggle: revamp error type conversions

This commit is contained in:
Pat Hickey
2020-03-27 18:27:17 -07:00
parent 167a040ea5
commit 3e97e5f1ae
14 changed files with 76 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
use proptest::prelude::*;
use wiggle::{GuestError, GuestMemory, GuestPtr};
use wiggle::{GuestMemory, GuestPtr};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
@@ -7,7 +7,7 @@ wiggle::from_witx!({
ctx: WasiCtx,
});
impl_errno!(types::Errno);
impl_errno!(types::Errno, types::GuestErrorConversion);
impl<'a> arrays::Arrays for WasiCtx<'a> {
fn reduce_excuses(

View File

@@ -1,5 +1,5 @@
use proptest::prelude::*;
use wiggle::{GuestError, GuestMemory};
use wiggle::GuestMemory;
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
@@ -7,7 +7,7 @@ wiggle::from_witx!({
ctx: WasiCtx,
});
impl_errno!(types::Errno);
impl_errno!(types::Errno, types::GuestErrorConversion);
impl<'a> atoms::Atoms for WasiCtx<'a> {
fn int_float_args(&self, an_int: u32, an_float: f32) -> Result<(), types::Errno> {

View File

@@ -1,6 +1,6 @@
use proptest::prelude::*;
use std::convert::TryFrom;
use wiggle::{GuestError, GuestMemory, GuestPtr};
use wiggle::{GuestMemory, GuestPtr};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
@@ -8,7 +8,7 @@ wiggle::from_witx!({
ctx: WasiCtx,
});
impl_errno!(types::Errno);
impl_errno!(types::Errno, types::GuestErrorConversion);
impl<'a> flags::Flags for WasiCtx<'a> {
fn configure_car(

View File

@@ -1,5 +1,5 @@
use proptest::prelude::*;
use wiggle::{GuestError, GuestMemory, GuestType};
use wiggle::{GuestMemory, GuestType};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
const FD_VAL: u32 = 123;
@@ -9,7 +9,7 @@ wiggle::from_witx!({
ctx: WasiCtx,
});
impl_errno!(types::Errno);
impl_errno!(types::Errno, types::GuestErrorConversion);
impl<'a> handle_examples::HandleExamples for WasiCtx<'a> {
fn fd_create(&self) -> Result<types::Fd, types::Errno> {

View File

@@ -1,6 +1,6 @@
use proptest::prelude::*;
use std::convert::TryFrom;
use wiggle::{GuestError, GuestMemory};
use wiggle::GuestMemory;
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
@@ -8,7 +8,7 @@ wiggle::from_witx!({
ctx: WasiCtx,
});
impl_errno!(types::Errno);
impl_errno!(types::Errno, types::GuestErrorConversion);
impl<'a> ints::Ints for WasiCtx<'a> {
fn cookie_cutter(&self, init_cookie: types::Cookie) -> Result<types::Bool, types::Errno> {

View File

@@ -1,5 +1,5 @@
use proptest::prelude::*;
use wiggle::{GuestError, GuestMemory, GuestPtr};
use wiggle::{GuestMemory, GuestPtr};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
@@ -7,7 +7,7 @@ wiggle::from_witx!({
ctx: WasiCtx,
});
impl_errno!(types::Errno);
impl_errno!(types::Errno, types::GuestErrorConversion);
impl<'a> pointers::Pointers for WasiCtx<'a> {
fn pointers_and_enums<'b>(

View File

@@ -1,5 +1,5 @@
use proptest::prelude::*;
use wiggle::{GuestBorrows, GuestError, GuestMemory, GuestPtr};
use wiggle::{GuestBorrows, GuestMemory, GuestPtr};
use wiggle_test::{impl_errno, HostMemory, MemArea, MemAreas, WasiCtx};
wiggle::from_witx!({
@@ -7,7 +7,7 @@ wiggle::from_witx!({
ctx: WasiCtx,
});
impl_errno!(types::Errno);
impl_errno!(types::Errno, types::GuestErrorConversion);
impl<'a> strings::Strings for WasiCtx<'a> {
fn hello_string(&self, a_string: &GuestPtr<str>) -> Result<u32, types::Errno> {

View File

@@ -1,5 +1,5 @@
use proptest::prelude::*;
use wiggle::{GuestError, GuestMemory, GuestPtr};
use wiggle::{GuestMemory, GuestPtr};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
@@ -7,7 +7,7 @@ wiggle::from_witx!({
ctx: WasiCtx,
});
impl_errno!(types::Errno);
impl_errno!(types::Errno, types::GuestErrorConversion);
impl<'a> structs::Structs for WasiCtx<'a> {
fn sum_of_pair(&self, an_pair: &types::PairInts) -> Result<i64, types::Errno> {

View File

@@ -1,5 +1,5 @@
use proptest::prelude::*;
use wiggle::{GuestError, GuestMemory, GuestType};
use wiggle::{GuestMemory, GuestType};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
@@ -7,7 +7,7 @@ wiggle::from_witx!({
ctx: WasiCtx,
});
impl_errno!(types::Errno);
impl_errno!(types::Errno, types::GuestErrorConversion);
// Avoid panics on overflow
fn mult_lose_overflow(a: i32, b: u32) -> i32 {

View File

@@ -29,6 +29,13 @@ impl GuestErrorType for types::Errno {
}
}
impl<'a> types::GuestErrorConversion for WasiCtx<'a> {
fn into_errno(&self, e: GuestError) -> types::Errno {
eprintln!("GuestError {:?}", e);
types::Errno::Badf
}
}
impl<'a> crate::wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx<'a> {
fn args_get(&self, _argv: &GuestPtr<GuestPtr<u8>>, _argv_buf: &GuestPtr<u8>) -> Result<()> {
unimplemented!("args_get")