Skip to content

Commit

Permalink
Merge pull request #2417 from aarroyoc/fix-2416
Browse files Browse the repository at this point in the history
Manage Float and Double FFI types in structs
  • Loading branch information
mthom authored Jun 7, 2024
2 parents 2d18e0d + a72632a commit d6ac035
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,18 @@ impl ForeignFunctionTable {
}
libffi::raw::FFI_TYPE_SINT64 => read_and_push_int!(i64),
libffi::raw::FFI_TYPE_POINTER => read_and_push_int!(i64),
libffi::raw::FFI_TYPE_FLOAT => {
field_ptr = field_ptr.add(field_ptr.align_offset(std::mem::align_of::<f32>()));
let n = std::ptr::read(field_ptr as *mut f32);
returns.push(Value::Float(f32::from(n).into()));
field_ptr = field_ptr.add(std::mem::size_of::<f32>());
}
libffi::raw::FFI_TYPE_DOUBLE => {
field_ptr = field_ptr.add(field_ptr.align_offset(std::mem::align_of::<f64>()));
let n = std::ptr::read(field_ptr as *mut f64);
returns.push(Value::Float(f64::from(n)));
field_ptr = field_ptr.add(std::mem::size_of::<f64>());
}
libffi::raw::FFI_TYPE_STRUCT => {
let substruct = struct_type.atom_fields[i].as_str();
let struct_type = self
Expand Down

0 comments on commit d6ac035

Please sign in to comment.