Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 47675f5

Browse files
committed
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
1 parent 8207cff commit 47675f5

8 files changed

Lines changed: 55 additions & 40 deletions

File tree

media/gmp-clearkey/0.1/moz.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
with Files("**"):
88
BUG_COMPONENT = ("Core", "Audio/Video: GMP")
99

10-
SharedLibrary("clearkey")
10+
GeckoSharedLibrary("clearkey", linkage=None)
1111

1212
FINAL_TARGET = "dist/bin/gmp-clearkey/0.1"
1313

memory/replace/logalloc/replay/moz.build

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,19 @@ if CONFIG["MOZ_DMD"] or CONFIG["MOZ_PHC"]:
4444
"/mozglue/misc/StackWalk.h",
4545
]
4646

47-
if not CONFIG["MOZ_REPLACE_MALLOC_STATIC"]:
47+
if CONFIG["MOZ_REPLACE_MALLOC_STATIC"]:
48+
UNIFIED_SOURCES += [
49+
"/mfbt/double-conversion/double-conversion/bignum-dtoa.cc",
50+
"/mfbt/double-conversion/double-conversion/bignum.cc",
51+
"/mfbt/double-conversion/double-conversion/cached-powers.cc",
52+
"/mfbt/double-conversion/double-conversion/double-to-string.cc",
53+
"/mfbt/double-conversion/double-conversion/fast-dtoa.cc",
54+
"/mfbt/double-conversion/double-conversion/fixed-dtoa.cc",
55+
"/mfbt/double-conversion/double-conversion/string-to-double.cc",
56+
"/mfbt/double-conversion/double-conversion/strtod.cc",
57+
"/mozglue/misc/Printf.cpp",
58+
]
59+
else:
4860
SOURCES += [
4961
"../FdPrintf.cpp",
5062
]

mfbt/tests/moz.build

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ if not CONFIG["MOZ_ASAN"]:
9191
]
9292
)
9393

94-
# Since we link directly with MFBT object files, define IMPL_MFBT
95-
DEFINES["IMPL_MFBT"] = True
96-
9794
DisableStlWrapping()
9895

9996
if CONFIG["CC_TYPE"] == "clang-cl":
@@ -103,7 +100,7 @@ if CONFIG["CC_TYPE"] == "clang-cl":
103100
]
104101

105102
USE_LIBS += [
106-
"mfbt",
103+
"mozglue",
107104
]
108105

109106
if CONFIG["CC_TYPE"] in ("clang", "gcc"):

mozglue/misc/Printf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class PrintfTarget {
8888
bool MFBT_API appendIntOct(uint64_t);
8989
bool MFBT_API appendIntHex(uint64_t);
9090

91+
inline size_t emitted() { return mEmitted; }
92+
9193
protected:
9294
MFBT_API PrintfTarget();
9395
virtual ~PrintfTarget() = default;

mozglue/misc/Sprintf.h

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,52 @@
1111

1212
#include <stdio.h>
1313
#include <stdarg.h>
14+
#include <algorithm>
1415

1516
#include "mozilla/Assertions.h"
1617
#include "mozilla/Attributes.h"
18+
#include "mozilla/Printf.h"
1719

1820
#ifdef __cplusplus
1921

22+
namespace mozilla {
23+
namespace detail {
24+
25+
struct MOZ_STACK_CLASS SprintfAppend final : public mozilla::PrintfTarget {
26+
template <size_t N>
27+
explicit SprintfAppend(char (&aBuf)[N]) : mBuf(aBuf), mBufLen(N) {}
28+
29+
bool append(const char* aStr, size_t aLen) override {
30+
if (aLen == 0) {
31+
return true;
32+
}
33+
// Don't copy more than what's left to use.
34+
size_t copy = std::min(mBufLen, aLen);
35+
if (copy > 0) {
36+
memcpy(mBuf, aStr, copy);
37+
mBuf += copy;
38+
mBufLen -= copy;
39+
}
40+
return true;
41+
}
42+
43+
private:
44+
char* mBuf;
45+
size_t mBufLen;
46+
};
47+
48+
} // namespace detail
49+
} // namespace mozilla
50+
2051
template <size_t N>
2152
MOZ_FORMAT_PRINTF(2, 0)
2253
int VsprintfLiteral(char (&buffer)[N], const char* format, va_list args) {
2354
MOZ_ASSERT(format != buffer);
24-
int result = vsnprintf(buffer, N, format, args);
25-
buffer[N - 1] = '\0';
26-
return result;
55+
mozilla::detail::SprintfAppend ss(buffer);
56+
ss.vprint(format, args);
57+
size_t len = ss.emitted();
58+
buffer[std::min(len, N - 1)] = '\0';
59+
return len;
2760
}
2861

2962
template <size_t N>

toolkit/mozapps/update/updater/TsanOptions.cpp

Lines changed: 0 additions & 23 deletions
This file was deleted.

toolkit/mozapps/update/updater/updater-common.build

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ if CONFIG["OS_ARCH"] == "WINNT":
4343
USE_LIBS += [
4444
"bspatch",
4545
"mar",
46+
"mozglue",
4647
"updatecommon",
4748
"xz-embedded",
4849
]
@@ -78,13 +79,6 @@ if have_progressui == 0:
7879

7980
SOURCES += sorted(srcs)
8081

81-
if CONFIG["MOZ_TSAN"]:
82-
# Since mozglue is not linked to the updater,
83-
# we need to include our own TSan suppression list.
84-
SOURCES += [
85-
"TsanOptions.cpp",
86-
]
87-
8882
DEFINES["NS_NO_XPCOM"] = True
8983
DisableStlWrapping()
9084
for var in ("MAR_CHANNEL_ID", "MOZ_APP_VERSION"):

xpcom/tests/moz.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test_progs = [
2424
]
2525
SimplePrograms(test_progs)
2626

27-
USE_LIBS += ["mfbt"]
27+
USE_LIBS += ["mozglue"]
2828

2929
XPCSHELL_TESTS_MANIFESTS += ["unit/xpcshell.ini"]
3030

0 commit comments

Comments
 (0)