Skip to content

Commit

Permalink
Fix linting (#2418)
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe authored Jun 19, 2024
1 parent b42ac0c commit 5d5b8a7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
5 changes: 3 additions & 2 deletions lib/ffi/src/cps/async_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ impl<V> AsyncStack<V> {
}

pub fn context(&mut self) -> Option<&mut Context<'_>> {
self.context
.map(|context| unsafe { &mut *transmute::<_, *mut _>(context) })
self.context.map(|context| unsafe {
&mut *transmute::<*mut Context<'_>, *mut Context<'_>>(context)
})
}

pub fn run_with_context<T>(
Expand Down
28 changes: 20 additions & 8 deletions lib/ffi/src/future/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ macro_rules! call {
let closure = $closure;

(unsafe {
transmute::<_, InitialStepFunction<_>>(closure.entry_function())
transmute::<*const u8, InitialStepFunction<$result_type>>(closure.entry_function())
})(stack, resolve, closure, $($argument),*);
});
let mut trampoline: Option<Trampoline> = None;
Expand Down Expand Up @@ -77,15 +77,15 @@ mod tests {

#[tokio::test]
async fn call_thunk() {
let value = 42.0;
let value = Number::new(42.0);

assert_eq!(
call!(
fn() -> Number,
Closure::new(thunk_entry_function as *const u8, value),
)
.await,
value.into()
value
);
}

Expand All @@ -105,7 +105,7 @@ mod tests {
assert_eq!(
call!(
fn(Number) -> Number,
Closure::new(closure_entry_function as *const u8, ()),
Closure::new(closure_entry_function as *const u8, Default::default()),
value.into(),
)
.await,
Expand All @@ -128,7 +128,10 @@ mod tests {
assert_eq!(
call!(
fn(Number, Number) -> Number,
Closure::new(closure_2_arity_entry_function as *const u8, ()),
Closure::new(
closure_2_arity_entry_function as *const u8,
Default::default()
),
40.0.into(),
2.0.into(),
)
Expand Down Expand Up @@ -162,7 +165,10 @@ mod tests {
assert_eq!(
call!(
fn() -> Number,
Closure::new(closure_entry_function_with_suspension as *const u8, ()),
Closure::new(
closure_entry_function_with_suspension as *const u8,
Default::default()
),
)
.await,
42.0.into()
Expand All @@ -185,7 +191,10 @@ mod tests {
assert_eq!(
call!(
fn(ByteString) -> ByteString,
Closure::new(closure_entry_function_with_string as *const u8, ()),
Closure::new(
closure_entry_function_with_string as *const u8,
Default::default()
),
value.into(),
)
.await,
Expand All @@ -200,7 +209,10 @@ mod tests {
assert_eq!(
call!(
fn(ByteString) -> ByteString,
Closure::new(closure_entry_function_with_string as *const u8, ()),
Closure::new(
closure_entry_function_with_string as *const u8,
Default::default()
),
value.clone(),
)
.await,
Expand Down
5 changes: 3 additions & 2 deletions lib/ffi/src/future/from_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ pub async fn from_closure<T, V>(closure: Closure<T>) -> V {
step(stack, continue_);
} else {
let closure = closure.take().unwrap();
let entry_function =
unsafe { transmute::<_, InitialStepFunction<V, T>>(closure.entry_function()) };
let entry_function = unsafe {
transmute::<*const u8, InitialStepFunction<V, T>>(closure.entry_function())
};

entry_function(stack, resolve, closure);
}
Expand Down
14 changes: 7 additions & 7 deletions packages/core/ffi/src/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ use core::mem::transmute;

#[ffi::bindgen]
fn _pen_core_bit_and(x: ffi::Number, y: ffi::Number) -> ffi::Number {
unsafe { transmute(transmute::<_, u64>(x) & transmute::<_, u64>(y)) }
unsafe { transmute(transmute::<ffi::Number, u64>(x) & transmute::<ffi::Number, u64>(y)) }
}

#[ffi::bindgen]
fn _pen_core_bit_or(x: ffi::Number, y: ffi::Number) -> ffi::Number {
unsafe { transmute(transmute::<_, u64>(x) | transmute::<_, u64>(y)) }
unsafe { transmute(transmute::<ffi::Number, u64>(x) | transmute::<ffi::Number, u64>(y)) }
}

#[ffi::bindgen]
fn _pen_core_bit_xor(x: ffi::Number, y: ffi::Number) -> ffi::Number {
unsafe { transmute(transmute::<_, u64>(x) ^ transmute::<_, u64>(y)) }
unsafe { transmute(transmute::<ffi::Number, u64>(x) ^ transmute::<ffi::Number, u64>(y)) }
}

#[ffi::bindgen]
fn _pen_core_bit_not(x: ffi::Number) -> ffi::Number {
unsafe { transmute(!transmute::<_, u64>(x)) }
unsafe { transmute(!transmute::<ffi::Number, u64>(x)) }
}

#[ffi::bindgen]
fn _pen_core_bit_left_shift(x: ffi::Number, count: ffi::Number) -> ffi::Number {
unsafe { transmute(transmute::<_, u64>(x) << (f64::from(count) as u64)) }
unsafe { transmute(transmute::<ffi::Number, u64>(x) << (f64::from(count) as u64)) }
}

#[ffi::bindgen]
fn _pen_core_bit_right_shift(x: ffi::Number, count: ffi::Number) -> ffi::Number {
unsafe { transmute(transmute::<_, u64>(x) >> (f64::from(count) as u64)) }
unsafe { transmute(transmute::<ffi::Number, u64>(x) >> (f64::from(count) as u64)) }
}

#[ffi::bindgen]
Expand All @@ -37,7 +37,7 @@ fn _pen_core_bit_to_integer_64(x: ffi::Number) -> ffi::Number {

#[ffi::bindgen]
fn _pen_core_bit_from_integer_64(x: ffi::Number) -> ffi::Number {
(unsafe { transmute::<_, u64>(x) } as f64).into()
(unsafe { transmute::<ffi::Number, u64>(x) } as f64).into()
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions packages/os-sync/ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
resolver = "2"
members = ["application", "library"]

0 comments on commit 5d5b8a7

Please sign in to comment.