From 3d7301fa649f415fc7a8bc4c29bc6d1e1a5cdba3 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 5 Dec 2023 23:00:30 -0800 Subject: [PATCH 1/3] `fn rav1d_cdf_thread_unref`: Make `cdf` arg a ref. --- src/cdf.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cdf.rs b/src/cdf.rs index 94f182ef1..034dcd92e 100644 --- a/src/cdf.rs +++ b/src/cdf.rs @@ -5679,11 +5679,11 @@ pub unsafe fn rav1d_cdf_thread_ref(dst: *mut CdfThreadContext, src: *mut CdfThre } } -pub unsafe fn rav1d_cdf_thread_unref(cdf: *mut CdfThreadContext) { +pub unsafe fn rav1d_cdf_thread_unref(cdf: &mut CdfThreadContext) { memset( - &mut (*cdf).data as *mut CdfThreadContext_data as *mut c_void, + &mut cdf.data as *mut CdfThreadContext_data as *mut c_void, 0 as c_int, ::core::mem::size_of::() - mem::offset_of!(CdfThreadContext, data), ); - rav1d_ref_dec(&mut (*cdf).r#ref); + rav1d_ref_dec(&mut cdf.r#ref); } From d94835a8567b497c11011acdd02dbb90e8e8a526 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 5 Dec 2023 23:10:21 -0800 Subject: [PATCH 2/3] `fn rav1d_cdf_thread_unref`: Replace a `memset` with `offset_of` with a normal assignment with 0s. --- lib.rs | 1 - src/cdf.rs | 16 +++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib.rs b/lib.rs index faed6eb12..fd8958691 100644 --- a/lib.rs +++ b/lib.rs @@ -3,7 +3,6 @@ #![allow(non_upper_case_globals)] #![feature(c_variadic)] #![feature(core_intrinsics)] -#![feature(offset_of)] // TODO(kkysen) Will be removed shortly. #![cfg_attr(target_arch = "arm", feature(stdsimd))] #![allow(clippy::all)] diff --git a/src/cdf.rs b/src/cdf.rs index 034dcd92e..34d68c298 100644 --- a/src/cdf.rs +++ b/src/cdf.rs @@ -23,12 +23,11 @@ use crate::src::r#ref::rav1d_ref_inc; use crate::src::r#ref::Rav1dRef; use crate::src::tables::dav1d_partition_type_count; use libc::memcpy; -use libc::memset; use std::cmp; use std::ffi::c_int; use std::ffi::c_uint; use std::ffi::c_void; -use std::mem; +use std::ptr; #[repr(C)] pub struct CdfContext { @@ -5680,10 +5679,13 @@ pub unsafe fn rav1d_cdf_thread_ref(dst: *mut CdfThreadContext, src: *mut CdfThre } pub unsafe fn rav1d_cdf_thread_unref(cdf: &mut CdfThreadContext) { - memset( - &mut cdf.data as *mut CdfThreadContext_data as *mut c_void, - 0 as c_int, - ::core::mem::size_of::() - mem::offset_of!(CdfThreadContext, data), - ); + *cdf = CdfThreadContext { + r#ref: cdf.r#ref, + data: CdfThreadContext_data { + cdf: ptr::null_mut(), + // cdf is larger than qcat, so this zeroes it + }, + progress: ptr::null_mut(), + }; rav1d_ref_dec(&mut cdf.r#ref); } From fc2341e3b5df7eb37bdcb1bd23f7a87009fc0dcc Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Tue, 5 Dec 2023 23:13:05 -0800 Subject: [PATCH 3/3] `fn {in,out}put_open`: Replace `offset_of`s of trailing ZSTs with `size_of`s as they are equivalent due to the ZST. --- tests/seek_stress.rs | 1 - tools/dav1d.rs | 1 - tools/input/input.rs | 2 +- tools/output/output.rs | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/seek_stress.rs b/tests/seek_stress.rs index 4adc0cd97..1a37991f5 100644 --- a/tests/seek_stress.rs +++ b/tests/seek_stress.rs @@ -2,7 +2,6 @@ #![allow(non_upper_case_globals)] #![feature(extern_types)] #![feature(c_variadic)] -#![feature(offset_of)] #![allow(clippy::all)] #[path = "../tools/input"] diff --git a/tools/dav1d.rs b/tools/dav1d.rs index e54189ed4..f31853817 100644 --- a/tools/dav1d.rs +++ b/tools/dav1d.rs @@ -2,7 +2,6 @@ #![allow(non_upper_case_globals)] #![feature(extern_types)] #![feature(c_variadic)] -#![feature(offset_of)] #![allow(clippy::all)] mod input { diff --git a/tools/input/input.rs b/tools/input/input.rs index 6fa659ded..163bf775e 100644 --- a/tools/input/input.rs +++ b/tools/input/input.rs @@ -157,7 +157,7 @@ pub unsafe fn input_open( } c = calloc( 1, - mem::offset_of!(DemuxerContext, priv_data) + (*impl_0).priv_data_size as usize, + mem::size_of::() + (*impl_0).priv_data_size as usize, ) as *mut DemuxerContext; if c.is_null() { fprintf( diff --git a/tools/output/output.rs b/tools/output/output.rs index 4d6e92b28..646fce60b 100644 --- a/tools/output/output.rs +++ b/tools/output/output.rs @@ -161,7 +161,7 @@ pub unsafe fn output_open( return -ENOPROTOOPT; } } - c = malloc(mem::offset_of!(MuxerContext, priv_data) + (*impl_0).priv_data_size as usize) + c = malloc(mem::size_of::() + (*impl_0).priv_data_size as usize) as *mut MuxerContext; if c.is_null() { fprintf(