diff --git a/compat/msvcrt/snprintf.c b/compat/msvcrt/snprintf.c new file mode 100644 index 0000000000..0800192338 --- /dev/null +++ b/compat/msvcrt/snprintf.c @@ -0,0 +1,63 @@ +/* + * C99-compatible snprintf() and vsnprintf() implementations + * Copyright (c) 2012 Ronald S. Bultje + * + * 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 +#include +#include +#include + +#include "libavutil/error.h" + +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; + + if (n == 0) + return 0; + 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 http://msdn.microsoft.com/en-us/library/1kt27hek(v=vs.80).aspx */ + memset(s, 0, n); + ret = _vsnprintf(s, n - 1, fmt, ap); + if (ret == -1) + ret = n; + + return ret; +} diff --git a/compat/strtod.c b/compat/strtod.c new file mode 100644 index 0000000000..d0f9b3d41b --- /dev/null +++ b/compat/strtod.c @@ -0,0 +1,94 @@ +/* + * C99-compatible strtod() implementation + * Copyright (c) 2012 Ronald S. Bultje + * + * 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 +#include +#include + +#include "libavutil/avstring.h" +#include "libavutil/mathematics.h" + +static char *check_nan_suffix(char *s) +{ + char *start = s; + + if (*s++ != '(') + return start; + + while ((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') || + (*s >= '0' && *s <= '9') || *s == '_') + s++; + + return *s == ')' ? s + 1 : start; +} + +#undef strtod +double strtod(const char *, char **); + +double avpriv_strtod(const char *nptr, char **endptr) +{ + char *end; + double res; + + /* Skip leading spaces */ + while (isspace(*nptr)) + nptr++; + + if (!av_strncasecmp(nptr, "infinity", 8)) { + end = nptr + 8; + res = INFINITY; + } else if (!av_strncasecmp(nptr, "inf", 3)) { + end = nptr + 3; + res = INFINITY; + } else if (!av_strncasecmp(nptr, "+infinity", 9)) { + end = nptr + 9; + res = INFINITY; + } else if (!av_strncasecmp(nptr, "+inf", 4)) { + end = nptr + 4; + res = INFINITY; + } else if (!av_strncasecmp(nptr, "-infinity", 9)) { + end = nptr + 9; + res = -INFINITY; + } else if (!av_strncasecmp(nptr, "-inf", 4)) { + end = nptr + 4; + res = -INFINITY; + } else if (!av_strncasecmp(nptr, "nan", 3)) { + end = check_nan_suffix(nptr + 3); + res = NAN; + } else if (!av_strncasecmp(nptr, "+nan", 4) || + !av_strncasecmp(nptr, "-nan", 4)) { + end = check_nan_suffix(nptr + 4); + res = NAN; + } else if (!av_strncasecmp(nptr, "0x", 2) || + !av_strncasecmp(nptr, "-0x", 3) || + !av_strncasecmp(nptr, "+0x", 3)) { + /* FIXME this doesn't handle exponents, non-integers (float/double) + * and numbers too large for long long */ + res = strtoll(nptr, &end, 16); + } else { + res = strtod(nptr, &end); + } + + if (endptr) + *endptr = end; + + return res; +} diff --git a/configure b/configure index f0b0388ebb..a92b367665 100755 --- a/configure +++ b/configure @@ -1330,6 +1330,7 @@ HAVE_LIST=" mkstemp mm_empty mmap + msvcrt nanosleep PeekNamedPipe perl @@ -2369,6 +2370,26 @@ EOF die "Sanity test failed." fi +msvc_flags(){ + for flag; do + case $flag in + -fomit-frame-pointer) echo -Oy ;; + -g) echo -Z7 ;; + -Wall) echo -W4 -wd4244 -wd4127 -wd4018 -wd4389 \ + -wd4146 -wd4057 -wd4204 -wd4706 -wd4305 \ + -wd4152 -wd4324 -we4013 -wd4100 -wd4214 \ + -wd4996 ;; + -std=c99) ;; + -fno-math-errno) ;; + -fno-common) ;; + -fno-signed-zeros) ;; + -lz) echo zlib.lib ;; + -l*) echo ${flag#-l}.lib ;; + *) echo $flag ;; + esac + done +} + pgi_flags(){ for flag; do case $flag in @@ -2555,6 +2576,29 @@ probe_cc(){ _cflags_size="-O2 -Munroll=c:1 $opt_common" _cflags_noopt="-O1" _flags_filter=pgi_flags + elif $_cc 2>&1 | grep -q Microsoft; then + _type=msvc + _ident=$($cc 2>&1 | head -n1) + _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | awk '\''/including/ { sub(/^.*file: */, ""); gsub(/\\/, "/"); if (!match($$0, / /)) print "$@:", $$0 }'\'' > $(@:.o=.d)' + _DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -showIncludes -Zs' + _cflags_speed="-O2" + _cflags_size="-O1" + # Nonstandard output options, to avoid msys path conversion issues, relies on wrapper to remap it + if $_cc 2>&1 | grep -q Linker; then + _ld_o='-out $@' + else + _ld_o='-Fe$@' + fi + _cc_o='-Fo $@' + _flags_filter=msvc_flags + _ld_lib='lib%.a' + _ld_path='-libpath:' + _flags='-nologo' + _cflags='-D_USE_MATH_DEFINES -Dinline=__inline -FIstdlib.h -Dstrtoll=_strtoi64' + if [ $pfx = hostcc ]; then + _cflags="$cflags -Dsnprintf=_snprintf" + fi + disable aligned_stack fi eval ${pfx}_type=\$_type @@ -3117,6 +3161,12 @@ elif check_header _mingw.h; then die "ERROR: MinGW runtime version must be >= 3.15." elif check_cpp_condition newlib.h "defined _NEWLIB_VERSION"; then libc_type=newlib +elif check_func_headers stdlib.h _get_doserrno; then + libc_type=msvcrt + add_cflags -Dstrtod=avpriv_strtod + add_cflags -Dsnprintf=avpriv_snprintf \ + -D_snprintf=avpriv_snprintf \ + -Dvsnprintf=avpriv_vsnprintf elif check_cpp_condition stddef.h "defined __KLIBC__"; then libc_type=klibc fi diff --git a/libavcodec/x86/dsputil_mmx.c b/libavcodec/x86/dsputil_mmx.c index d293e19b59..93f09fb8b6 100644 --- a/libavcodec/x86/dsputil_mmx.c +++ b/libavcodec/x86/dsputil_mmx.c @@ -3189,13 +3189,13 @@ void ff_dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx) if (mm_flags & AV_CPU_FLAG_MMXEXT) dsputil_init_mmx2(c, avctx, mm_flags); - if (mm_flags & AV_CPU_FLAG_3DNOW && HAVE_AMD3DNOW) + if (mm_flags & AV_CPU_FLAG_3DNOW) dsputil_init_3dnow(c, avctx, mm_flags); - if (mm_flags & AV_CPU_FLAG_3DNOWEXT && HAVE_AMD3DNOWEXT) + if (mm_flags & AV_CPU_FLAG_3DNOWEXT) dsputil_init_3dnowext(c, avctx, mm_flags); - if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) + if (mm_flags & AV_CPU_FLAG_SSE) dsputil_init_sse(c, avctx, mm_flags); if (mm_flags & AV_CPU_FLAG_SSE2) @@ -3204,7 +3204,7 @@ void ff_dsputil_init_mmx(DSPContext *c, AVCodecContext *avctx) if (mm_flags & AV_CPU_FLAG_SSSE3) dsputil_init_ssse3(c, avctx, mm_flags); - if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) + if (mm_flags & AV_CPU_FLAG_SSE4) dsputil_init_sse4(c, avctx, mm_flags); if (mm_flags & AV_CPU_FLAG_AVX) diff --git a/libavcodec/x86/vp56_arith.h b/libavcodec/x86/vp56_arith.h index ddbf38b1a9..e71dbf8ed0 100644 --- a/libavcodec/x86/vp56_arith.h +++ b/libavcodec/x86/vp56_arith.h @@ -24,7 +24,7 @@ #ifndef AVCODEC_X86_VP56_ARITH_H #define AVCODEC_X86_VP56_ARITH_H -#if HAVE_FAST_CMOV +#if HAVE_INLINE_ASM && HAVE_FAST_CMOV #define vp56_rac_get_prob vp56_rac_get_prob static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) { diff --git a/libavutil/Makefile b/libavutil/Makefile index ef1f658bb4..75039b1887 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -94,6 +94,9 @@ OBJS = adler32.o \ utils.o \ xtea.o \ +OBJS-$(HAVE_MSVCRT) += ../compat/msvcrt/snprintf.o \ + ../compat/strtod.o + TESTPROGS = adler32 \ aes \ avstring \ diff --git a/libavutil/opt.h b/libavutil/opt.h index 5d7f62c2f8..285d85448a 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -64,7 +64,7 @@ * * static const AVOption options[] = { * { "test_int", "This is a test option of int type.", offsetof(test_struct, int_opt), - * AV_OPT_TYPE_INT, {.i64 = -1 }, INT_MIN, INT_MAX }, + * AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX }, * { "test_str", "This is a test option of string type.", offsetof(test_struct, str_opt), * AV_OPT_TYPE_STRING }, * { "test_bin", "This is a test option of binary type.", offsetof(test_struct, bin_opt), @@ -123,7 +123,7 @@ * } child_struct; * static const AVOption child_opts[] = { * { "test_flags", "This is a test option of flags type.", - * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, INT_MIN, INT_MAX }, + * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX }, * { NULL }, * }; * static const AVClass child_class = { @@ -170,8 +170,8 @@ * above, put the following into the child_opts array: * @code * { "test_flags", "This is a test option of flags type.", - * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, INT_MIN, INT_MAX, "test_unit" }, - * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, {.i64 = 16 }, 0, 0, "test_unit" }, + * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX, "test_unit" }, + * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { .i64 = 16 }, 0, 0, "test_unit" }, * @endcode * * @section avoptions_use Using AVOptions diff --git a/tests/fate.sh b/tests/fate.sh index 0bf10ab853..1f70e798c5 100755 --- a/tests/fate.sh +++ b/tests/fate.sh @@ -50,6 +50,7 @@ configure()( ${cpu:+--cpu="$cpu"} \ ${cross_prefix:+--cross-prefix="$cross_prefix"} \ ${cc:+--cc="$cc"} \ + ${ld:+--ld="$ld"} \ ${target_os:+--target-os="$target_os"} \ ${sysroot:+--sysroot="$sysroot"} \ ${target_exec:+--target-exec="$target_exec"} \