Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Aug 29, 2023
2 parents e8377e9 + b51922c commit a784ea7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
5 changes: 3 additions & 2 deletions eo-runtime/src/main/rust/eo_env/src/eo_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'local> EOEnv<'_> {
}
}

pub fn dataize(&mut self, v: u32) -> Option<Vec<i8>> {
pub fn dataize(&mut self, v: u32) -> Option<Vec<u8>> {
let java_array = JByteArray::from(
self.java_env
.call_method(
Expand All @@ -114,6 +114,7 @@ impl<'local> EOEnv<'_> {
if self.java_env.get_byte_array_region(&java_array, 0, &mut bytes[0..]).is_err() {
return None;
}
return Some(bytes);
let unsigned = unsafe { &*(&bytes[0..] as *const _ as *const [u8]) };
return Some(unsigned.to_vec());
}
}
9 changes: 3 additions & 6 deletions eo-runtime/src/test/eo/org/eolang/rust-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,12 @@

pub fn foo(env: &mut EOEnv) -> EO {
let a = env.find("$.^.a") as u32;
let b = env.find("$.^.b") as u32;
let bytes_a = env.dataize(a).unwrap();
let mut arr_a = unsafe { &*(&bytes_a[0..] as *const _ as *const [u8]) };
let a = bytes_a.as_slice().read_i64::<BigEndian>().unwrap();

let b = env.find("$.^.b") as u32;
let bytes_b = env.dataize(b).unwrap();
let mut arr_b = unsafe { &*(&bytes_b[0..] as *const _ as *const [u8]) };

let a = arr_a.read_i64::<BigEndian>().unwrap();
let b = arr_b.read_i64::<BigEndian>().unwrap();
let b = bytes_b.as_slice().read_i64::<BigEndian>().unwrap();
println!("sum 5 + 10 = {}", a + b);

EOInt(a + b)
Expand Down

0 comments on commit a784ea7

Please sign in to comment.