Bug 1277155 - Part 2: Remove snprintf() polyfills in media code imported from libav. r=jya
authorChris Peterson <cpeterson@mozilla.com>
Mon, 27 Jun 2016 20:44:30 -0700
changeset 344010 9e0a6eedc2b6b2c24b67b356b8ab0de57af33abf
parent 344009 3f99486c6b0157f468e0bc76bdc2348daf158541
child 344011 d4203db171009cdd99724d7b83c4f4b9a2438b45
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1277155
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1277155 - Part 2: Remove snprintf() polyfills in media code imported from libav. r=jya
media/ffvpx/changes.patch
media/ffvpx/compat/msvcrt/snprintf.c
media/ffvpx/compat/msvcrt/snprintf.h
media/ffvpx/compat/strtod.c
media/ffvpx/ffvpxcommon.mozbuild
media/ffvpx/libavutil/avutil.symbols
media/ffvpx/libavutil/internal.h
media/ffvpx/libavutil/moz.build
media/libav/libavcommon.mozbuild
--- a/media/ffvpx/changes.patch
+++ b/media/ffvpx/changes.patch
@@ -45,21 +45,8 @@ index 9fb8d0a..97ad3b9 100644
      rgba_color[3] = 255;
  
      if (!av_strcasecmp(color_string2, "random") || !av_strcasecmp(color_string2, "bikeshed")) {
 -        int rgba = av_get_random_seed();
 +        int rgba = 0xffffffff; /* av_get_random_seed(); */
          rgba_color[0] = rgba >> 24;
          rgba_color[1] = rgba >> 16;
          rgba_color[2] = rgba >> 8;
-diff --git a/media/ffvpx/libavutil/internal.h b/media/ffvpx/libavutil/internal.h
-index 047f742..fe504c3 100644
---- a/media/ffvpx/libavutil/internal.h
-+++ b/media/ffvpx/libavutil/internal.h
-@@ -237,7 +237,7 @@ void avpriv_request_sample(void *avc,
- 
- #if HAVE_LIBC_MSVCRT
- #include <crtversion.h>
--#if defined(_VC_CRT_MAJOR_VERSION) && _VC_CRT_MAJOR_VERSION < 14
-+#if defined(_VC_CRT_MAJOR_VERSION) && _VC_CRT_MAJOR_VERSION < 12
- #pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_strtod")
- #pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_snprintf")
- #endif
deleted file mode 100644
--- a/media/ffvpx/compat/msvcrt/snprintf.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * C99-compatible snprintf() and vsnprintf() implementations
- * Copyright (c) 2012 Ronald S. Bultje <rsbultje@gmail.com>
- *
- * 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 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;
-}
deleted file mode 100644
--- a/media/ffvpx/compat/msvcrt/snprintf.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * C99-compatible snprintf() and vsnprintf() implementations
- * Copyright (c) 2012 Ronald S. Bultje <rsbultje@gmail.com>
- *
- * 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 */
deleted file mode 100644
--- a/media/ffvpx/compat/strtod.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * C99-compatible strtod() implementation
- * Copyright (c) 2012 Ronald S. Bultje <rsbultje@gmail.com>
- *
- * 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 <limits.h>
-#include <stdlib.h>
-
-#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 (av_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;
-}
--- a/media/ffvpx/ffvpxcommon.mozbuild
+++ b/media/ffvpx/ffvpxcommon.mozbuild
@@ -73,21 +73,16 @@ elif CONFIG['_MSC_VER']:
         '-wd4245', # conversion from 'int' to 'uint32_t', signed/unsigned mismatch
         '-wd4703', # potentially uninitialized local pointer
         '-wd4293', # '<<' : shift count negative or too big, undefined behavior
         # from FFmpeg configure
         '-wd4244', '-wd4127', '-wd4018', '-wd4389', '-wd4146', '-wd4701',
         '-wd4057', '-wd4204', '-wd4706', '-wd4305', '-wd4152', '-wd4324',
         '-we4013', '-wd4100', '-wd4214', '-wd4307', '-wd4273', '-wd4554',
     ]
