CCExtractor / rusty_ffmpeg

FFI bindings for FFmpeg inner libraries.

Home Page:https://crates.io/crates/rusty_ffmpeg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use usize in stead of size_t

RobertLabonte opened this issue · comments

I don't have access to open a PR. I am building rusty_ffmpeg to target wasm32-wasi. Since wasm32 uses a u32 as usize, it fails to build src/avutil/error.rs because it looks for catches x86 has a target that requires a u32 function input. The following changes will remove the need to check for build target and use usize in place of size_t allowing easier support for non-x86/x86_64 targets.

diff --git a/build.rs b/build.rs
index 876684c..8806e4b 100644
--- a/build.rs
+++ b/build.rs
@@ -148,6 +148,7 @@ fn generate_bindings(ffmpeg_include_dir: Option<&Path>, headers: &[PathBuf]) ->
                     .parse_callbacks(Box::new(filter_callback))
                     // Add clang path, for `#include` header finding in bindgen process.
                     .clang_arg(format!("-I{}", ffmpeg_include_dir))
+                    .size_t_is_usize(true)
             } else {
                 bindgen::builder().parse_callbacks(Box::new(filter_callback))
             },
diff --git a/src/avutil/error.rs b/src/avutil/error.rs
index 96049b4..506afb4 100644
--- a/src/avutil/error.rs
+++ b/src/avutil/error.rs
@@ -63,13 +63,9 @@ pub const AV_ERROR_MAX_STRING_SIZE: usize   = 64;
 /// Safety requirements is the same as the  av_strerror()`
 pub unsafe fn av_make_error_string(
     errbuf: *mut libc::c_char,
-    errbuf_size: libc::size_t,
+    errbuf_size: usize,
     errnum: libc::c_int
 ) -> *mut libc::c_char {
-    #[cfg(target_arch="x86")]
-    let errbuf_size = errbuf_size as u32;
-    #[cfg(not(target_arch="x86"))]
-    let errbuf_size = errbuf_size as u64;
     ffi::av_strerror(errnum, errbuf, errbuf_size);
     errbuf
 }