Skip to content

Commit

Permalink
Merge branch 'main' into code-review
Browse files Browse the repository at this point in the history
  • Loading branch information
jayz22 authored Sep 14, 2023
2 parents 4897658 + 0d7b94e commit de9b15c
Show file tree
Hide file tree
Showing 21 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion soroban-env-common/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ soroban_env_macros::generate_env_meta_consts!(
#[cfg(not(feature = "next"))]
soroban_env_macros::generate_env_meta_consts!(
ledger_protocol_version: 20,
pre_release_version: 57,
pre_release_version: 58,
);

pub const fn get_ledger_protocol_version(interface_version: u64) -> u32 {
Expand Down
35 changes: 20 additions & 15 deletions soroban-env-host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,20 +1078,25 @@ impl EnvBase for Host {
}

fn map_new_from_slices(&self, keys: &[&str], vals: &[Val]) -> Result<MapObject, HostError> {
Vec::<Symbol>::charge_bulk_init_cpy(keys.len() as u64, self)?;
// If only fallible iterators worked better in Rust, we would not need this Vec<...>.
let mut key_syms: Vec<Symbol> = Vec::with_capacity(keys.len());
for k in keys.iter() {
key_syms.push(Symbol::try_from_val(self, k)?);
}
for v in vals.iter() {
self.check_val_integrity(*v)?;
if keys.len() != vals.len() {
return Err(self.err(
ScErrorType::Object,
ScErrorCode::UnexpectedSize,
"differing key and value slice lengths when creating map from slices",
&[],
));
}
let pair_iter = key_syms
Vec::<(Val, Val)>::charge_bulk_init_cpy(keys.len() as u64, self)?;
let map_vec = keys
.iter()
.map(|s| s.to_val())
.zip(vals.iter().cloned());
let map = HostMap::from_exact_iter(pair_iter, self)?;
.zip(vals.iter().copied())
.map(|(key_str, val)| {
let sym = Symbol::try_from_val(self, key_str)?;
self.check_val_integrity(val)?;
Ok((sym.to_val(), val))
})
.collect::<Result<Vec<(Val, Val)>, HostError>>()?;
let map = HostMap::from_map(map_vec, self)?;
self.add_host_object(map)
}

Expand All @@ -1105,7 +1110,7 @@ impl EnvBase for Host {
return Err(self.err(
ScErrorType::Object,
ScErrorCode::UnexpectedSize,
"differing key and value vector lengths when unpacking map to slice",
"differing key and value slice lengths when unpacking map to slice",
&[],
));
}
Expand All @@ -1114,7 +1119,7 @@ impl EnvBase for Host {
return Err(self.err(
ScErrorType::Object,
ScErrorCode::UnexpectedSize,
"differing host map and output vector lengths when unpacking map to slice",
"differing host map and output slice lengths when unpacking map to slice",
&[],
));
}
Expand Down Expand Up @@ -1160,7 +1165,7 @@ impl EnvBase for Host {

fn symbol_index_in_strs(&self, sym: Symbol, slices: &[&str]) -> Result<U32Val, Self::Error> {
let mut found = None;
self.metered_scan_slice_of_slices(slices, |i, slice| {
self.scan_slice_of_slices(slices, |i, slice| {
if self.symbol_matches(slice.as_bytes(), sym)? && found.is_none() {
found = Some(i)
}
Expand Down
4 changes: 1 addition & 3 deletions soroban-env-host/src/host/mem_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl Host {
Ok(())
}

pub(crate) fn metered_scan_slice_of_slices(
pub(crate) fn scan_slice_of_slices(
&self,
slices: &[&str],
mut callback: impl FnMut(usize, &str) -> Result<(), HostError>,
Expand Down Expand Up @@ -303,8 +303,6 @@ impl Host {
let obj_end = obj_pos
.checked_add(len)
.ok_or_else(|| self.err_arith_overflow())? as usize;
// TODO: we currently grow the destination vec if it's not big enough,
// make sure this is desirable behaviour.
if obj_new.len() < obj_end {
self.charge_budget(
ContractCostType::HostMemAlloc,
Expand Down
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/curr/example_add_f32.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/curr/example_add_i32.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/curr/example_alloc.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/curr/example_complex.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/curr/example_err.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/curr/example_fannkuch.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/curr/example_fib.wasm
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/curr/example_hostile.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified soroban-test-wasms/wasm-workspace/opt/curr/example_vec.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit de9b15c

Please sign in to comment.