fix(c-api) Use uppercase enum variants for constants of wasi_version_t.

This commit is contained in:
Ivan Enderlin
2021-01-26 12:20:44 +01:00
parent fb50d19191
commit 434285c0f9
2 changed files with 30 additions and 16 deletions

View File

@@ -268,18 +268,18 @@ fn read_inner(wasi_file: &mut Box<dyn WasiFile>, inner_buffer: &mut [u8]) -> isi
#[repr(u32)] #[repr(u32)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub enum wasi_version_t { pub enum wasi_version_t {
Latest = 0, LATEST = 0,
Snapshot0 = 1, SNAPSHOT0 = 1,
Snapshot1 = 2, SNAPSHOT1 = 2,
InvalidVersion = u32::max_value(), INVALID_VERSION = 4294967295, // u32::MAX,
} }
impl From<WasiVersion> for wasi_version_t { impl From<WasiVersion> for wasi_version_t {
fn from(other: WasiVersion) -> Self { fn from(other: WasiVersion) -> Self {
match other { match other {
WasiVersion::Snapshot0 => wasi_version_t::Snapshot0, WasiVersion::Snapshot0 => wasi_version_t::SNAPSHOT0,
WasiVersion::Snapshot1 => wasi_version_t::Snapshot1, WasiVersion::Snapshot1 => wasi_version_t::SNAPSHOT1,
WasiVersion::Latest => wasi_version_t::Latest, WasiVersion::Latest => wasi_version_t::LATEST,
} }
} }
} }
@@ -289,10 +289,10 @@ impl TryFrom<wasi_version_t> for WasiVersion {
fn try_from(other: wasi_version_t) -> Result<Self, Self::Error> { fn try_from(other: wasi_version_t) -> Result<Self, Self::Error> {
Ok(match other { Ok(match other {
wasi_version_t::Snapshot0 => WasiVersion::Snapshot0, wasi_version_t::SNAPSHOT0 => WasiVersion::Snapshot0,
wasi_version_t::Snapshot1 => WasiVersion::Snapshot1, wasi_version_t::SNAPSHOT1 => WasiVersion::Snapshot1,
wasi_version_t::Latest => WasiVersion::Latest, wasi_version_t::LATEST => WasiVersion::Latest,
wasi_version_t::InvalidVersion => return Err("Invalid WASI version cannot be used"), wasi_version_t::INVALID_VERSION => return Err("Invalid WASI version cannot be used"),
}) })
} }
} }
@@ -301,7 +301,7 @@ impl TryFrom<wasi_version_t> for WasiVersion {
pub unsafe extern "C" fn wasi_get_wasi_version(module: &wasm_module_t) -> wasi_version_t { pub unsafe extern "C" fn wasi_get_wasi_version(module: &wasm_module_t) -> wasi_version_t {
get_wasi_version(&module.inner, false) get_wasi_version(&module.inner, false)
.map(Into::into) .map(Into::into)
.unwrap_or(wasi_version_t::InvalidVersion) .unwrap_or(wasi_version_t::INVALID_VERSION)
} }
/// Takes ownership of `wasi_env_t`. /// Takes ownership of `wasi_env_t`.

View File

@@ -62,6 +62,24 @@
#include <stdlib.h> #include <stdlib.h>
#include "wasm.h" #include "wasm.h"
#if defined(WASMER_WASI_ENABLED)
enum wasi_version_t {
#if defined(WASMER_WASI_ENABLED)
LATEST = 0,
#endif
#if defined(WASMER_WASI_ENABLED)
SNAPSHOT0 = 1,
#endif
#if defined(WASMER_WASI_ENABLED)
SNAPSHOT1 = 2,
#endif
#if defined(WASMER_WASI_ENABLED)
INVALID_VERSION = 4294967295,
#endif
};
typedef uint32_t wasi_version_t;
#endif
#if defined(WASMER_COMPILER_ENABLED) #if defined(WASMER_COMPILER_ENABLED)
/** /**
* Kind of compilers that can be used by the engines. * Kind of compilers that can be used by the engines.
@@ -120,10 +138,6 @@ typedef struct wasi_config_t wasi_config_t;
typedef struct wasi_env_t wasi_env_t; typedef struct wasi_env_t wasi_env_t;
#endif #endif
#if defined(WASMER_WASI_ENABLED)
typedef struct wasi_version_t wasi_version_t;
#endif
#if defined(WASMER_WASI_ENABLED) #if defined(WASMER_WASI_ENABLED)
void wasi_config_arg(wasi_config_t *config, const char *arg); void wasi_config_arg(wasi_config_t *config, const char *arg);
#endif #endif