Fix -Wexit-time-destructors warnings in non-test code.
Switch to pdfium_strict_config in remaining non-test targets.
Rename some modified constants to kFoo along the way.
Change-Id: I18876fcb635bcdc78e2707dea17955d6dbf56216
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/79855
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/BUILD.gn b/core/fpdfapi/page/BUILD.gn
index c762cdc..ca21c78 100644
--- a/core/fpdfapi/page/BUILD.gn
+++ b/core/fpdfapi/page/BUILD.gn
@@ -99,7 +99,7 @@
"cpdf_transparency.h",
"ipdf_page.h",
]
- configs += [ "../../../:pdfium_core_config" ]
+ configs += [ "../../../:pdfium_strict_config" ]
deps = [
"../../../constants",
"../../fxcodec",
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index c56cfc7..2039a57 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -38,6 +38,7 @@
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxge/cfx_graphstatedata.h"
#include "third_party/base/check.h"
+#include "third_party/base/no_destructor.h"
#include "third_party/base/notreached.h"
#include "third_party/base/span.h"
#include "third_party/base/stl_util.h"
@@ -535,10 +536,11 @@
}
void CPDF_StreamContentParser::OnOperator(ByteStringView op) {
- static const OpCodes s_OpCodes = InitializeOpCodes();
+ static const pdfium::base::NoDestructor<OpCodes> s_OpCodes(
+ InitializeOpCodes());
- auto it = s_OpCodes.find(op.GetID());
- if (it != s_OpCodes.end())
+ auto it = s_OpCodes->find(op.GetID());
+ if (it != s_OpCodes->end())
(this->*it->second)();
}
diff --git a/core/fxcrt/BUILD.gn b/core/fxcrt/BUILD.gn
index ed22e6f..a9ba304 100644
--- a/core/fxcrt/BUILD.gn
+++ b/core/fxcrt/BUILD.gn
@@ -87,7 +87,7 @@
"xml/cfx_xmltext.cpp",
"xml/cfx_xmltext.h",
]
- configs += [ "../../:pdfium_core_config" ]
+ configs += [ "../../:pdfium_strict_config" ]
visibility = [
"../*",
"../../:*",
diff --git a/core/fxcrt/fx_memory.cpp b/core/fxcrt/fx_memory.cpp
index 0c3e73d..5530a9b 100644
--- a/core/fxcrt/fx_memory.cpp
+++ b/core/fxcrt/fx_memory.cpp
@@ -14,20 +14,24 @@
#include "core/fxcrt/fx_safe_types.h"
#include "third_party/base/allocator/partition_allocator/partition_alloc.h"
#include "third_party/base/debug/alias.h"
+#include "third_party/base/no_destructor.h"
pdfium::base::PartitionAllocatorGeneric& GetArrayBufferPartitionAllocator() {
- static pdfium::base::PartitionAllocatorGeneric s_array_buffer_allocator;
- return s_array_buffer_allocator;
+ static pdfium::base::NoDestructor<pdfium::base::PartitionAllocatorGeneric>
+ s_array_buffer_allocator;
+ return *s_array_buffer_allocator;
}
pdfium::base::PartitionAllocatorGeneric& GetGeneralPartitionAllocator() {
- static pdfium::base::PartitionAllocatorGeneric s_general_allocator;
- return s_general_allocator;
+ static pdfium::base::NoDestructor<pdfium::base::PartitionAllocatorGeneric>
+ s_general_allocator;
+ return *s_general_allocator;
}
pdfium::base::PartitionAllocatorGeneric& GetStringPartitionAllocator() {
- static pdfium::base::PartitionAllocatorGeneric s_string_allocator;
- return s_string_allocator;
+ static pdfium::base::NoDestructor<pdfium::base::PartitionAllocatorGeneric>
+ s_string_allocator;
+ return *s_string_allocator;
}
void FXMEM_InitializePartitionAlloc() {
diff --git a/fxjs/BUILD.gn b/fxjs/BUILD.gn
index 0d9dc05..4159d6e 100644
--- a/fxjs/BUILD.gn
+++ b/fxjs/BUILD.gn
@@ -15,7 +15,7 @@
"ijs_runtime.cpp",
"ijs_runtime.h",
]
- configs += [ "../:pdfium_core_config" ]
+ configs += [ "../:pdfium_strict_config" ]
deps = [ "../core/fxcrt" ]
visibility = [ "../*" ]
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index 9f15141..3342bb9 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -1174,20 +1174,17 @@
}
ByteString TrillionUS(ByteStringView bsData) {
- static const ByteStringView pUnits[] = {"zero", "one", "two", "three",
- "four", "five", "six", "seven",
- "eight", "nine"};
- static const ByteStringView pCapUnits[] = {"Zero", "One", "Two", "Three",
- "Four", "Five", "Six", "Seven",
- "Eight", "Nine"};
- static const ByteStringView pTens[] = {
+ static const char kUnits[][6] = {"zero", "one", "two", "three", "four",
+ "five", "six", "seven", "eight", "nine"};
+ static const char kCapUnits[][6] = {"Zero", "One", "Two", "Three", "Four",
+ "Five", "Six", "Seven", "Eight", "Nine"};
+ static const char kTens[][10] = {
"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen",
"Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};
- static const ByteStringView pLastTens[] = {"Twenty", "Thirty", "Forty",
- "Fifty", "Sixty", "Seventy",
- "Eighty", "Ninety"};
- static const ByteStringView pComm[] = {" Hundred ", " Thousand ", " Million ",
- " Billion ", "Trillion"};
+ static const char kLastTens[][8] = {"Twenty", "Thirty", "Forty", "Fifty",
+ "Sixty", "Seventy", "Eighty", "Ninety"};
+ static const char kComm[][11] = {" Hundred ", " Thousand ", " Million ",
+ " Billion ", "Trillion"};
const char* pData = bsData.unterminated_c_str();
int32_t iLength = bsData.GetLength();
int32_t iComm = 0;
@@ -1208,66 +1205,66 @@
int32_t iIndex = 0;
if (iFirstCount == 3) {
if (pData[iIndex] != '0') {
- strBuf << pCapUnits[pData[iIndex] - '0'];
- strBuf << pComm[0];
+ strBuf << kCapUnits[pData[iIndex] - '0'];
+ strBuf << kComm[0];
}
if (pData[iIndex + 1] == '0') {
- strBuf << pCapUnits[pData[iIndex + 2] - '0'];
+ strBuf << kCapUnits[pData[iIndex + 2] - '0'];
} else {
if (pData[iIndex + 1] > '1') {
- strBuf << pLastTens[pData[iIndex + 1] - '2'];
+ strBuf << kLastTens[pData[iIndex + 1] - '2'];
strBuf << "-";
- strBuf << pUnits[pData[iIndex + 2] - '0'];
+ strBuf << kUnits[pData[iIndex + 2] - '0'];
} else if (pData[iIndex + 1] == '1') {
- strBuf << pTens[pData[iIndex + 2] - '0'];
+ strBuf << kTens[pData[iIndex + 2] - '0'];
} else if (pData[iIndex + 1] == '0') {
- strBuf << pCapUnits[pData[iIndex + 2] - '0'];
+ strBuf << kCapUnits[pData[iIndex + 2] - '0'];
}
}
iIndex += 3;
} else if (iFirstCount == 2) {
if (pData[iIndex] == '0') {
- strBuf << pCapUnits[pData[iIndex + 1] - '0'];
+ strBuf << kCapUnits[pData[iIndex + 1] - '0'];
} else {
if (pData[iIndex] > '1') {
- strBuf << pLastTens[pData[iIndex] - '2'];
+ strBuf << kLastTens[pData[iIndex] - '2'];
strBuf << "-";
- strBuf << pUnits[pData[iIndex + 1] - '0'];
+ strBuf << kUnits[pData[iIndex + 1] - '0'];
} else if (pData[iIndex] == '1') {
- strBuf << pTens[pData[iIndex + 1] - '0'];
+ strBuf << kTens[pData[iIndex + 1] - '0'];
} else if (pData[iIndex] == '0') {
- strBuf << pCapUnits[pData[iIndex + 1] - '0'];
+ strBuf << kCapUnits[pData[iIndex + 1] - '0'];
}
}
iIndex += 2;
} else if (iFirstCount == 1) {
- strBuf << pCapUnits[pData[iIndex] - '0'];
+ strBuf << kCapUnits[pData[iIndex] - '0'];
++iIndex;
}
if (iLength > 3 && iFirstCount > 0) {
- strBuf << pComm[iComm];
+ strBuf << kComm[iComm];
--iComm;
}
while (iIndex < iLength) {
if (pData[iIndex] != '0') {
- strBuf << pCapUnits[pData[iIndex] - '0'];
- strBuf << pComm[0];
+ strBuf << kCapUnits[pData[iIndex] - '0'];
+ strBuf << kComm[0];
}
if (pData[iIndex + 1] == '0') {
- strBuf << pCapUnits[pData[iIndex + 2] - '0'];
+ strBuf << kCapUnits[pData[iIndex + 2] - '0'];
} else {
if (pData[iIndex + 1] > '1') {
- strBuf << pLastTens[pData[iIndex + 1] - '2'];
+ strBuf << kLastTens[pData[iIndex + 1] - '2'];
strBuf << "-";
- strBuf << pUnits[pData[iIndex + 2] - '0'];
+ strBuf << kUnits[pData[iIndex + 2] - '0'];
} else if (pData[iIndex + 1] == '1') {
- strBuf << pTens[pData[iIndex + 2] - '0'];
+ strBuf << kTens[pData[iIndex + 2] - '0'];
} else if (pData[iIndex + 1] == '0') {
- strBuf << pCapUnits[pData[iIndex + 2] - '0'];
+ strBuf << kCapUnits[pData[iIndex + 2] - '0'];
}
}
if (iIndex < iLength - 3) {
- strBuf << pComm[iComm];
+ strBuf << kComm[iComm];
--iComm;
}
iIndex += 3;