Skip to content

Commit

Permalink
offset_of!: Translate all offsetofs.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen committed Dec 8, 2023
1 parent 96f7feb commit a033fee
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/cdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::cmp;
use std::ffi::c_int;
use std::ffi::c_uint;
use std::ffi::c_void;
use std::mem;

#[repr(C)]
pub struct CdfContext {
Expand Down Expand Up @@ -5682,7 +5683,7 @@ 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::<CdfThreadContext>()).wrapping_sub(8),
::core::mem::size_of::<CdfThreadContext>() - mem::offset_of!(CdfThreadContext, data),
);
rav1d_ref_dec(&mut (*cdf).r#ref);
}
1 change: 1 addition & 0 deletions tests/seek_stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![allow(non_upper_case_globals)]
#![feature(extern_types)]
#![feature(c_variadic)]
#![feature(offset_of)]
#![allow(clippy::all)]

#[path = "../tools/input"]
Expand Down
1 change: 1 addition & 0 deletions tools/dav1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![allow(non_upper_case_globals)]
#![feature(extern_types)]
#![feature(c_variadic)]
#![feature(offset_of)]
#![allow(clippy::all)]

mod input {
Expand Down
3 changes: 2 additions & 1 deletion tools/input/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::ffi::c_char;
use std::ffi::c_int;
use std::ffi::c_uint;
use std::ffi::c_void;
use std::mem;

extern "C" {
pub type DemuxerPriv;
Expand Down Expand Up @@ -156,7 +157,7 @@ pub unsafe fn input_open(
}
c = calloc(
1,
(16 as usize).wrapping_add((*impl_0).priv_data_size as usize),
mem::offset_of!(DemuxerContext, priv_data) + (*impl_0).priv_data_size as usize,
) as *mut DemuxerContext;
if c.is_null() {
fprintf(
Expand Down
4 changes: 3 additions & 1 deletion tools/output/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::ffi::c_long;
use std::ffi::c_uint;
use std::ffi::c_ulong;
use std::ffi::c_void;
use std::mem;

extern "C" {
pub type MuxerPriv;
Expand Down Expand Up @@ -160,7 +161,8 @@ pub unsafe fn output_open(
return -ENOPROTOOPT;
}
}
c = malloc((48 as usize).wrapping_add((*impl_0).priv_data_size as usize)) as *mut MuxerContext;
c = malloc(mem::offset_of!(MuxerContext, priv_data) + (*impl_0).priv_data_size as usize)
as *mut MuxerContext;
if c.is_null() {
fprintf(
stderr,
Expand Down

0 comments on commit a033fee

Please sign in to comment.