Skip to content

Commit

Permalink
static dav1d_scans: Make safe (i.e. non-mut) by using `static [u1…
Browse files Browse the repository at this point in the history
…6]`s instead of `*const u16`s (#356)

Non-`mut` `static`s can't contain internal raw ptrs, so this is needed
to make it safe. All use sites implicitly coerce from slice to raw ptr.

See my suggestion for future work in
#354 (review);
it was simple so I just did it.
  • Loading branch information
kkysen authored Aug 7, 2023
2 parents a1fd5bb + 6191b6a commit dc22537
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
5 changes: 2 additions & 3 deletions src/recon_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ extern "C" {
);
fn dav1d_copy_lpf_16bpc(f: *mut Dav1dFrameContext, src: *const *mut pixel, sby: libc::c_int);
fn dav1d_lr_sbrow_16bpc(f: *mut Dav1dFrameContext, dst: *const *mut pixel, sby: libc::c_int);
static dav1d_scans: [*const uint16_t; 19];
static mut dav1d_wedge_masks: [[[[*const uint8_t; 16]; 2]; 3]; 22];
static mut dav1d_ii_masks: [[[*const uint8_t; 4]; 3]; 22];
}
Expand All @@ -63,11 +62,11 @@ use crate::src::msac::dav1d_msac_decode_hi_tok;
use crate::src::msac::dav1d_msac_decode_symbol_adapt16;
use crate::src::msac::dav1d_msac_decode_symbol_adapt4;
use crate::src::msac::dav1d_msac_decode_symbol_adapt8;
use crate::src::scan::dav1d_scans;
use crate::src::tables::dav1d_block_dimensions;
use crate::src::tables::dav1d_filter_2d;
use crate::src::tables::dav1d_filter_mode_to_y_mode;
use crate::src::tables::dav1d_lo_ctx_offsets;

use crate::src::tables::dav1d_tx_type_class;
use crate::src::tables::dav1d_tx_types_per_set;
use crate::src::tables::dav1d_txfm_dimensions;
Expand Down Expand Up @@ -1013,7 +1012,7 @@ unsafe fn decode_coefs(
&dav1d_lo_ctx_offsets
[nonsquare_tx.wrapping_add(tx as libc::c_uint & nonsquare_tx) as usize],
);
scan = dav1d_scans[tx as usize];
scan = dav1d_scans[tx as usize].as_ptr();
let stride: ptrdiff_t = (4 * sh) as ptrdiff_t;
let shift: libc::c_uint = (if ((*t_dim).lh as libc::c_int) < 4 {
(*t_dim).lh as libc::c_int + 2
Expand Down
5 changes: 2 additions & 3 deletions src/recon_tmpl_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ extern "C" {
);
fn dav1d_copy_lpf_8bpc(f: *mut Dav1dFrameContext, src: *const *mut pixel, sby: libc::c_int);
fn dav1d_lr_sbrow_8bpc(f: *mut Dav1dFrameContext, dst: *const *mut pixel, sby: libc::c_int);
static dav1d_scans: [*const uint16_t; 19];
static mut dav1d_wedge_masks: [[[[*const uint8_t; 16]; 2]; 3]; 22];
static mut dav1d_ii_masks: [[[*const uint8_t; 4]; 3]; 22];
}
Expand All @@ -62,11 +61,11 @@ use crate::src::msac::dav1d_msac_decode_hi_tok;
use crate::src::msac::dav1d_msac_decode_symbol_adapt16;
use crate::src::msac::dav1d_msac_decode_symbol_adapt4;
use crate::src::msac::dav1d_msac_decode_symbol_adapt8;
use crate::src::scan::dav1d_scans;
use crate::src::tables::dav1d_block_dimensions;
use crate::src::tables::dav1d_filter_2d;
use crate::src::tables::dav1d_filter_mode_to_y_mode;
use crate::src::tables::dav1d_lo_ctx_offsets;

use crate::src::tables::dav1d_tx_type_class;
use crate::src::tables::dav1d_tx_types_per_set;
use crate::src::tables::dav1d_txfm_dimensions;
Expand Down Expand Up @@ -986,7 +985,7 @@ unsafe fn decode_coefs(
&dav1d_lo_ctx_offsets
[nonsquare_tx.wrapping_add(tx as libc::c_uint & nonsquare_tx) as usize],
);
scan = dav1d_scans[tx as usize];
scan = dav1d_scans[tx as usize].as_ptr();
let stride: ptrdiff_t = (4 * sh) as ptrdiff_t;
let shift: libc::c_uint = (if ((*t_dim).lh as libc::c_int) < 4 {
(*t_dim).lh as libc::c_int + 2
Expand Down
42 changes: 21 additions & 21 deletions src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,25 @@ static scan_32x32: Align32<[u16; 1024]> = Align32([
986, 1017, 1018, 987, 956, 925, 894, 863, 895, 926, 957, 988, 1019, 1020, 989, 958, 927, 959,
990, 1021, 1022, 991, 1023,
]);
#[no_mangle]
pub static mut dav1d_scans: [*const u16; 19] = [
scan_4x4.0.as_ptr(),
scan_8x8.0.as_ptr(),
scan_16x16.0.as_ptr(),
scan_32x32.0.as_ptr(),
scan_32x32.0.as_ptr(),
scan_4x8.0.as_ptr(),
scan_8x4.0.as_ptr(),
scan_8x16.0.as_ptr(),
scan_16x8.0.as_ptr(),
scan_16x32.0.as_ptr(),
scan_32x16.0.as_ptr(),
scan_32x32.0.as_ptr(),
scan_32x32.0.as_ptr(),
scan_4x16.0.as_ptr(),
scan_16x4.0.as_ptr(),
scan_8x32.0.as_ptr(),
scan_32x8.0.as_ptr(),
scan_16x32.0.as_ptr(),
scan_32x16.0.as_ptr(),

pub static dav1d_scans: [&'static [u16]; 19] = [
&scan_4x4.0,
&scan_8x8.0,
&scan_16x16.0,
&scan_32x32.0,
&scan_32x32.0,
&scan_4x8.0,
&scan_8x4.0,
&scan_8x16.0,
&scan_16x8.0,
&scan_16x32.0,
&scan_32x16.0,
&scan_32x32.0,
&scan_32x32.0,
&scan_4x16.0,
&scan_16x4.0,
&scan_8x32.0,
&scan_32x8.0,
&scan_16x32.0,
&scan_32x16.0,
];

0 comments on commit dc22537

Please sign in to comment.