Skip to content

Commit

Permalink
fix(runtime-c-api) wasmer_instance_context_data_get returns void
Browse files Browse the repository at this point in the history
…if `instance` is null.
  • Loading branch information
Hywan committed Jan 20, 2020
1 parent c89f53b commit df2b93e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/runtime-c-api/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,25 @@ pub extern "C" fn wasmer_instance_context_memory(
memory as *const Memory as *const wasmer_memory_t
}

/// Gets the `data` field within the context.
/// Gets the data that can be hold by an instance.
///
/// This function is complementary of
/// `wasmer_instance_context_data_set()`. Please read its
/// documentation. You can also read the documentation of
/// `wasmer_instance_context_t` to get other examples.
///
/// This function returns nothing if `ctx` is a null pointer.
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_instance_context_data_get(
ctx: *const wasmer_instance_context_t,
) -> *mut c_void {
if ctx.is_null() {
return ptr::null_mut() as _;
}

let ctx = unsafe { &*(ctx as *const Ctx) };

ctx.data
}

Expand Down

0 comments on commit df2b93e

Please sign in to comment.