Skip to content

Commit

Permalink
fn errno_location, static std{out,err}: Remove from rav1d lib a…
Browse files Browse the repository at this point in the history
…nd into the binaries.

The binaries aren't important, so it's useful to fully remove these from the important `rav1d` lib.
  • Loading branch information
kkysen committed Dec 10, 2023
1 parent 4b9cc3a commit 0232c47
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 50 deletions.
29 changes: 0 additions & 29 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,33 +89,4 @@ pub mod src {
mod wedge;
} // mod src

use std::ffi::c_int;

pub use src::error::Dav1dResult;

// NOTE: temporary code to support Linux and macOS, should be removed eventually
cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] {
extern "C" {
pub static mut stdout: *mut libc::FILE;

pub static mut stderr: *mut libc::FILE;
}

pub unsafe fn errno_location() -> *mut c_int {
libc::__errno_location()
}
} else if #[cfg(target_os = "macos")] {
extern "C" {
#[link_name = "__stdoutp"]
pub static mut stdout: *mut libc::FILE;

#[link_name = "__stderrp"]
pub static mut stderr: *mut libc::FILE;
}

pub unsafe fn errno_location() -> *mut c_int {
libc::__error()
}
}
}
7 changes: 6 additions & 1 deletion tests/seek_stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#![feature(c_variadic)]
#![allow(clippy::all)]

#[path = "../tools/compat"]
mod compat {
pub mod errno;
pub mod stdio;
} // mod compat
#[path = "../tools/input"]
mod input {
mod annexb;
Expand All @@ -22,6 +27,7 @@ mod output {
#[path = "../tools/dav1d_cli_parse.rs"]
mod dav1d_cli_parse;

use crate::compat::stdio::stderr;
use crate::dav1d_cli_parse::parse;
use crate::dav1d_cli_parse::CLISettings;
use crate::dav1d_cli_parse::REALTIME_DISABLE;
Expand Down Expand Up @@ -63,7 +69,6 @@ use rav1d::src::lib::dav1d_parse_sequence_header;
use rav1d::src::lib::dav1d_picture_unref;
use rav1d::src::lib::dav1d_send_data;
use rav1d::src::lib::dav1d_version;
use rav1d::stderr;
use std::ffi::c_char;
use std::ffi::c_double;
use std::ffi::c_float;
Expand Down
14 changes: 14 additions & 0 deletions tools/compat/errno.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::ffi::c_int;

// NOTE: temporary code to support Linux and macOS, should be removed eventually
cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] {
pub unsafe fn errno_location() -> *mut c_int {
libc::__errno_location()
}
} else if #[cfg(target_os = "macos")] {
pub unsafe fn errno_location() -> *mut c_int {
libc::__error()
}
}
}
18 changes: 18 additions & 0 deletions tools/compat/stdio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// NOTE: temporary code to support Linux and macOS, should be removed eventually
cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] {
extern "C" {
pub static mut stdout: *mut libc::FILE;

pub static mut stderr: *mut libc::FILE;
}
} else if #[cfg(target_os = "macos")] {
extern "C" {
#[link_name = "__stdoutp"]
pub static mut stdout: *mut libc::FILE;

#[link_name = "__stderrp"]
pub static mut stderr: *mut libc::FILE;
}
}
}
6 changes: 5 additions & 1 deletion tools/dav1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#![feature(c_variadic)]
#![allow(clippy::all)]

