Skip to content

Commit

Permalink
#[derive(Copy, Clone)]: Remove except where needed (#417)
Browse files Browse the repository at this point in the history
`Copy` is needed for `union` fields and array repeat initializers.

`Clone` is needed for copying assignments, which are now `.clone()`d for
explicitness.

This is needed to replace fields with non-`Copy` and non-`Clone` types,
such as `AtomicI32`, `Vec`, etc.
  • Loading branch information
kkysen authored Aug 30, 2023
2 parents 584b1c7 + f2fb255 commit 1f7c183
Show file tree
Hide file tree
Showing 63 changed files with 86 additions and 294 deletions.
5 changes: 3 additions & 2 deletions include/dav1d/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ use crate::include::stdint::int64_t;
use crate::include::stdint::uint8_t;
use crate::src::r#ref::Dav1dRef;

#[derive(Copy, Clone)]
#[derive(Clone)]
#[repr(C)]
pub struct Dav1dUserData {
pub data: *const uint8_t,
pub r#ref: *mut Dav1dRef,
}
#[derive(Copy, Clone)]

#[derive(Clone)]
#[repr(C)]
pub struct Dav1dDataProps {
pub timestamp: int64_t,
Expand Down
2 changes: 1 addition & 1 deletion include/dav1d/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::include::stddef::size_t;
use crate::include::stdint::uint8_t;
use crate::src::r#ref::Dav1dRef;

#[derive(Copy, Clone)]
#[derive(Clone)]
#[repr(C)]
pub struct Dav1dData {
pub data: *const uint8_t,
Expand Down
2 changes: 1 addition & 1 deletion include/dav1d/dav1d.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Copy, Clone)]
#[derive(Clone)]
#[repr(C)]
pub struct Dav1dLogger {
pub cookie: *mut libc::c_void,
Expand Down
38 changes: 14 additions & 24 deletions include/dav1d/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub const DAV1D_WM_TYPE_ROT_ZOOM: Dav1dWarpedMotionType = 2;
pub const DAV1D_WM_TYPE_TRANSLATION: Dav1dWarpedMotionType = 1;
pub const DAV1D_WM_TYPE_IDENTITY: Dav1dWarpedMotionType = 0;

#[derive(Copy, Clone)]
#[derive(Clone)]
#[repr(C)]
pub struct Dav1dWarpedMotionParams {
pub type_0: Dav1dWarpedMotionType,
Expand Down Expand Up @@ -135,29 +135,27 @@ pub const DAV1D_CHR_UNKNOWN: Dav1dChromaSamplePosition = 0;
// Constants from Section 3. "Symbols and abbreviated terms"
pub const DAV1D_MAX_SEGMENTS: u8 = 8;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dContentLightLevel {
pub max_content_light_level: libc::c_int,
pub max_frame_average_light_level: libc::c_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dMasteringDisplay {
pub primaries: [[uint16_t; 2]; 3],
pub white_point: [uint16_t; 2],
pub max_luminance: uint32_t,
pub min_luminance: uint32_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dITUTT35 {
pub country_code: uint8_t,
pub country_code_extension_byte: uint8_t,
pub payload_size: size_t,
pub payload: *mut uint8_t,
}
#[derive(Copy, Clone)]

#[derive(Clone, Copy)]
#[repr(C)]
pub struct Dav1dSequenceHeaderOperatingPoint {
pub major_level: libc::c_int,
Expand All @@ -168,14 +166,15 @@ pub struct Dav1dSequenceHeaderOperatingPoint {
pub decoder_model_param_present: libc::c_int,
pub display_model_param_present: libc::c_int,
}
#[derive(Copy, Clone)]

#[derive(Clone, Copy)]
#[repr(C)]
pub struct Dav1dSequenceHeaderOperatingParameterInfo {
pub decoder_buffer_delay: libc::c_int,
pub encoder_buffer_delay: libc::c_int,
pub low_delay_mode: libc::c_int,
}
#[derive(Copy, Clone)]

#[repr(C)]
pub struct Dav1dSequenceHeader {
pub profile: libc::c_int,
Expand Down Expand Up @@ -232,7 +231,8 @@ pub struct Dav1dSequenceHeader {
pub film_grain_present: libc::c_int,
pub operating_parameter_info: [Dav1dSequenceHeaderOperatingParameterInfo; 32],
}
#[derive(Copy, Clone)]

#[derive(Clone)]
#[repr(C)]
pub struct Dav1dSegmentationData {
pub delta_q: libc::c_int,
Expand All @@ -244,20 +244,23 @@ pub struct Dav1dSegmentationData {
pub skip: libc::c_int,
pub globalmv: libc::c_int,
}
#[derive(Copy, Clone)]

#[derive(Clone)]
#[repr(C)]
pub struct Dav1dSegmentationDataSet {
pub d: [Dav1dSegmentationData; 8],
pub preskip: libc::c_int,
pub last_active_segid: libc::c_int,
}
#[derive(Copy, Clone)]

#[derive(Clone)]
#[repr(C)]
pub struct Dav1dLoopfilterModeRefDeltas {
pub mode_delta: [libc::c_int; 2],
pub ref_delta: [libc::c_int; 8],
}
#[derive(Copy, Clone)]

#[derive(Clone)]
#[repr(C)]
pub struct Dav1dFilmGrainData {
pub seed: libc::c_uint,
Expand All @@ -278,25 +281,21 @@ pub struct Dav1dFilmGrainData {
pub overlap_flag: libc::c_int,
pub clip_to_restricted_range: libc::c_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader_film_grain {
pub data: Dav1dFilmGrainData,
pub present: libc::c_int,
pub update: libc::c_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeaderOperatingPoint {
pub buffer_removal_time: libc::c_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader_super_res {
pub width_scale_denominator: libc::c_int,
pub enabled: libc::c_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader_tiling {
pub uniform: libc::c_int,
Expand All @@ -313,7 +312,6 @@ pub struct Dav1dFrameHeader_tiling {
pub row_start_sb: [uint16_t; 65],
pub update: libc::c_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader_quant {
pub yac: libc::c_int,
Expand All @@ -327,7 +325,6 @@ pub struct Dav1dFrameHeader_quant {
pub qm_u: libc::c_int,
pub qm_v: libc::c_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader_segmentation {
pub enabled: libc::c_int,
Expand All @@ -338,26 +335,22 @@ pub struct Dav1dFrameHeader_segmentation {
pub lossless: [libc::c_int; 8],
pub qidx: [libc::c_int; 8],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader_delta_q {
pub present: libc::c_int,
pub res_log2: libc::c_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader_delta_lf {
pub present: libc::c_int,
pub res_log2: libc::c_int,
pub multi: libc::c_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader_delta {
pub q: Dav1dFrameHeader_delta_q,
pub lf: Dav1dFrameHeader_delta_lf,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader_loopfilter {
pub level_y: [libc::c_int; 2],
Expand All @@ -368,21 +361,18 @@ pub struct Dav1dFrameHeader_loopfilter {
pub mode_ref_deltas: Dav1dLoopfilterModeRefDeltas,
pub sharpness: libc::c_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader_cdef {
pub damping: libc::c_int,
pub n_bits: libc::c_int,
pub y_strength: [libc::c_int; 8],
pub uv_strength: [libc::c_int; 8],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader_restoration {
pub type_0: [Dav1dRestorationType; 3],
pub unit_size: [libc::c_int; 2],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader {
pub film_grain: Dav1dFrameHeader_film_grain,
Expand Down
6 changes: 3 additions & 3 deletions include/dav1d/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::include::stddef::ptrdiff_t;
use crate::include::stdint::uintptr_t;
use crate::src::r#ref::Dav1dRef;

#[derive(Copy, Clone)]
#[derive(Clone)]
#[repr(C)]
pub struct Dav1dPictureParameters {
pub w: libc::c_int,
Expand All @@ -18,7 +18,7 @@ pub struct Dav1dPictureParameters {
pub bpc: libc::c_int,
}

#[derive(Copy, Clone)]
#[derive(Clone)]
#[repr(C)]
pub struct Dav1dPicture {
pub seq_hdr: *mut Dav1dSequenceHeader,
Expand All @@ -41,7 +41,7 @@ pub struct Dav1dPicture {
pub allocator_data: *mut libc::c_void,
}

#[derive(Copy, Clone)]
#[derive(Clone)]
#[repr(C)]
pub struct Dav1dPicAllocator {
pub cookie: *mut libc::c_void,
Expand Down
1 change: 0 additions & 1 deletion include/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ cfg_if::cfg_if! {
0
}
} else if #[cfg(target_os = "macos")] {
#[derive(Copy, Clone)]
#[repr(C)]
pub struct _opaque_pthread_once_t {
pub __sig: libc::c_long,
Expand Down
1 change: 0 additions & 1 deletion include/sched.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub type __cpu_mask = libc::c_ulong;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct cpu_set_t {
pub __bits: [__cpu_mask; 16],
Expand Down
1 change: 0 additions & 1 deletion include/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ extern "C" {
pub type _IO_marker;
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct _IO_FILE {
pub _flags: libc::c_int,
Expand Down
2 changes: 1 addition & 1 deletion src/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::ops::{Index, IndexMut};

macro_rules! def_align {
($align:literal, $name:ident) => {
#[derive(Copy, Clone)]
#[derive(Clone, Copy)]
#[repr(C, align($align))]
pub struct $name<T>(pub T);

Expand Down
1 change: 0 additions & 1 deletion src/cdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub type cdef_fn = unsafe extern "C" fn(
) -> ();
pub type cdef_dir_fn =
unsafe extern "C" fn(*const DynPixel, ptrdiff_t, *mut libc::c_uint, libc::c_int) -> libc::c_int;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dCdefDSPContext {
pub dir: cdef_dir_fn,
Expand Down
8 changes: 0 additions & 8 deletions src/cdef_apply_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::include::stdatomic::atomic_int;
use crate::include::dav1d::common::Dav1dDataProps;
use crate::include::dav1d::data::Dav1dData;
use crate::src::r#ref::Dav1dRef;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameContext {
pub seq_hdr_ref: *mut Dav1dRef,
Expand Down Expand Up @@ -102,7 +101,6 @@ use crate::src::refmvs::refmvs_frame;

use crate::src::env::BlockContext;
use crate::src::refmvs::refmvs_temporal_block;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFrameContext_bd_fn {
pub recon_b_intra: recon_b_intra_fn,
Expand All @@ -120,7 +118,6 @@ pub type read_coef_blocks_fn =
Option<unsafe extern "C" fn(*mut Dav1dTaskContext, BlockSize, *const Av1Block) -> ()>;
use crate::src::levels::BlockSize;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dTaskContext {
pub c: *const Dav1dContext,
Expand Down Expand Up @@ -154,7 +151,6 @@ use crate::src::refmvs::refmvs_tile;

use crate::src::internal::Dav1dTileState;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dContext {
pub fc: *mut Dav1dFrameContext,
Expand Down Expand Up @@ -226,7 +222,6 @@ use crate::src::internal::Dav1dContext_intra_edge;
use crate::src::intra_edge::EdgeFlags;
use crate::src::refmvs::Dav1dRefmvsDSPContext;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dDSPContext {
pub fg: Dav1dFilmGrainDSPContext,
Expand All @@ -247,7 +242,6 @@ use crate::src::cdef::CDEF_HAVE_RIGHT;
use crate::src::cdef::CDEF_HAVE_TOP;
use crate::src::itx::Dav1dInvTxfmDSPContext;
use crate::src::loopfilter::Dav1dLoopFilterDSPContext;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dMCDSPContext {
pub mc: [mc_fn; 10],
Expand Down Expand Up @@ -433,7 +427,6 @@ pub type mc_fn = Option<
libc::c_int,
) -> (),
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dIntraPredDSPContext {
pub intra_pred: [angular_ipred_fn; 14],
Expand Down Expand Up @@ -487,7 +480,6 @@ pub type angular_ipred_fn = Option<
libc::c_int,
) -> (),
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dFilmGrainDSPContext {
pub generate_grain_y: generate_grain_y_fn,
Expand Down
Loading

0 comments on commit 1f7c183

Please sign in to comment.