clippy: clear the workspace errors and apply the machine fixes

- Mark the raw-pointer interop entry points unsafe with # Safety docs
  (oak-core upload/download/frame-from-pixels, oak-audio convert) and
  satisfy the existing callers (tests).
- mut_from_ref: allow with the ABI contract documented (the handle
  get_mut helpers in oak-timeline/oak-render/oak-task take the shared
  reference the C ABI passes; exclusivity is the caller's unsafe
  contract).
- Fix the eq_op in the white-balance normalization (green / green).
- Apply cargo clippy --fix across the workspace (redundant closures and
  field names, field reassignment, items after test modules, ...).
- Revert the replace_box fix in image_effect's clip_define: a
  redefinition must allocate a new box, otherwise the old clip handle
  stays valid and the HS-map replace contract (clip != clip2) breaks.
- 283 warnings remain; they are all non-machine-applicable
  (chunks_exact -> as_chunks needs a manual iter_mut, too_many_arguments,
  complex types, missing Safety docs, ...) and are tracked as the
  follow-up.
This commit is contained in:
2026-09-15 19:29:32 +08:00
parent 7e87ec135e
commit ee7ea18d94
146 changed files with 5235 additions and 4046 deletions
@@ -12,7 +12,9 @@ use oak_render::ticket::{AudioTicketParams, MontageClip, TicketPayload};
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() < 6 {
eprintln!("usage: render_audio_wav <media> <stream_index> <start_sec> <end_sec> <out.wav> [fps]");
eprintln!(
"usage: render_audio_wav <media> <stream_index> <start_sec> <end_sec> <out.wav> [fps]"
);
std::process::exit(64);
}
let media = &args[1];
@@ -20,7 +22,11 @@ fn main() {
let start_sec: f64 = args[3].parse().unwrap();
let end_sec: f64 = args[4].parse().unwrap();
let out_path = &args[5];
let fps: i64 = if args.len() > 6 { args[6].parse().unwrap() } else { 25 };
let fps: i64 = if args.len() > 6 {
args[6].parse().unwrap()
} else {
25
};
let sample_rate = 48000i32;
let channel_layout = 0x3u64; // stereo
@@ -58,7 +64,7 @@ fn main() {
other => {
eprintln!("frame {f}: render failed: {:?}", other.is_err());
let frames = ((sample_rate as f64) / fps as f64).round() as usize;
pcm.extend(std::iter::repeat(0i16).take(frames * channels));
pcm.extend(std::iter::repeat_n(0i16, frames * channels));
}
}
}
+6 -6
View File
@@ -144,7 +144,7 @@ fn uuid_text_to_bytes(uuid: &str) -> [u8; 16] {
break;
}
let d = c.to_digit(16).unwrap_or(0) as u8;
if nibble % 2 == 0 {
if nibble.is_multiple_of(2) {
bytes[nibble / 2] = d << 4;
} else {
bytes[nibble / 2] |= d;
@@ -286,7 +286,7 @@ impl PlaybackCache {
pub fn set_uuid(&mut self, uuid: &str) {
self.uuid = uuid.to_string();
let dir = self.disk_dir.clone();
let _ = self.load_state(&std::path::Path::new(&dir));
let _ = self.load_state(std::path::Path::new(&dir));
}
/// Set the frame timebase (frame-hash flavors; C++ `set_timebase`).
@@ -319,7 +319,7 @@ impl PlaybackCache {
self.passthroughs.retain(|(r, _)| !overlaps(*r, range));
if self.saving_enabled {
let dir = self.disk_dir.clone();
let _ = self.save_state(&std::path::Path::new(&dir));
let _ = self.save_state(std::path::Path::new(&dir));
}
}
@@ -328,7 +328,7 @@ impl PlaybackCache {
self.validated.insert(range);
if self.saving_enabled {
let dir = self.disk_dir.clone();
let _ = self.save_state(&std::path::Path::new(&dir));
let _ = self.save_state(std::path::Path::new(&dir));
}
}
@@ -401,7 +401,7 @@ impl PlaybackCache {
}
if self.saving_enabled {
let dir = self.disk_dir.clone();
let _ = self.save_state(&std::path::Path::new(&dir));
let _ = self.save_state(std::path::Path::new(&dir));
}
}
@@ -421,7 +421,7 @@ impl PlaybackCache {
}
if self.saving_enabled {
let dir = self.disk_dir.clone();
let _ = self.save_state(&std::path::Path::new(&dir));
let _ = self.save_state(std::path::Path::new(&dir));
}
}
+4 -4
View File
@@ -559,7 +559,7 @@ impl RenderEvalHooks {
in_flight: &mut HashSet<usize>,
) -> NodeValue {
let mut payload = payload.clone();
for (_, value) in payload.params.iter_mut() {
for value in payload.params.values_mut() {
self.resolve_value(value, depth, in_flight);
}
match self.process_shader_job(&payload) {
@@ -584,7 +584,7 @@ impl RenderEvalHooks {
in_flight: &mut HashSet<usize>,
) -> Option<NodeValue> {
let mut payload = payload.clone();
for (_, value) in payload.values.iter_mut() {
for value in payload.values.values_mut() {
self.resolve_value(value, depth, in_flight);
}
@@ -843,7 +843,7 @@ impl RenderEvalHooks {
return None;
}
let nested = (unsafe { oak_node::jobs::shader_job(handle) }).cloned()?;
Some(self.process_shader_job_depth(&nested, depth + 1)?)
self.process_shader_job_depth(&nested, depth + 1)
});
let tex = tex?;
let (token, tex_size) = match &tex {
@@ -1797,7 +1797,7 @@ fn blend_transition(
// Fallback: without a blend (a missing side, or a shader job that
// could not run) show the side that natively covers `time` — the
// outgoing block before the cut, the incoming one at or after it.
Ok(blended.or_else(|| if progress < 0.5 { from } else { to }))
Ok(blended.or(if progress < 0.5 { from } else { to }))
}
/// Walk an adjustment block's effect chain to its head: the first node
+5
View File
@@ -100,6 +100,11 @@ pub unsafe fn get<T: Any>(h: &CHandle) -> Option<&T> {
/// `T` must be the boxed type, and the caller must guarantee the handle
/// is not concurrently borrowed (the C ABI contract: a handle passed by
/// value is exclusively owned for the duration of the call).
// The shared reference is the ABI input; exclusivity is the caller's
// `unsafe` contract above, so the lint's usual aliasing concern is
// discharged by the caller, not by `&mut CHandle` (which the C ABI does
// not pass).
#[allow(clippy::mut_from_ref)]
pub unsafe fn get_mut<T: Any>(h: &CHandle) -> Option<&mut T> {
if h.is_null() {
return None;
+6 -9
View File
@@ -287,9 +287,11 @@ pub struct HelloCapsMsg {
/// representation and are dropped by [`WireNodeValue::from_node_value`].
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(tag = "t", content = "v", rename_all = "snake_case")]
#[derive(Default)]
pub enum WireNodeValue {
/// No value.
None,
#[default]
None,
/// Integer.
Int(i64),
/// Float.
@@ -318,11 +320,6 @@ pub enum WireNodeValue {
Binary(Vec<u8>),
}
impl Default for WireNodeValue {
fn default() -> Self {
WireNodeValue::None
}
}
impl WireNodeValue {
/// The wire form of a node value, or `None` when the variant has no
@@ -1174,7 +1171,8 @@ impl FrameSlotPool {
if unsafe { (*header).magic } != FRAMEPOOL_MAGIC {
return FrameSlotPool::invalid();
}
let pool = unsafe {
unsafe {
FrameSlotPool {
base: mem,
header,
@@ -1183,8 +1181,7 @@ impl FrameSlotPool {
meta: mem.add((*header).meta_offset as usize) as *mut FrameSlotMeta,
data: mem.add((*header).data_offset as usize),
}
};
pool
}
}
/// An invalid pool (attach on a non-pool segment).
+3 -4
View File
@@ -1379,11 +1379,10 @@ impl ProcessDispatcher {
pub fn broadcast_plugin_cancel(&self) {
let mut inner = lock(&self.inner);
for handle in inner.workers.iter_mut() {
if matches!(handle.state, WorkerState::Alive | WorkerState::Starting) {
if self.send_json(handle, &plugin_cancel_json()).is_err() {
if matches!(handle.state, WorkerState::Alive | WorkerState::Starting)
&& self.send_json(handle, &plugin_cancel_json()).is_err() {
handle.state = WorkerState::Dead;
}
}
}
}
@@ -2386,7 +2385,7 @@ impl JobDispatch for ProcessDispatcher {
// Every ticket still open completes with cancellation; the map
// is dropped with the dispatcher (clear for hygiene — leaked
// entries pin shm region views).
for (_, pt) in inner.tickets.iter_mut() {
for pt in inner.tickets.values_mut() {
if let Some(done) = pt.done.take() {
fired.push((done, Err(Error::State)));
}
+11 -9
View File
@@ -75,24 +75,27 @@ fn footage_decode_renders_known_content() {
let off = y * stride + x * 16;
let mut out = [0f32; 4];
for i in 0..4 {
out[i] = f32::from_le_bytes(
frame.data[off + i * 4..off + i * 4 + 4]
.try_into()
.unwrap(),
);
out[i] =
f32::from_le_bytes(frame.data[off + i * 4..off + i * 4 + 4].try_into().unwrap());
}
out
};
for &(x, y) in &[(8usize, 32usize), (20, 10)] {
let [r, g, b, a] = read(x, y);
assert!(r > 0.5, "left half red at ({x},{y}): {r}");
assert!(g < 0.4 && b < 0.4, "left half not red at ({x},{y}): {r},{g},{b}");
assert!(
g < 0.4 && b < 0.4,
"left half not red at ({x},{y}): {r},{g},{b}"
);
assert!(a > 0.9, "opaque at ({x},{y}): {a}");
}
for &(x, y) in &[(56usize, 32usize), (40, 50)] {
let [r, g, b, a] = read(x, y);
assert!(b > 0.5, "right half blue at ({x},{y}): {b}");
assert!(r < 0.4 && g < 0.4, "right half not blue at ({x},{y}): {r},{g},{b}");
assert!(
r < 0.4 && g < 0.4,
"right half not blue at ({x},{y}): {r},{g},{b}"
);
assert!(a > 0.9, "opaque at ({x},{y}): {a}");
}
@@ -131,7 +134,6 @@ fn footage_decode_fails_explainably_for_missing_file() {
(16, 16),
PixelFormat::F32,
)
.err()
.expect("decode of a missing file must fail");
.expect_err("decode of a missing file must fail");
let _ = err.code(); // explainable error, not a panic
}
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -11,7 +11,7 @@ fn filled_frame(size: (i32, i32), rgba: [f32; 4]) -> Texture {
Texture::wrap_frame(f)
}
fn pixel_at(frame: &oak_core::texture::Frame, x: usize, y: usize) -> [f32; 4] {
let stride = frame.linesize_bytes() as usize;
let stride = frame.linesize_bytes();
let at = y * stride + x * 16;
let mut out = [0f32; 4];
for c in 0..4 { out[c] = f32::from_le_bytes(frame.data[at + c*4..at + c*4 + 4].try_into().unwrap()); }
+1 -1
View File
@@ -11,7 +11,7 @@ fn filled_frame(size: (i32, i32), rgba: [f32; 4]) -> Texture {
Texture::wrap_frame(f)
}
fn pixel_at(frame: &oak_core::texture::Frame, x: usize, y: usize) -> [f32; 4] {
let stride = frame.linesize_bytes() as usize;
let stride = frame.linesize_bytes();
let at = y * stride + x * 16;
let mut out = [0f32; 4];
for c in 0..4 { out[c] = f32::from_le_bytes(frame.data[at + c*4..at + c*4 + 4].try_into().unwrap()); }
+2 -2
View File
@@ -11,7 +11,7 @@ fn filled_frame(size: (i32, i32), rgba: [f32; 4]) -> Texture {
Texture::wrap_frame(f)
}
fn pixel_at(frame: &oak_core::texture::Frame, x: usize, y: usize) -> [f32; 4] {
let stride = frame.linesize_bytes() as usize;
let stride = frame.linesize_bytes();
let at = y * stride + x * 16;
let mut out = [0f32; 4];
for c in 0..4 { out[c] = f32::from_le_bytes(frame.data[at + c*4..at + c*4 + 4].try_into().unwrap()); }
@@ -44,7 +44,7 @@ const BLACK: [f32; 4] = [0.0, 0.0, 0.0, 1.0];
/// Paint one RGBA pixel into a CPU frame (these F32 frames are 16 bytes a
/// pixel).
fn paint(frame: &mut oak_core::texture::Frame, x: usize, y: usize, rgba: [f32; 4]) {
let at = y * frame.linesize_bytes() as usize + x * 16;
let at = y * frame.linesize_bytes() + x * 16;
for (c, v) in rgba.iter().enumerate() {
frame.data[at + c * 4..at + c * 4 + 4].copy_from_slice(&v.to_le_bytes());
}
+1 -1
View File
@@ -11,7 +11,7 @@ fn filled_frame(size: (i32, i32), rgba: [f32; 4]) -> Texture {
Texture::wrap_frame(f)
}
fn pixel_at(frame: &oak_core::texture::Frame, x: usize, y: usize) -> [f32; 4] {
let stride = frame.linesize_bytes() as usize;
let stride = frame.linesize_bytes();
let at = y * stride + x * 16;
let mut out = [0f32; 4];
for c in 0..4 { out[c] = f32::from_le_bytes(frame.data[at + c*4..at + c*4 + 4].try_into().unwrap()); }
+1 -1
View File
@@ -11,7 +11,7 @@ fn filled_frame(size: (i32, i32), rgba: [f32; 4]) -> Texture {
Texture::wrap_frame(f)
}
fn pixel_at(frame: &oak_core::texture::Frame, x: usize, y: usize) -> [f32; 4] {
let stride = frame.linesize_bytes() as usize;
let stride = frame.linesize_bytes();
let at = y * stride + x * 16;
let mut out = [0f32; 4];
for c in 0..4 { out[c] = f32::from_le_bytes(frame.data[at + c*4..at + c*4 + 4].try_into().unwrap()); }
+1 -1
View File
@@ -18,7 +18,7 @@ fn filled_frame(size: (i32, i32), rgba: [f32; 4]) -> Texture {
Texture::wrap_frame(f)
}
fn pixel_at(frame: &oak_core::texture::Frame, x: usize, y: usize) -> [f32; 4] {
let stride = frame.linesize_bytes() as usize;
let stride = frame.linesize_bytes();
let at = y * stride + x * 16;
let mut out = [0f32; 4];
for c in 0..4 { out[c] = f32::from_le_bytes(frame.data[at + c*4..at + c*4 + 4].try_into().unwrap()); }
+1 -1
View File
@@ -47,7 +47,7 @@ fn gradient_frame_x(size: (i32, i32)) -> Texture {
Texture::wrap_frame(f)
}
fn pixel_at(frame: &oak_core::texture::Frame, x: usize, y: usize) -> [f32; 4] {
let stride = frame.linesize_bytes() as usize;
let stride = frame.linesize_bytes();
let at = y * stride + x * 16;
let mut out = [0f32; 4];
for c in 0..4 { out[c] = f32::from_le_bytes(frame.data[at + c*4..at + c*4 + 4].try_into().unwrap()); }