From 99406198ac4921a53425edc73cac67e7b4760895 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 9 Mar 2016 17:37:12 -0800 Subject: Move ScopedSetInsertion to third_party/base/stl_util.h Also move ScopedFileStream, since it isn't specific to the parser, and belongs with the fxcrt object it manipulates. R=ochang@chromium.org Review URL: https://codereview.chromium.org/1780063003 . --- core/include/fpdfapi/fpdf_parser.h | 19 ------------------- core/include/fxcrt/fx_ext.h | 6 ++++++ core/src/fpdfapi/fpdf_parser/cpdf_document.cpp | 3 ++- core/src/fpdfapi/fpdf_parser/cpdf_parser.cpp | 2 +- .../fpdf_parser/fpdf_parser_parser_unittest.cpp | 1 + fpdfsdk/src/fpdfsave.cpp | 1 + third_party/base/stl_util.h | 17 +++++++++++++++++ 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/core/include/fpdfapi/fpdf_parser.h b/core/include/fpdfapi/fpdf_parser.h index 7d7243c90f..705587c513 100644 --- a/core/include/fpdfapi/fpdf_parser.h +++ b/core/include/fpdfapi/fpdf_parser.h @@ -42,25 +42,6 @@ class IPDF_SecurityHandler; #define FPDFPERM_PRINT_HIGH 0x0800 #define FPDF_PAGE_MAX_NUM 0xFFFFF -// TODO(thestig) Using unique_ptr with ReleaseDeleter is still not ideal. -// Come up or wait for something better. -using ScopedFileStream = - std::unique_ptr>; - -template -class ScopedSetInsertion { - public: - ScopedSetInsertion(std::set* org_set, T elem) - : m_Set(org_set), m_Entry(elem) { - m_Set->insert(m_Entry); - } - ~ScopedSetInsertion() { m_Set->erase(m_Entry); } - - private: - std::set* const m_Set; - const T m_Entry; -}; - // Indexed by 8-bit char code, contains unicode code points. extern const FX_WORD PDFDocEncoding[256]; diff --git a/core/include/fxcrt/fx_ext.h b/core/include/fxcrt/fx_ext.h index c8afb2b793..689d8e8fc4 100644 --- a/core/include/fxcrt/fx_ext.h +++ b/core/include/fxcrt/fx_ext.h @@ -12,6 +12,12 @@ #include "core/include/fxcrt/fx_basic.h" +// TODO(thestig) Using unique_ptr with ReleaseDeleter is still not ideal. +// Come up or wait for something better. This appears in this file rather +// than fx_stream.h due to include ordering restrictions. +using ScopedFileStream = + std::unique_ptr>; + FX_FLOAT FXSYS_tan(FX_FLOAT a); FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x); FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_document.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_document.cpp index d97d6e01ff..e509e36382 100644 --- a/core/src/fpdfapi/fpdf_parser/cpdf_document.cpp +++ b/core/src/fpdfapi/fpdf_parser/cpdf_document.cpp @@ -35,7 +35,8 @@ int CountPages(CPDF_Dictionary* pPages, } if (pKid->KeyExist("Kids")) { // Use |visited_pages| to help detect circular references of pages. - ScopedSetInsertion local_add(visited_pages, pKid); + pdfium::ScopedSetInsertion local_add(visited_pages, + pKid); count += CountPages(pKid, visited_pages); } else { // This page is a leaf node. diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_parser.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_parser.cpp index 675eec8f3a..45d29f9351 100644 --- a/core/src/fpdfapi/fpdf_parser/cpdf_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/cpdf_parser.cpp @@ -1150,8 +1150,8 @@ CPDF_Object* CPDF_Parser::ParseIndirectObject( // Prevent circular parsing the same object. if (pdfium::ContainsKey(m_ParsingObjNums, objnum)) return nullptr; - ScopedSetInsertion local_insert(&m_ParsingObjNums, objnum); + pdfium::ScopedSetInsertion local_insert(&m_ParsingObjNums, objnum); if (GetObjectType(objnum) == 1 || GetObjectType(objnum) == 255) { FX_FILESIZE pos = m_ObjectInfo[objnum].pos; if (pos <= 0) diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp index c8e1ceec0b..49521b0102 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp @@ -8,6 +8,7 @@ #include "core/include/fpdfapi/cpdf_parser.h" #include "core/include/fpdfapi/fpdf_parser.h" #include "core/include/fxcrt/fx_stream.h" +#include "core/include/fxcrt/fx_ext.h" #include "core/src/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/utils/path_service.h" diff --git a/fpdfsdk/src/fpdfsave.cpp b/fpdfsdk/src/fpdfsave.cpp index 0971a4bcd1..1193223632 100644 --- a/fpdfsdk/src/fpdfsave.cpp +++ b/fpdfsdk/src/fpdfsave.cpp @@ -11,6 +11,7 @@ #include "core/include/fpdfapi/cpdf_document.h" #include "core/include/fpdfapi/fpdf_parser.h" #include "core/include/fpdfapi/fpdf_serial.h" +#include "core/include/fxcrt/fx_ext.h" #include "fpdfsdk/include/fsdk_define.h" #include "public/fpdf_edit.h" diff --git a/third_party/base/stl_util.h b/third_party/base/stl_util.h index 353d3a68c3..2d1846724c 100644 --- a/third_party/base/stl_util.h +++ b/third_party/base/stl_util.h @@ -6,6 +6,7 @@ #define PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ #include +#include #include "third_party/base/numerics/safe_conversions.h" @@ -33,6 +34,22 @@ ResultType CollectionSize(const Collection& collection) { return pdfium::base::checked_cast(collection.size()); } +// Track the addition of an object to a set, removing it automatically when +// the ScopedSetInsertion goes out of scope. +template +class ScopedSetInsertion { + public: + ScopedSetInsertion(std::set* org_set, T elem) + : m_Set(org_set), m_Entry(elem) { + m_Set->insert(m_Entry); + } + ~ScopedSetInsertion() { m_Set->erase(m_Entry); } + + private: + std::set* const m_Set; + const T m_Entry; +}; + } // namespace pdfium #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ -- cgit v1.2.3