[PR] Remove some obsolete MSVC checks and code (PR #24241)
Kacper Michajłow via ffmpeg-devel <[email protected]>
| Newsgroups | gmane.comp.video.ffmpeg.devel |
|---|---|
| Message-ID | <[email protected]> |
PR #24241 opened by Kacper Michajłow (kasper93) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24241 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24241.patch From e37c1a1e91d52fbcfa6580abae771b4afecfc2ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]> Date: Sat, 22 Aug 2026 17:13:58 +0200 Subject: [PATCH 1/7] configure: drop snprintf fallback for mingw-w64 runtime < 3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mingw-w64 3.0 was released in 2013 and provides C99-correct snprintf. No C11-capable toolchain ships with an older runtime. Signed-off-by: Kacper Michajłow <[email protected]> --- configure | 4 ---- 1 file changed, 4 deletions(-) diff --git a/configure b/configure index 594697b64b..1909d219ef 100755 --- a/configure +++ b/configure @@ -6422,10 +6422,6 @@ probe_libc(){ # MinGW64 is backwards compatible with MinGW32, so check for it first. elif test_${pfx}cpp_condition _mingw.h "defined __MINGW64_VERSION_MAJOR"; then eval ${pfx}libc_type=mingw64 - if test_${pfx}cpp_condition _mingw.h "__MINGW64_VERSION_MAJOR < 3"; then - add_compat msvcrt/snprintf.o - add_allcflags "-include $source_path/compat/msvcrt/snprintf.h" - fi add_${pfx}cflags -U__STRICT_ANSI__ if ! test_${pfx}cpp_condition crtdefs.h "defined(_UCRT)"; then add_${pfx}cppflags -D__USE_MINGW_ANSI_STDIO=1 -- 2.52.0 From 84ac3d2eafc8a66255f4eda701b5a69a0de683b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]> Date: Sat, 22 Aug 2026 17:14:15 +0200 Subject: [PATCH 2/7] configure: drop support for MSVC runtimes older than UCRT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The C11 requirement makes the effective MSVC floor VS2019 16.8, which ships only the UCRT. Pre-UCRT CRTs (_VC_CRT_MAJOR_VERSION < 14) cannot appear in a supported build, and the UCRT provides C99-correct snprintf, strtod, strtoll and strtoull. Signed-off-by: Kacper Michajłow <[email protected]> --- compat/msvcrt/snprintf.c | 71 ---------------------------------------- compat/msvcrt/snprintf.h | 38 --------------------- configure | 14 -------- 3 files changed, 123 deletions(-) delete mode 100644 compat/msvcrt/snprintf.c delete mode 100644 compat/msvcrt/snprintf.h diff --git a/compat/msvcrt/snprintf.c b/compat/msvcrt/snprintf.c deleted file mode 100644 index 43f5c3bb39..0000000000 --- a/compat/msvcrt/snprintf.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * C99-compatible snprintf() and vsnprintf() implementations - * Copyright (c) 2012 Ronald S. Bultje <[email protected]> - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <stdio.h> -#include <stdarg.h> -#include <limits.h> -#include <string.h> - -#include "compat/va_copy.h" -#include "libavutil/error.h" - -#if defined(__MINGW32__) -#define EOVERFLOW EFBIG -#endif - -int avpriv_snprintf(char *s, size_t n, const char *fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = avpriv_vsnprintf(s, n, fmt, ap); - va_end(ap); - - return ret; -} - -int avpriv_vsnprintf(char *s, size_t n, const char *fmt, - va_list ap) -{ - int ret; - va_list ap_copy; - - if (n == 0) - return _vscprintf(fmt, ap); - else if (n > INT_MAX) - return AVERROR(EOVERFLOW); - - /* we use n - 1 here because if the buffer is not big enough, the MS - * runtime libraries don't add a terminating zero at the end. MSDN - * recommends to provide _snprintf/_vsnprintf() a buffer size that - * is one less than the actual buffer, and zero it before calling - * _snprintf/_vsnprintf() to workaround this problem. - * See https://web.archive.org/web/20151214111935/http://msdn.microsoft.com/en-us/library/1kt27hek(v=vs.80).aspx */ - memset(s, 0, n); - va_copy(ap_copy, ap); - ret = _vsnprintf(s, n - 1, fmt, ap_copy); - va_end(ap_copy); - if (ret == -1) - ret = _vscprintf(fmt, ap); - - return ret; -} diff --git a/compat/msvcrt/snprintf.h b/compat/msvcrt/snprintf.h deleted file mode 100644 index cd47953e87..0000000000 --- a/compat/msvcrt/snprintf.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * C99-compatible snprintf() and vsnprintf() implementations - * Copyright (c) 2012 Ronald S. Bultje <[email protected]> - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef COMPAT_MSVCRT_SNPRINTF_H -#define COMPAT_MSVCRT_SNPRINTF_H - -#include <stdarg.h> -#include <stdio.h> - -int avpriv_snprintf(char *s, size_t n, const char *fmt, ...); -int avpriv_vsnprintf(char *s, size_t n, const char *fmt, va_list ap); - -#undef snprintf -#undef _snprintf -#undef vsnprintf -#define snprintf avpriv_snprintf -#define _snprintf avpriv_snprintf -#define vsnprintf avpriv_vsnprintf - -#endif /* COMPAT_MSVCRT_SNPRINTF_H */ diff --git a/configure b/configure index 1909d219ef..dabde4b5f4 100755 --- a/configure +++ b/configure @@ -6446,23 +6446,9 @@ probe_libc(){ add_${pfx}cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 elif test_${pfx}cpp_condition crtversion.h "defined _VC_CRT_MAJOR_VERSION"; then eval ${pfx}libc_type=msvcrt - if test_${pfx}cpp_condition crtversion.h "_VC_CRT_MAJOR_VERSION < 14"; then - if [ "$pfx" = host_ ]; then - add_host_cppflags -Dsnprintf=_snprintf - else - add_compat strtod.o strtod=avpriv_strtod - add_compat msvcrt/snprintf.o snprintf=avpriv_snprintf \ - _snprintf=avpriv_snprintf \ - vsnprintf=avpriv_vsnprintf - fi - fi add_${pfx}cppflags -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS test_${pfx}cpp_condition windows.h "!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0601" && add_${pfx}cppflags -D_WIN32_WINNT=0x0601 - if [ "$pfx" = "" ]; then - check_func strtoll || add_allcflags -Dstrtoll=_strtoi64 - check_func strtoull || add_allcflags -Dstrtoull=_strtoui64 - fi elif test_${pfx}cpp_condition stddef.h "defined __KLIBC__"; then eval ${pfx}libc_type=klibc elif test_${pfx}cpp_condition sys/cdefs.h "defined __BIONIC__"; then -- 2.52.0 From 0780cdae8093e8c51511868d86c64c21cd273257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]> Date: Sat, 22 Aug 2026 17:14:32 +0200 Subject: [PATCH 3/7] compat: remove va_copy.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit va_copy is mandated by C99. MSVC has provided it since VS2013 and no GCC old enough to lack it can pass the C11 configure check, so both fallback branches were unreachable. Signed-off-by: Kacper Michajłow <[email protected]> --- compat/va_copy.h | 34 ---------------------------------- fftools/cmdutils.c | 1 - libavutil/bprint.c | 1 - 3 files changed, 36 deletions(-) delete mode 100644 compat/va_copy.h diff --git a/compat/va_copy.h b/compat/va_copy.h deleted file mode 100644 index a40bbe6637..0000000000 --- a/compat/va_copy.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * MSVC Compatible va_copy macro - * Copyright (c) 2012 Derek Buitenhuis - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef COMPAT_VA_COPY_H -#define COMPAT_VA_COPY_H - -#include <stdarg.h> - -#if !defined(va_copy) && defined(_MSC_VER) -#define va_copy(dst, src) ((dst) = (src)) -#endif -#if !defined(va_copy) && defined(__GNUC__) && __GNUC__ < 3 -#define va_copy(dst, src) __va_copy(dst, src) -#endif - -#endif /* COMPAT_VA_COPY_H */ diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 9fdd680448..95e8a971cd 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -30,7 +30,6 @@ references to libraries that are not being built. */ #include "config.h" -#include "compat/va_copy.h" #include "libavformat/avformat.h" #include "libswscale/swscale.h" #include "libswresample/swresample.h" diff --git a/libavutil/bprint.c b/libavutil/bprint.c index 266da11304..3c6d14c2e9 100644 --- a/libavutil/bprint.c +++ b/libavutil/bprint.c @@ -25,7 +25,6 @@ #include <time.h> #include "avstring.h" #include "bprint.h" -#include "compat/va_copy.h" #include "error.h" #include "macros.h" #include "mem.h" -- 2.52.0 From cc8f39c041cf7f01334c0b9d1b8a4f57bb93ea4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]> Date: Sat, 22 Aug 2026 17:14:44 +0200 Subject: [PATCH 4/7] configure: remove obsolete MSVC workarounds The C11 requirement puts the MSVC floor at VS2019 16.8, so the VS2015 version checks for the SSA optimizer bug and -utf-8 availability are always true, and cl in C11 mode accepts the inline keyword. --- configure | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/configure b/configure index dabde4b5f4..3186c9698b 100755 --- a/configure +++ b/configure @@ -8159,27 +8159,10 @@ elif enabled_any msvc icl; then disable ebx_available fi fi - # msvcrt10 x64 incorrectly enables log2, only msvcrt12 (MSVC 2013) onwards actually has log2. - check_cpp_condition log2 crtversion.h "_VC_CRT_MAJOR_VERSION >= 12" - # the new SSA optimizer in VS2015 U3 is mis-optimizing some parts of the code - # Issue has been fixed in MSVC v19.00.24218. - test_cpp_condition windows.h "_MSC_FULL_VER >= 190024218" || - check_cflags -d2SSAOptimizer- - # enable utf-8 source processing on VS2015 U2 and newer - test_cpp_condition windows.h "_MSC_FULL_VER >= 190023918" && - add_cflags -utf-8 + # enable utf-8 source processing + add_cflags -utf-8 fi -for pfx in "" host_; do - varname=${pfx%_}cc_type - eval "type=\$$varname" - if [ "$type" = "msvc" ]; then - test_${pfx}cc <<EOF || add_${pfx}cflags -Dinline=__inline -static inline int foo(int a) { return a; } -EOF - fi -done - case $as_type in clang) add_asflags -Qunused-arguments -- 2.52.0 From 3caa5f82ee05efa46c250c55667229089af99c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]> Date: Sat, 22 Aug 2026 17:15:11 +0200 Subject: [PATCH 5/7] avcodec/tableprint: use %zu unconditionally MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The UCRT printf supports %zu, and pre-UCRT MSVC is no longer supported. Signed-off-by: Kacper Michajłow <[email protected]> --- libavcodec/tableprint.h | 16 +++------------- libavcodec/tableprint_vlc.h | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/libavcodec/tableprint.h b/libavcodec/tableprint.h index 6f61c7124b..794e0264ff 100644 --- a/libavcodec/tableprint.h +++ b/libavcodec/tableprint.h @@ -72,21 +72,11 @@ void write_uint32_t_2d_array(const void *, int, int); void write_float_2d_array (const void *, int, int); /** @} */ // end of printfuncs group -/* - * MSVC doesn't have %zu, since it was introduced in C99, - * but has its own %Iu for printing size_t values. - */ -#if defined(_MSC_VER) -#define FMT "Iu" -#else -#define FMT "zu" -#endif - #define WRITE_ARRAY_ALIGNED(prefix, align, type, name) \ do { \ const size_t array_size = FF_ARRAY_ELEMS(name); \ printf(prefix" DECLARE_ALIGNED("#align", " \ - #type", "#name")[%"FMT"] = {\n", \ + #type", "#name")[%zu] = {\n", \ array_size); \ write_##type##_array(name, array_size); \ printf("};\n"); \ @@ -95,7 +85,7 @@ void write_float_2d_array (const void *, int, int); #define WRITE_ARRAY(prefix, type, name) \ do { \ const size_t array_size = FF_ARRAY_ELEMS(name); \ - printf(prefix" "#type" "#name"[%"FMT"] = {\n", \ + printf(prefix" "#type" "#name"[%zu] = {\n", \ array_size); \ write_##type##_array(name, array_size); \ printf("};\n"); \ @@ -105,7 +95,7 @@ void write_float_2d_array (const void *, int, int); do { \ const size_t array_size1 = FF_ARRAY_ELEMS(name); \ const size_t array_size2 = FF_ARRAY_ELEMS(name[0]); \ - printf(prefix" "#type" "#name"[%"FMT"][%"FMT"] = {\n", \ + printf(prefix" "#type" "#name"[%zu][%zu] = {\n", \ array_size1, array_size2 ); \ write_##type##_2d_array(name, array_size1, array_size2); \ printf("};\n"); \ diff --git a/libavcodec/tableprint_vlc.h b/libavcodec/tableprint_vlc.h index e7c6764573..d8b3d27ef7 100644 --- a/libavcodec/tableprint_vlc.h +++ b/libavcodec/tableprint_vlc.h @@ -67,7 +67,7 @@ static void write_vlc_type(const VLC *vlc, const VLCElem *base_table, const char do { \ int i; \ const size_t array_size = FF_ARRAY_ELEMS(name); \ - printf(prefix" VLC "#name"[%"FMT"] = {{\n", \ + printf(prefix" VLC "#name"[%zu] = {{\n", \ array_size); \ for (i = 0; i < array_size; i++) { \ write_vlc_type(name + i, \ -- 2.52.0 From a3d6859e1cc802fc5b96611fa022716730a3d561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]> Date: Sat, 22 Aug 2026 17:15:21 +0200 Subject: [PATCH 6/7] avutil/x86/intmath: remove always-true MSVC version check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _MSC_VER >= 1700 is VS2012, far below the supported floor. Signed-off-by: Kacper Michajłow <[email protected]> --- libavutil/x86/intmath.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavutil/x86/intmath.h b/libavutil/x86/intmath.h index d8d1f19b24..ca708ec2be 100644 --- a/libavutil/x86/intmath.h +++ b/libavutil/x86/intmath.h @@ -47,7 +47,7 @@ static av_always_inline av_const int ff_log2_x86(unsigned int v) # endif # define ff_log2_16bit av_log2 -#if defined(__INTEL_COMPILER) || (defined(_MSC_VER) && (_MSC_VER >= 1700) && \ +#if defined(__INTEL_COMPILER) || (defined(_MSC_VER) && \ (defined(__BMI__) || !defined(__clang__))) # define ff_ctz(v) _tzcnt_u32(v) -- 2.52.0 From 6ff79a6d6576cda9b82352a0ec75d34f0771278c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]> Date: Sat, 22 Aug 2026 17:24:36 +0200 Subject: [PATCH 7/7] configure: remove MSVC version check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The C11 support check rejects anything older than VS2019 16.8, where /std:c11 was introduced. A separate version probe is redundant. Signed-off-by: Kacper Michajłow <[email protected]> --- configure | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/configure b/configure index 3186c9698b..67dd308563 100755 --- a/configure +++ b/configure @@ -4959,13 +4959,8 @@ case "$toolchain" in esac ;; msvc) - cl_major_ver=$(cl.exe 2>&1 | sed -n 's/.*Version \([[:digit:]]\{1,\}\)\..*/\1/p') - if [ -z "$cl_major_ver" ] || [ $cl_major_ver -ge 18 ]; then - cc_default="cl.exe" - cxx_default="cl.exe" - else - die "Unsupported MSVC version (2013 or newer required)" - fi + cc_default="cl.exe" + cxx_default="cl.exe" ld_default="$source_path/compat/windows/mslink" windres_default="$source_path/compat/windows/mswindres" nm_default="dumpbin.exe -symbols" -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]