зеркало из https://github.com/mozilla/gecko-dev.git
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, and the updater, for which we keep using vsnprintf. Differential Revision: https://phabricator.services.mozilla.com/D103730
This commit is contained in:
Родитель
e47bda795b
Коммит
9c0fcac97c
|
@ -7,7 +7,7 @@
|
|||
with Files("**"):
|
||||
BUG_COMPONENT = ("Core", "Audio/Video: GMP")
|
||||
|
||||
SharedLibrary("clearkey")
|
||||
GeckoSharedLibrary("clearkey", linkage=None)
|
||||
|
||||
FINAL_TARGET = "dist/bin/gmp-clearkey/0.1"
|
||||
|
||||
|
|
|
@ -44,7 +44,19 @@ if CONFIG["MOZ_DMD"] or CONFIG["MOZ_PHC"]:
|
|||
"/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 += [
|
||||
"../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()
|
||||
|
||||
if CONFIG["CC_TYPE"] == "clang-cl":
|
||||
|
@ -103,7 +100,7 @@ if CONFIG["CC_TYPE"] == "clang-cl":
|
|||
]
|
||||
|
||||
USE_LIBS += [
|
||||
"mfbt",
|
||||
"mozglue",
|
||||
]
|
||||
|
||||
if CONFIG["CC_TYPE"] in ("clang", "gcc"):
|
||||
|
|
|
@ -88,6 +88,8 @@ class PrintfTarget {
|
|||
bool MFBT_API appendIntOct(uint64_t);
|
||||
bool MFBT_API appendIntHex(uint64_t);
|
||||
|
||||
inline size_t emitted() { return mEmitted; }
|
||||
|
||||
protected:
|
||||
MFBT_API PrintfTarget();
|
||||
virtual ~PrintfTarget() = default;
|
||||
|
|
|
@ -11,19 +11,60 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Printf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
# ifndef SPRINTF_H_USES_VSNPRINTF
|
||||
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
|
||||
# endif // SPRINTF_H_USES_VSNPRINTF
|
||||
|
||||
template <size_t N>
|
||||
MOZ_FORMAT_PRINTF(2, 0)
|
||||
int VsprintfLiteral(char (&buffer)[N], const char* format, va_list args) {
|
||||
MOZ_ASSERT(format != buffer);
|
||||
# ifdef SPRINTF_H_USES_VSNPRINTF
|
||||
int result = vsnprintf(buffer, N, format, args);
|
||||
buffer[N - 1] = '\0';
|
||||
return result;
|
||||
# else
|
||||
mozilla::detail::SprintfAppend ss(buffer);
|
||||
ss.vprint(format, args);
|
||||
size_t len = ss.emitted();
|
||||
buffer[std::min(len, N - 1)] = '\0';
|
||||
return len;
|
||||
# endif
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
|
|
|
@ -85,6 +85,7 @@ if CONFIG["MOZ_TSAN"]:
|
|||
"TsanOptions.cpp",
|
||||
]
|
||||
|
||||
DEFINES["SPRINTF_H_USES_VSNPRINTF"] = True
|
||||
DEFINES["NS_NO_XPCOM"] = True
|
||||
DisableStlWrapping()
|
||||
for var in ("MAR_CHANNEL_ID", "MOZ_APP_VERSION"):
|
||||
|
|
|
@ -24,7 +24,7 @@ test_progs = [
|
|||
]
|
||||
SimplePrograms(test_progs)
|
||||
|
||||
USE_LIBS += ["mfbt"]
|
||||
USE_LIBS += ["mozglue"]
|
||||
|
||||
XPCSHELL_TESTS_MANIFESTS += ["unit/xpcshell.ini"]
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче