Skip to content

Don't bind the C library functions that std defines too: memcpy, memm… - #155

Open
lattice0 wants to merge 1 commit into
CCExtractor:masterfrom
lattice0:fix-warnings
Open

lattice0 wants to merge 1 commit into
CCExtractor:masterfrom
lattice0:fix-warnings

Conversation

@lattice0

Copy link
Copy Markdown

Fixes the six warnings that every build of this crate prints with a recent rustc:

warning: suspicious definition of the runtime `memcpy` symbol used by the standard library
         ... and `memmove`, `memset`, `memcmp`, `bcmp`, `strlen`
  = note: expected `unsafe extern "C" fn(*mut c_void, *const c_void, usize) -> *mut c_void`
          found    `unsafe extern "C" fn(*mut c_void, *const c_void, u64) -> *mut c_void`
  = note: `#[warn(suspicious_runtime_symbol_definitions)]` on by default

Why

build.rs runs bindgen on FFmpeg's headers with no allowlist, and FFmpeg's headers include <string.h>. So the bindings declare about 50 C library functions, which aren't FFmpeg's API. Six of them are runtime symbols that Rust's standard library defines too: bindgen declares them with c_ulong for size_t, where std has usize, and rustc flags the mismatch. On LP64 Linux and macOS the two are the same size, but on Windows c_ulong is 32 bits.

What changes

  • build.rs: .blocklist_function("memcpy|memmove|memset|memcmp|bcmp|strlen"), so bindgen no longer declares them. bindgen anchors the pattern: in the regenerated bindings exactly those six go, and memchr, memccpy, strnlen, memmem and mempcpy stay.
  • src/binding.rs, the tracked binding that docs.rs and the use_prebuilt_binding feature copy: the same six extern "C" blocks removed (38 lines, nothing else), which is what the blocklist generates. It couldn't be regenerated here, as that needs FFmpeg 8.1's headers.

Nothing in the crate uses these six. Code that called them through rusty_ffmpeg::ffi would use std::ptr::copy and the like, or libc.

Tested

With RUSTFLAGS="-D warnings", offline, in a container (rustc 1.98.1, bindgen 0.72.1):

Build Before After
DOCS_RS=1 cargo check --features ffmpeg8_1 (the tracked binding) 6 errors clean
cargo check --features ffmpeg8, bindgen on FFmpeg 8.0.3's headers through FFMPEG_PKG_CONFIG_PATH 6 errors on the 0.16 line, same declarations clean

The 0.16 line's numbers come from lattice0-labs/supernova, which uses this crate through rsmpeg and where these warnings showed in every build.

Not tested: Windows, and generating against FFmpeg 8.1's headers.

…ove, memset, memcmp, bcmp, strlen

FFmpeg's headers include <string.h>, and bindgen declared these with c_ulong for size_t where Rust's standard library has usize, which rustc warns about (suspicious_runtime_symbol_definitions, six warnings in every build). They aren't FFmpeg's API. build.rs blocklists them, and the tracked src/binding.rs drops the same six declarations, as the blocklist would generate it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant