wasi-rs icon indicating copy to clipboard operation
wasi-rs copied to clipboard

witx-bindgen cannot take arrays as parameters

Open Ekleog opened this issue 3 years ago • 1 comments

Running witx-bindgen on this code:

(module $foo
  (import "memory" (memory))
  (@interface func (export "bar")
    (param $buf (array u8))
    (result $error u32)))

generates this code:

// This file is automatically generated, DO NOT EDIT
//
// To regenerate this file run the `crates/witx-bindgen` command

use core::mem::MaybeUninit;

pub use crate::error::Error;
pub type Result<T, E = Error> = core::result::Result<T, E>;
pub unsafe fn bar(buf: &'a [u8]) -> Result<()> {
    let rc = foo::bar(buf.as_ptr(), buf.len());
    if let Some(err) = Error::from_raw_error(rc) {
        Err(err)
    } else {
        Ok(())
    }
}

pub mod foo {
    use super::*;
    #[link(wasm_import_module = "foo")]
    extern "C" {
        pub fn bar(buf_ptr: *const u8, buf_len: usize) -> u32;
    }
}

Which is invalid, as the 'a lifetime is never defined.

Ekleog avatar Jan 07 '21 18:01 Ekleog

(Also, buf should probably be taken by &mut and not &, as the host side gets a mut-able GuestPtr)

Ekleog avatar Jan 07 '21 18:01 Ekleog

This issue is no longer applicable as all the witx infrastructure is now removed and largely considered dated. Modern infrastructure for bindings is built on WIT and wit-bindgen, so I'm going to close this.

alexcrichton avatar Feb 23 '24 15:02 alexcrichton