Address feedback: misc clean ups

This commit is contained in:
Mark McCaskey
2020-11-25 14:19:29 -08:00
parent de6cb9c4c4
commit 40eec3fbd6
5 changed files with 29 additions and 8 deletions

View File

@@ -130,6 +130,14 @@ impl Instance {
exports,
};
// # Safety
// `initialize_host_envs` should be called after instantiation but before
// returning an `Instance` to the user. We set up the host environments
// via `WasmerEnv::init_with_instance`.
//
// This usage is correct because we pass a valid pointer to `instance` and the
// correct error type returned by `WasmerEnv::init_with_instance` as a generic
// parameter.
unsafe {
instance
.handle

View File

@@ -174,12 +174,12 @@ pub extern "C" fn wasi_env_new(mut config: Box<wasi_config_t>) -> Option<Box<was
#[no_mangle]
pub extern "C" fn wasi_env_delete(_state: Option<Box<wasi_env_t>>) {}
/// This function is deprecated. You may safely remove all calls to it and everything
/// will continue to work.
// Dead code: deprecate or remove
#[allow(unused_variables)]
#[no_mangle]
pub extern "C" fn wasi_env_set_instance(
_env: &mut wasi_env_t,
_instance: &wasm_instance_t,
) -> bool {
pub extern "C" fn wasi_env_set_instance(env: &mut wasi_env_t, instance: &wasm_instance_t) -> bool {
/*
let memory = if let Ok(memory) = instance.inner.exports.get_memory("memory") {
memory
@@ -192,9 +192,12 @@ pub extern "C" fn wasi_env_set_instance(
true
}
/// This function is deprecated. You may safely remove all calls to it and everything
/// will continue to work.
// Dead code: deprecate or remove
#[allow(unused_variables)]
#[no_mangle]
pub extern "C" fn wasi_env_set_memory(_env: &mut wasi_env_t, _memory: &wasm_memory_t) {
pub extern "C" fn wasi_env_set_memory(env: &mut wasi_env_t, memory: &wasm_memory_t) {
//env.inner.set_memory(memory.inner.clone());
}

View File

@@ -145,11 +145,19 @@ intptr_t wasi_env_read_stdout(wasi_env_t *env, char *buffer, uintptr_t buffer_le
#endif
#if defined(WASMER_WASI_ENABLED)
bool wasi_env_set_instance(wasi_env_t *_env, const wasm_instance_t *_instance);
/**
* This function is deprecated. You may safely remove all calls to it and everything
* will continue to work.
*/
bool wasi_env_set_instance(wasi_env_t *env, const wasm_instance_t *instance);
#endif
#if defined(WASMER_WASI_ENABLED)
void wasi_env_set_memory(wasi_env_t *_env, const wasm_memory_t *_memory);
/**
* This function is deprecated. You may safely remove all calls to it and everything
* will continue to work.
*/
void wasi_env_set_memory(wasi_env_t *env, const wasm_memory_t *memory);
#endif
#if defined(WASMER_WASI_ENABLED)

View File

@@ -1163,6 +1163,7 @@ impl InstanceHandle {
/// - This function must be called with the correct `Err` type parameter: the error type is not
/// visible to code in `wasmer_vm`, so it's the caller's responsibility to ensure these
/// functions are called with the correct type.
/// - `instance_ptr` must point to a valid `wasmer::Instance`.
pub unsafe fn initialize_host_envs<Err: Sized>(
&mut self,
instance_ptr: *const std::ffi::c_void,

View File

@@ -82,7 +82,8 @@ impl WasiEnv {
/// Get a reference to the memory
pub fn memory(&self) -> &Memory {
self.memory_ref().unwrap()
self.memory_ref()
.expect("Memory should be set on `WasiEnv` first")
}
pub(crate) fn get_memory_and_wasi_state(