mod compat {
pub mod errno;
pub mod stdio;
} // mod compat
mod input {
mod annexb;
pub mod input;
Expand All @@ -19,6 +23,7 @@ mod output {
} // mod output
mod dav1d_cli_parse;

use crate::compat::stdio::stderr;
use crate::dav1d_cli_parse::parse;
use crate::dav1d_cli_parse::CLISettings;
use crate::dav1d_cli_parse::REALTIME_CUSTOM;
Expand Down Expand Up @@ -82,7 +87,6 @@ use rav1d::src::lib::dav1d_open;
use rav1d::src::lib::dav1d_parse_sequence_header;
use rav1d::src::lib::dav1d_send_data;
use rav1d::src::lib::dav1d_version;
use rav1d::stderr;
use rav1d::Dav1dResult;
use std::ffi::c_char;
use std::ffi::c_double;
Expand Down
2 changes: 1 addition & 1 deletion tools/dav1d_cli_parse.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::compat::stdio::stderr;
use libc::fprintf;
use libc::getopt_long;
use libc::memset;
Expand All @@ -24,7 +25,6 @@ use rav1d::include::dav1d::dav1d::DAV1D_INLOOPFILTER_RESTORATION;
use rav1d::src::cpu::dav1d_set_cpu_flags_mask;
use rav1d::src::lib::dav1d_default_settings;
use rav1d::src::lib::dav1d_version;
use rav1d::stderr;
use std::ffi::c_char;
use std::ffi::c_double;
use std::ffi::c_int;
Expand Down
4 changes: 2 additions & 2 deletions tools/input/annexb.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::compat::errno::errno_location;
use crate::compat::stdio::stderr;
use libc::fclose;
use libc::fopen;
use libc::fprintf;
use libc::fread;
use libc::fseeko;
use libc::strerror;
use rav1d::errno_location;
use rav1d::include::dav1d::data::Dav1dData;
use rav1d::include::dav1d::headers::Dav1dObuType;
use rav1d::include::dav1d::headers::DAV1D_OBU_FRAME;
Expand All @@ -14,7 +15,6 @@ use rav1d::include::dav1d::headers::DAV1D_OBU_TD;
use rav1d::include::dav1d::headers::DAV1D_OBU_TILE_GRP;
use rav1d::src::lib::dav1d_data_create;
use rav1d::src::lib::dav1d_data_unref;
use rav1d::stderr;
use std::cmp;
use std::ffi::c_char;
use std::ffi::c_int;
Expand Down
4 changes: 2 additions & 2 deletions tools/input/input.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::compat::errno::errno_location;
use crate::compat::stdio::stderr;
use libc::calloc;
use libc::fclose;
use libc::fopen;
Expand All @@ -9,9 +11,7 @@ use libc::strcmp;
use libc::strerror;
use libc::ENOMEM;
use libc::ENOPROTOOPT;
use rav1d::errno_location;
use rav1d::include::dav1d::data::Dav1dData;
use rav1d::stderr;
use std::cmp;
use std::ffi::c_char;
use std::ffi::c_int;
Expand Down
4 changes: 2 additions & 2 deletions tools/input/ivf.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::compat::errno::errno_location;
use crate::compat::stdio::stderr;
use libc::fclose;
use libc::fopen;
use libc::fprintf;
Expand All @@ -7,11 +9,9 @@ use libc::ftello;
use libc::ptrdiff_t;
use libc::strerror;
use libc::ENOMEM;
use rav1d::errno_location;
use rav1d::include::dav1d::data::Dav1dData;
use rav1d::src::lib::dav1d_data_create;
use rav1d::src::lib::dav1d_data_unref;
use rav1d::stderr;
use std::ffi::c_char;
use std::ffi::c_double;
use std::ffi::c_int;
Expand Down
4 changes: 2 additions & 2 deletions tools/input/section5.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::compat::errno::errno_location;
use crate::compat::stdio::stderr;
use libc::fclose;
use libc::feof;
use libc::fopen;
use libc::fprintf;
use libc::fread;
use libc::fseeko;
use libc::strerror;
use rav1d::errno_location;
use rav1d::include::dav1d::data::Dav1dData;
use rav1d::include::dav1d::headers::Dav1dObuType;
use rav1d::include::dav1d::headers::DAV1D_OBU_FRAME;
Expand All @@ -15,7 +16,6 @@ use rav1d::include::dav1d::headers::DAV1D_OBU_TD;
use rav1d::include::dav1d::headers::DAV1D_OBU_TILE_GRP;
use rav1d::src::lib::dav1d_data_create;
use rav1d::src::lib::dav1d_data_unref;
use rav1d::stderr;
use std::ffi::c_char;
use std::ffi::c_int;
use std::ffi::c_uint;
Expand Down
6 changes: 3 additions & 3 deletions tools/output/md5.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use crate::compat::errno::errno_location;
use crate::compat::stdio::stderr;
use crate::compat::stdio::stdout;
use libc::fclose;
use libc::fopen;
use libc::fprintf;
Expand All @@ -6,15 +9,12 @@ use libc::strcmp;
use libc::strerror;
use libc::strlen;
use libc::strtoul;
use rav1d::errno_location;
use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I400;
use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I420;
use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I444;
use rav1d::include::dav1d::picture::Dav1dPicture;
use rav1d::include::dav1d::picture::Dav1dPictureParameters;
use rav1d::src::lib::dav1d_picture_unref;
use rav1d::stderr;
use rav1d::stdout;
use std::cmp;
use std::ffi::c_char;
use std::ffi::c_int;
Expand Down
2 changes: 1 addition & 1 deletion tools/output/output.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::compat::stdio::stderr;
use libc::fprintf;
use libc::free;
use libc::malloc;
Expand All @@ -11,7 +12,6 @@ use libc::ENOMEM;
use libc::ENOPROTOOPT;
use rav1d::include::dav1d::picture::Dav1dPicture;
use rav1d::include::dav1d::picture::Dav1dPictureParameters;
use rav1d::stderr;
use std::cmp;
use std::ffi::c_char;
use std::ffi::c_int;
Expand Down
6 changes: 3 additions & 3 deletions tools/output/y4m2.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use crate::compat::errno::errno_location;
use crate::compat::stdio::stderr;
use crate::compat::stdio::stdout;
use libc::fclose;
use libc::fopen;
use libc::fprintf;
use libc::fwrite;
use libc::strcmp;
use libc::strerror;
use rav1d::errno_location;
use rav1d::include::dav1d::headers::DAV1D_CHR_UNKNOWN;
use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I400;
use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I420;
use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I444;
use rav1d::include::dav1d::picture::Dav1dPicture;
use rav1d::include::dav1d::picture::Dav1dPictureParameters;
use rav1d::src::lib::dav1d_picture_unref;
use rav1d::stderr;
use rav1d::stdout;
use std::ffi::c_char;
use std::ffi::c_int;
use std::ffi::c_uint;
Expand Down
6 changes: 3 additions & 3 deletions tools/output/yuv.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use crate::compat::errno::errno_location;
use crate::compat::stdio::stderr;
use crate::compat::stdio::stdout;
use libc::fclose;
use libc::fopen;
use libc::fprintf;
use libc::fwrite;
use libc::strcmp;
use libc::strerror;
use rav1d::errno_location;
use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I400;
use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I420;
use rav1d::include::dav1d::headers::DAV1D_PIXEL_LAYOUT_I444;
use rav1d::include::dav1d::picture::Dav1dPicture;
use rav1d::include::dav1d::picture::Dav1dPictureParameters;
use rav1d::src::lib::dav1d_picture_unref;
use rav1d::stderr;
use rav1d::stdout;
use std::ffi::c_char;
use std::ffi::c_int;
use std::ffi::c_uint;
Expand Down

0 comments on commit 0232c47

Please sign in to comment.