Skip to content

Commit

Permalink
Port C code to Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Bossen committed Mar 23, 2024
1 parent 96cd413 commit a142e2d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,9 @@ unsafe fn gen_picture(c: &mut Rav1dContext) -> Rav1dResult {
}

pub(crate) unsafe fn rav1d_send_data(c: &mut Rav1dContext, in_0: &mut Rav1dData) -> Rav1dResult {
validate_input!((
in_0.data.as_ref().map_or(true, |data| !data.is_empty()),
EINVAL
))?;
if in_0.data.is_some() {
let sz = in_0.data.as_ref().unwrap().len();
validate_input!((sz > 0 && sz <= usize::MAX / 2, EINVAL))?;
c.drain = 0 as c_int;
}
if c.in_0.data.is_some() {
Expand Down Expand Up @@ -1036,6 +1034,7 @@ pub unsafe extern "C" fn dav1d_data_wrap(
|| -> Rav1dResult {
let buf = validate_input!(NonNull::new(buf).ok_or(EINVAL))?;
let ptr = validate_input!(NonNull::new(ptr.cast_mut()).ok_or(EINVAL))?;
validate_input!((sz <= usize::MAX / 2, EINVAL))?;
let data = slice::from_raw_parts(ptr.as_ptr(), sz).into();
let data = Rav1dData::wrap(data, free_callback, user_data)?;
buf.as_ptr().write(data.into());
Expand Down

0 comments on commit a142e2d

Please sign in to comment.