diff options
author | dsinclair <dsinclair@chromium.org> | 2016-08-24 11:12:19 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-24 11:12:19 -0700 |
commit | cedaa557316a3f5c436814e69d67f19795f471d7 (patch) | |
tree | 128140994288bcd5b01f578e9dafc4bf1ea87493 /core/fpdfapi/fpdf_parser/cpdf_parser.cpp | |
parent | ade4b495433751ac853f2d677b9e1da94d0d6bf7 (diff) | |
download | pdfium-cedaa557316a3f5c436814e69d67f19795f471d7.tar.xz |
Flip document and parser ownership
This Cl switches the ownership between the parser and the document. Previously
the parser owned the document and we'd jump through hoops during cleanup to
delete the right object. This Cl flips the ownership so the document owns
the parser and simplifies the cleanup logic where needed.
BUG=pdfium:565
Review-Url: https://codereview.chromium.org/2275773003
Diffstat (limited to 'core/fpdfapi/fpdf_parser/cpdf_parser.cpp')
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_parser.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp index ffd3f79a62..e2bab450be 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp @@ -126,7 +126,7 @@ void CPDF_Parser::ShrinkObjectMap(uint32_t objnum) { void CPDF_Parser::CloseParser() { m_bVersionUpdated = false; - m_pDocument.reset(); + m_pDocument = nullptr; if (m_pTrailer) { m_pTrailer->Release(); @@ -158,9 +158,8 @@ void CPDF_Parser::CloseParser() { } } -CPDF_Parser::Error CPDF_Parser::StartParse( - IFX_FileRead* pFileAccess, - std::unique_ptr<CPDF_Document> pDocument) { +CPDF_Parser::Error CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, + CPDF_Document* pDocument) { CloseParser(); m_bXRefStream = FALSE; @@ -190,7 +189,7 @@ CPDF_Parser::Error CPDF_Parser::StartParse( return FORMAT_ERROR; m_pSyntax->RestorePos(m_pSyntax->m_FileLen - m_pSyntax->m_HeaderOffset - 9); - m_pDocument = std::move(pDocument); + m_pDocument = pDocument; FX_BOOL bXRefRebuilt = FALSE; if (m_pSyntax->SearchWord("startxref", TRUE, FALSE, 4096)) { @@ -765,7 +764,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { last_obj = start_pos; FX_FILESIZE obj_end = 0; CPDF_Object* pObject = ParseIndirectObjectAtByStrict( - m_pDocument.get(), obj_pos, objnum, &obj_end); + m_pDocument, obj_pos, objnum, &obj_end); if (CPDF_Stream* pStream = ToStream(pObject)) { if (CPDF_Dictionary* pDict = pStream->GetDict()) { if ((pDict->KeyExist("Type")) && @@ -828,8 +827,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { last_trailer = pos + i - 7; m_pSyntax->RestorePos(pos + i - m_pSyntax->m_HeaderOffset); - CPDF_Object* pObj = - m_pSyntax->GetObject(m_pDocument.get(), 0, 0, true); + CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true); if (pObj) { if (!pObj->IsDictionary() && !pObj->AsStream()) { pObj->Release(); @@ -851,7 +849,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { uint32_t dwObjNum = pElement ? pElement->GetObjNum() : 0; if (dwObjNum) { - m_pTrailer->SetAtReference(key, m_pDocument.get(), + m_pTrailer->SetAtReference(key, m_pDocument, dwObjNum); } else { m_pTrailer->SetAt(key, pElement->Clone()); @@ -975,7 +973,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { } FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { - CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument.get(), *pos, 0); + CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0); if (!pObject) return FALSE; @@ -1478,7 +1476,7 @@ CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { return nullptr; std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( - m_pSyntax->GetObject(m_pDocument.get(), 0, 0, true)); + m_pSyntax->GetObject(m_pDocument, 0, 0, true)); if (!ToDictionary(pObj.get())) return nullptr; return pObj.release()->AsDictionary(); @@ -1550,9 +1548,8 @@ FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, return FALSE; } -CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( - IFX_FileRead* pFileAccess, - std::unique_ptr<CPDF_Document> pDocument) { +CPDF_Parser::Error CPDF_Parser::StartLinearizedParse(IFX_FileRead* pFileAccess, + CPDF_Document* pDocument) { CloseParser(); m_bXRefStream = FALSE; m_LastXRefOffset = 0; @@ -1567,7 +1564,7 @@ CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( return StartParse(pFileAccess, std::move(pDocument)); } - m_pDocument = std::move(pDocument); + m_pDocument = pDocument; FX_FILESIZE dwFirstXRefOffset = m_pSyntax->SavePos(); FX_BOOL bXRefRebuilt = FALSE; |