Bug 1690167 - Change VsprintfLiteral/SprintfLiteral to rely on PrintfTarget. r=nika,Gankra,firefox-build-system-reviewers,mhentges

Instead of snprintf.

Because some standalone code uses those functions directly or indirectly,
and PrintfTarget lives in mozglue, they now need to depend on mozglue
instead of mfbt. Except logalloc/replay, which cherry-picks what it
uses.

Differential Revision: https://phabricator.services.mozilla.com/D103730
This commit is contained in:
Mike Hommey 2021-02-16 21:20:04 +00:00
Родитель 34cf11e754
Коммит 622b111f9e
8 изменённых файлов: 55 добавлений и 40 удалений

Просмотреть файл

@ -7,7 +7,7 @@
with Files("**"): with Files("**"):
BUG_COMPONENT = ("Core", "Audio/Video: GMP") BUG_COMPONENT = ("Core", "Audio/Video: GMP")
SharedLibrary("clearkey") GeckoSharedLibrary("clearkey", linkage=None)
FINAL_TARGET = "dist/bin/gmp-clearkey/0.1" FINAL_TARGET = "dist/bin/gmp-clearkey/0.1"

Просмотреть файл

@ -44,7 +44,19 @@ if CONFIG["MOZ_DMD"] or CONFIG["MOZ_PHC"]:
"/mozglue/misc/StackWalk.h", "/mozglue/misc/StackWalk.h",
] ]
if not CONFIG["MOZ_REPLACE_MALLOC_STATIC"]: if CONFIG["MOZ_REPLACE_MALLOC_STATIC"]:
UNIFIED_SOURCES += [
"/mfbt/double-conversion/double-conversion/bignum-dtoa.cc",
"/mfbt/double-conversion/double-conversion/bignum.cc",
"/mfbt/double-conversion/double-conversion/cached-powers.cc",
"/mfbt/double-conversion/double-conversion/double-to-string.cc",
"/mfbt/double-conversion/double-conversion/fast-dtoa.cc",
"/mfbt/double-conversion/double-conversion/fixed-dtoa.cc",
"/mfbt/double-conversion/double-conversion/string-to-double.cc",
"/mfbt/double-conversion/double-conversion/strtod.cc",
"/mozglue/misc/Printf.cpp",
]
else:
SOURCES += [ SOURCES += [
"../FdPrintf.cpp", "../FdPrintf.cpp",
] ]

Просмотреть файл

@ -91,9 +91,6 @@ if not CONFIG["MOZ_ASAN"]:
] ]
) )
# Since we link directly with MFBT object files, define IMPL_MFBT
DEFINES["IMPL_MFBT"] = True
DisableStlWrapping() DisableStlWrapping()
if CONFIG["CC_TYPE"] == "clang-cl": if CONFIG["CC_TYPE"] == "clang-cl":
@ -103,7 +100,7 @@ if CONFIG["CC_TYPE"] == "clang-cl":
] ]
USE_LIBS += [ USE_LIBS += [
"mfbt", "mozglue",
] ]
if CONFIG["CC_TYPE"] in ("clang", "gcc"): if CONFIG["CC_TYPE"] in ("clang", "gcc"):

Просмотреть файл

@ -88,6 +88,8 @@ class PrintfTarget {
bool MFBT_API appendIntOct(uint64_t); bool MFBT_API appendIntOct(uint64_t);
bool MFBT_API appendIntHex(uint64_t); bool MFBT_API appendIntHex(uint64_t);
inline size_t emitted() { return mEmitted; }
protected: protected:
MFBT_API PrintfTarget(); MFBT_API PrintfTarget();
virtual ~PrintfTarget() = default; virtual ~PrintfTarget() = default;

Просмотреть файл

@ -11,19 +11,52 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <algorithm>
#include "mozilla/Assertions.h" #include "mozilla/Assertions.h"
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/Printf.h"
#ifdef __cplusplus #ifdef __cplusplus
namespace mozilla {
namespace detail {
struct MOZ_STACK_CLASS SprintfAppend final : public mozilla::PrintfTarget {
template <size_t N>
explicit SprintfAppend(char (&aBuf)[N]) : mBuf(aBuf), mBufLen(N) {}
bool append(const char* aStr, size_t aLen) override {
if (aLen == 0) {
return true;
}
// Don't copy more than what's left to use.
size_t copy = std::min(mBufLen, aLen);
if (copy > 0) {
memcpy(mBuf, aStr, copy);
mBuf += copy;
mBufLen -= copy;
}
return true;
}
private:
char* mBuf;
size_t mBufLen;
};
} // namespace detail
} // namespace mozilla
template <size_t N> template <size_t N>
MOZ_FORMAT_PRINTF(2, 0) MOZ_FORMAT_PRINTF(2, 0)
int VsprintfLiteral(char (&buffer)[N], const char* format, va_list args) { int VsprintfLiteral(char (&buffer)[N], const char* format, va_list args) {
MOZ_ASSERT(format != buffer); MOZ_ASSERT(format != buffer);
int result = vsnprintf(buffer, N, format, args); mozilla::detail::SprintfAppend ss(buffer);
buffer[N - 1] = '\0'; ss.vprint(format, args);
return result; size_t len = ss.emitted();
buffer[std::min(len, N - 1)] = '\0';
return len;
} }
template <size_t N> template <size_t N>

Просмотреть файл

@ -1,23 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Attributes.h"
#include "mozilla/TsanOptions.h"
#ifndef _MSC_VER // Not supported by clang-cl yet
// See also mozglue/build/TsanOptions.cpp before modifying this
extern "C" const char* __tsan_default_suppressions() {
// clang-format off
return "# Add your suppressions below\n"
// External uninstrumented libraries
MOZ_TSAN_DEFAULT_EXTLIB_SUPPRESSIONS
// End of suppressions.
; // Please keep this semicolon.
// clang-format on
}
#endif // _MSC_VER

Просмотреть файл

@ -43,6 +43,7 @@ if CONFIG["OS_ARCH"] == "WINNT":
USE_LIBS += [ USE_LIBS += [
"bspatch", "bspatch",
"mar", "mar",
"mozglue",
"updatecommon", "updatecommon",
"xz-embedded", "xz-embedded",
] ]
@ -78,13 +79,6 @@ if have_progressui == 0:
SOURCES += sorted(srcs) SOURCES += sorted(srcs)
if CONFIG["MOZ_TSAN"]:
# Since mozglue is not linked to the updater,
# we need to include our own TSan suppression list.
SOURCES += [
"TsanOptions.cpp",
]
DEFINES["NS_NO_XPCOM"] = True DEFINES["NS_NO_XPCOM"] = True
DisableStlWrapping() DisableStlWrapping()
for var in ("MAR_CHANNEL_ID", "MOZ_APP_VERSION"): for var in ("MAR_CHANNEL_ID", "MOZ_APP_VERSION"):

Просмотреть файл

@ -24,7 +24,7 @@ test_progs = [
] ]
SimplePrograms(test_progs) SimplePrograms(test_progs)
USE_LIBS += ["mfbt"] USE_LIBS += ["mozglue"]
XPCSHELL_TESTS_MANIFESTS += ["unit/xpcshell.ini"] XPCSHELL_TESTS_MANIFESTS += ["unit/xpcshell.ini"]