Issue 3223: more unsafe scope refinements

This commit is contained in:
Alexander McLin
2026-04-08 19:39:05 -04:00
parent 9d49415449
commit fbc5345c9a
2 changed files with 29 additions and 44 deletions

View File

@@ -65,20 +65,16 @@ impl FunctionImpl {
Integer: From<T>,
T: Copy + TryInto<i64> + MightNotFitInFixnum,
{
unsafe {
let n = self.cif.call::<T>(self.code_ptr, args);
let n = unsafe { self.cif.call::<T>(self.code_ptr, args) };
Ok(Value::Number(fixnum!(Number, n, arena)))
}
}
unsafe fn call_float<T>(&self, args: &[Arg], _: &mut Arena) -> Result<Value, FfiError>
where
T: Into<f64>,
{
unsafe {
let n = self.cif.call::<T>(self.code_ptr, args);
let n = unsafe { self.cif.call::<T>(self.code_ptr, args) };
Ok(Value::Number(Number::Float(OrderedFloat(n.into()))))
}
}
unsafe fn call_ptr(&self, args: &[Arg], arena: &mut Arena) -> Result<Value, FfiError> {
@@ -270,11 +266,9 @@ impl StructImpl {
let (new_layout, offset) = layout
.extend(Layout::new::<T>())
.map_err(|_| FfiError::LayoutError)?;
*layout = new_layout;
unsafe {
let n = std::ptr::read::<T>(ptr.byte_offset(offset as isize).cast());
*layout = new_layout;
let n = unsafe { std::ptr::read::<T>(ptr.byte_offset(offset as isize).cast()) };
Ok(n)
}
}
unsafe fn read_int<T>(
@@ -286,10 +280,9 @@ impl StructImpl {
T: Copy + TryInto<i64> + MightNotFitInFixnum,
Integer: From<T>,
{
unsafe {
let n = read_primitive::<T>(ptr, layout)?;
let n = unsafe { read_primitive::<T>(ptr, layout)? };
Ok(Value::Number(fixnum!(Number, n, arena)))
}
}
unsafe fn read_float<T>(
@@ -299,10 +292,8 @@ impl StructImpl {
where
T: Into<f64>,
{
unsafe {
let n = read_primitive::<T>(ptr, layout)?;
let n = unsafe { read_primitive::<T>(ptr, layout)? };
Ok(Value::Number(Number::Float(OrderedFloat(n.into()))))
}
}
let mut layout = Layout::from_size_align(0, 1).map_err(|_| FfiError::LayoutError)?;
@@ -803,10 +794,8 @@ impl ForeignFunctionTable {
T: Copy + TryInto<i64> + MightNotFitInFixnum,
Integer: From<T>,
{
unsafe {
let n = ptr.cast::<T>().read();
let n = unsafe { ptr.cast::<T>().read() };
Value::Number(fixnum!(Number, n, arena))
}
}
let ptr = ptr.as_ptr()?;