-    if CONFIG['_MSC_VER'] < '1900':
-        DEFINES['MSVC_2013_OR_LOWER'] = True
-        DEFINES['snprintf'] = "avpriv_snprintf"
-        DEFINES['_snprintf'] = "avpriv_snprintf"
-        DEFINES['vsnprintf'] = "avpriv_vsnprintf"
 
 DEFINES['HAVE_AV_CONFIG_H'] = True
 
 if CONFIG['MOZ_DEBUG']:
     # Enable all assertions in debug builds.
     DEFINES['ASSERT_LEVEL'] = 2
 elif not CONFIG['RELEASE_BUILD']:
     # Enable fast assertions in opt builds of Nightly and Aurora.
--- a/media/ffvpx/libavutil/avutil.symbols
+++ b/media/ffvpx/libavutil/avutil.symbols
@@ -327,13 +327,9 @@ avpriv_request_sample
 avpriv_scalarproduct_float_c
 avpriv_set_systematic_pal2
 avpriv_solve_lls
 avutil_configuration
 avutil_license
 avutil_version
 #ifdef XP_WIN
 avpriv_emms_yasm
-#ifdef MSVC_2013_OR_LOWER
-avpriv_snprintf
 #endif
-avpriv_strtod
-#endif
--- a/media/ffvpx/libavutil/internal.h
+++ b/media/ffvpx/libavutil/internal.h
@@ -233,17 +233,17 @@ void avpriv_report_missing_feature(void 
  *                a pointer to an AVClass struct
  * @param[in] msg string containing the name of the missing feature
  */
 void avpriv_request_sample(void *avc,
                            const char *msg, ...) av_printf_format(2, 3);
 
 #if HAVE_LIBC_MSVCRT
 #include <crtversion.h>
-#if defined(_VC_CRT_MAJOR_VERSION) && _VC_CRT_MAJOR_VERSION < 12
+#if defined(_VC_CRT_MAJOR_VERSION) && _VC_CRT_MAJOR_VERSION < 14
 #pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_strtod")
 #pragma comment(linker, "/include:" EXTERN_PREFIX "avpriv_snprintf")
 #endif
 
 #define avpriv_open ff_open
 #define PTRDIFF_SPECIFIER "Id"
 #define SIZE_SPECIFIER "Iu"
 #else
--- a/media/ffvpx/libavutil/moz.build
+++ b/media/ffvpx/libavutil/moz.build
@@ -46,23 +46,14 @@ SOURCES += [
     'reverse.c',
     'samplefmt.c',
     'threadmessage.c',
     'time.c',
     'timecode.c',
     'utils.c',
 ]
 
-if CONFIG['OS_ARCH'] == 'WINNT':
-    SOURCES += [
-        '../compat/strtod.c'
-    ]
-    if CONFIG['_MSC_VER'] < '1900':
-        SOURCES += [
-            '../compat/msvcrt/snprintf.c'
-        ]
-
 SYMBOLS_FILE =  'avutil.symbols'
 NO_VISIBILITY_FLAGS = True
 
 OS_LIBS += CONFIG['REALTIME_LIBS']
 
 include("../ffvpxcommon.mozbuild")
--- a/media/libav/libavcommon.mozbuild
+++ b/media/libav/libavcommon.mozbuild
@@ -9,19 +9,16 @@ if CONFIG['LIBAV_FFT_ASFLAGS']:
     ASFLAGS += CONFIG['LIBAV_FFT_ASFLAGS']
     ASFLAGS += ['-I%s/media/libav' % TOPSRCDIR]
     USE_YASM = True
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     # Fix inline symbols and math defines for windows.
     DEFINES['_USE_MATH_DEFINES'] = True
     DEFINES['inline'] = "__inline"
-    if CONFIG['_MSC_VER'] and CONFIG['_MSC_VER'] < '1900':
-        # snprintf is prefixed with an underscore on MSVC 2013.
-        DEFINES['snprintf'] = "_snprintf"
     ASFLAGS += ['-Pconfig_win.asm']
     # 32-bit windows need to prefix symbols with an underscore.
     if CONFIG['CPU_ARCH'] == 'x86':
         ASFLAGS += ['-DPREFIX']
 elif CONFIG['OS_ARCH'] == 'Darwin':
     # 32/64-bit macosx assemblers need to prefix symbols with an underscore.
     ASFLAGS += ['-Pconfig_darwin.asm', '-DPREFIX']
 else: