Skip to content

Commit

Permalink
Remove redundant checks form api::Global::set
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McCaskey committed Sep 3, 2020
1 parent b407144 commit c2a10c4
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions lib/api/src/externals/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Global {
});
unsafe {
global
.set(val.clone())
.set_unchecked(val.clone())
.map_err(|e| RuntimeError::new(format!("create global for {:?}: {}", val, e)))?;
};

Expand Down Expand Up @@ -76,25 +76,13 @@ impl Global {
/// * The global is not mutable
/// * The type of the `Val` doesn't matches the Global type.
pub fn set(&self, val: Val) -> Result<(), RuntimeError> {
if self.ty().mutability != Mutability::Var {
return Err(RuntimeError::new(
"immutable global cannot be set".to_string(),
));
}
if val.ty() != self.ty().ty {
return Err(RuntimeError::new(format!(
"global of type {:?} cannot be set to {:?}",
self.ty().ty,
val.ty()
)));
}
if !val.comes_from_same_store(&self.store) {
return Err(RuntimeError::new("cross-`Store` values are not supported"));
}
unsafe {
self.global
.set(val)
.map_err(|e| RuntimeError::new(format!("Failed to set global: {}", e)))?;
.map_err(|e| RuntimeError::new(format!("{}", e)))?;
}
Ok(())
}
Expand Down

0 comments on commit c2a10c4

Please sign in to comment.