From 832a715d795a3b928e9fe6e4dcb2a62a2381bf78 Mon Sep 17 00:00:00 2001 From: Alaric Senat Date: Tue, 21 Jul 2026 22:18:39 +0200 Subject: [PATCH] libvlc-sys: declare vsnprintf outside the generated block vsnprintf is a C-runtime symbol, not a libvlc export, so it has no business sitting in the block of bindings generated from libvlc's headers. It only ended up there because the Windows link workaround needed a declaration. Drop it from the allowlist and declare it by hand in lib.rs. --- libvlc-sys/bindings.rs | 6 ------ libvlc-sys/src/lib.rs | 11 +++++++++++ src/core.rs | 2 +- xtask/src/main.rs | 3 --- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libvlc-sys/bindings.rs b/libvlc-sys/bindings.rs index 41c1ebe..9cd88a7 100644 --- a/libvlc-sys/bindings.rs +++ b/libvlc-sys/bindings.rs @@ -1611,12 +1611,6 @@ const _: () = { [::core::mem::offset_of!(libvlc_log_message_t, psz_message) - 32usize]; }; unsafe extern "C" { - pub fn vsnprintf( - __s: *mut libc::c_char, - __maxlen: libc::c_ulong, - __format: *const libc::c_char, - __arg: VaList, - ) -> libc::c_int; pub fn libvlc_errmsg() -> *const libc::c_char; pub fn libvlc_clearerr(); pub fn libvlc_vprinterr( diff --git a/libvlc-sys/src/lib.rs b/libvlc-sys/src/lib.rs index e7ec8c3..5605ec0 100644 --- a/libvlc-sys/src/lib.rs +++ b/libvlc-sys/src/lib.rs @@ -8,3 +8,14 @@ pub mod valist; // The bindings are a committed source file, regenerated out of band with // `cargo xtask bindgen`. include!("../bindings.rs"); + +// `libc` does not expose vsnprintf and libvlc advises to use it to handle logs in the log +// callbacks. Expose it for convenience. +unsafe extern "C" { + pub fn vsnprintf( + s: *mut libc::c_char, + n: usize, + fmt: *const libc::c_char, + ap: VaList, + ) -> libc::c_int; +} diff --git a/src/core.rs b/src/core.rs index dd4ed94..a3b426e 100644 --- a/src/core.rs +++ b/src/core.rs @@ -161,7 +161,7 @@ unsafe extern "C" fn logging_cb( let f: &Box) + Send + 'static> = ::std::mem::transmute(data); let mut buf: [c_char; BUF_SIZE] = [0; BUF_SIZE]; - sys::vsnprintf(buf.as_mut_ptr(), BUF_SIZE.try_into().unwrap(), fmt, args); + sys::vsnprintf(buf.as_mut_ptr(), BUF_SIZE, fmt, args); f((level as u32).into(), Log{ptr: ctx}, from_cstr_ref(buf.as_ptr()).unwrap()); } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 027886b..df9a2da 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -43,9 +43,6 @@ fn generate_bindings() { .ctypes_prefix("libc") // Allowlist every (lib)vlc symbol. .allowlist_item("(lib|LIB)?(vlc|VLC)_.*") - // Required by the Windows `legacy_stdio_definitions` link workaround - // (see libvlc-sys/build.rs). - .allowlist_function("vsnprintf") // libvlc only uses FILE behind a pointer. Map it // to libc's opaque, per-platform FILE rather than emitting glibc's // plain _IO_FILE, whose baked-in layout breaks non-Linux builds.