From b86544285e263310c1017a3aa056d71e68c5d5a1 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 26 Jun 2018 15:19:38 +0000 Subject: Make CPDF_Document::m_pRootDict an UnownedPtr<>. In turn, this requires making some of the tests use an indirect root dictionary so as to satisfy the lifetime requirements. Change-Id: Ibdbe294a76200d4486134e5848c169a6c2d802bf Reviewed-on: https://pdfium-review.googlesource.com/36110 Commit-Queue: dsinclair Reviewed-by: dsinclair --- core/fpdfapi/parser/cpdf_document.h | 8 ++----- core/fpdfapi/parser/cpdf_document_unittest.cpp | 31 +++++++++----------------- 2 files changed, 13 insertions(+), 26 deletions(-) (limited to 'core/fpdfapi/parser') diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h index 94d20504c5..db659b38c8 100644 --- a/core/fpdfapi/parser/cpdf_document.h +++ b/core/fpdfapi/parser/cpdf_document.h @@ -61,8 +61,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder { } CPDF_Parser* GetParser() const { return m_pParser.get(); } - const CPDF_Dictionary* GetRoot() const { return m_pRootDict; } - CPDF_Dictionary* GetRoot() { return m_pRootDict; } + CPDF_Dictionary* GetRoot() const { return m_pRootDict.Get(); } CPDF_Dictionary* GetInfo(); void DeletePage(int iPage); @@ -148,10 +147,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder { void ResetTraversal(); std::unique_ptr m_pParser; - - // TODO(tsepez): figure out why tests break if this is an UnownedPtr. - CPDF_Dictionary* m_pRootDict; // Not owned. - + UnownedPtr m_pRootDict; UnownedPtr m_pInfoDict; // Vector of pairs to know current position in the page tree. The index in the diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp index f06a7f42d3..fa52d3bc7f 100644 --- a/core/fpdfapi/parser/cpdf_document_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp @@ -87,20 +87,16 @@ class CPDF_TestDocumentForPages : public CPDF_Document { CPDF_Dictionary* pagesDict = CreatePageTreeNode(std::move(allPages), this, kNumTestPages); - m_pOwnedRootDict = pdfium::MakeUnique(); - m_pOwnedRootDict->SetNewFor("Pages", this, - pagesDict->GetObjNum()); - m_pRootDict = m_pOwnedRootDict.get(); + m_pRootDict = NewIndirect(); + m_pRootDict->SetNewFor("Pages", this, + pagesDict->GetObjNum()); m_PageList.resize(kNumTestPages); } void SetTreeSize(int size) { - m_pOwnedRootDict->SetNewFor("Count", size); + m_pRootDict->SetNewFor("Count", size); m_PageList.resize(size); } - - private: - std::unique_ptr m_pOwnedRootDict; }; class CPDF_TestDocumentWithPageWithoutPageNum : public CPDF_Document { @@ -116,17 +112,15 @@ class CPDF_TestDocumentWithPageWithoutPageNum : public CPDF_Document { inlined_page_ = allPages->Add(CreateNumberedPage(2)); CPDF_Dictionary* pagesDict = CreatePageTreeNode(std::move(allPages), this, 3); - m_pOwnedRootDict = pdfium::MakeUnique(); - m_pOwnedRootDict->SetNewFor("Pages", this, - pagesDict->GetObjNum()); - m_pRootDict = m_pOwnedRootDict.get(); + m_pRootDict = NewIndirect(); + m_pRootDict->SetNewFor("Pages", this, + pagesDict->GetObjNum()); m_PageList.resize(3); } const CPDF_Object* inlined_page() const { return inlined_page_; } private: - std::unique_ptr m_pOwnedRootDict; const CPDF_Object* inlined_page_; }; @@ -143,15 +137,12 @@ class CPDF_TestDocPagesWithoutKids : public CPDF_Document { pagesDict->SetNewFor("Type", "Pages"); pagesDict->SetNewFor("Count", 3); m_PageList.resize(10); - m_pOwnedRootDict = pdfium::MakeUnique(); - m_pOwnedRootDict->SetNewFor("Pages", this, - pagesDict->GetObjNum()); - m_pRootDict = m_pOwnedRootDict.get(); + m_pRootDict = NewIndirect(); + m_pRootDict->SetNewFor("Pages", this, + pagesDict->GetObjNum()); } - - private: - std::unique_ptr m_pOwnedRootDict; }; + } // namespace class cpdf_document_test : public testing::Test { -- cgit v1.2.3