diff options
author | tsepez <tsepez@chromium.org> | 2016-11-04 11:38:40 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-04 11:38:40 -0700 |
commit | 33fdebc3da676bff84d0fd0f69b9087c0c12dfeb (patch) | |
tree | 274499f6bc4df60ebb57a52bf78b82180ea52295 /core/fpdfapi/page | |
parent | 761eed284e1248f851fbb23beaa45835b644ecee (diff) | |
download | pdfium-33fdebc3da676bff84d0fd0f69b9087c0c12dfeb.tar.xz |
Reland "Remove CPDF_Object::Release() in favor of direct delete"
This reverts commit f0d5b6c35fa343108a3ab7a25bc2cc2b3cf105b3.
Review-Url: https://codereview.chromium.org/2478303002
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r-- | core/fpdfapi/page/cpdf_contentmark.cpp | 3 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_contentmarkitem.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_contentmarkitem.h | 6 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_image.cpp | 18 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_image.h | 6 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.cpp | 43 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/page/fpdf_page_parser_old.cpp | 16 |
8 files changed, 43 insertions, 53 deletions
diff --git a/core/fpdfapi/page/cpdf_contentmark.cpp b/core/fpdfapi/page/cpdf_contentmark.cpp index d60e144d6e..a867409335 100644 --- a/core/fpdfapi/page/cpdf_contentmark.cpp +++ b/core/fpdfapi/page/cpdf_contentmark.cpp @@ -110,8 +110,7 @@ void CPDF_ContentMark::MarkData::AddMark(const CFX_ByteString& name, if (pDict) { if (bDirect) { item.SetDirectDict( - std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>( - ToDictionary(pDict->Clone()))); + std::unique_ptr<CPDF_Dictionary>(ToDictionary(pDict->Clone()))); } else { item.SetPropertiesDict(pDict); } diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.cpp b/core/fpdfapi/page/cpdf_contentmarkitem.cpp index 597f8a595c..dffeada707 100644 --- a/core/fpdfapi/page/cpdf_contentmarkitem.cpp +++ b/core/fpdfapi/page/cpdf_contentmarkitem.cpp @@ -39,7 +39,7 @@ bool CPDF_ContentMarkItem::HasMCID() const { } void CPDF_ContentMarkItem::SetDirectDict( - std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict) { + std::unique_ptr<CPDF_Dictionary> pDict) { m_ParamType = DirectDict; m_pDirectDict = std::move(pDict); } diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.h b/core/fpdfapi/page/cpdf_contentmarkitem.h index f1f06c3a38..ed2737111b 100644 --- a/core/fpdfapi/page/cpdf_contentmarkitem.h +++ b/core/fpdfapi/page/cpdf_contentmarkitem.h @@ -31,16 +31,14 @@ class CPDF_ContentMarkItem { bool HasMCID() const; void SetName(const CFX_ByteString& name) { m_MarkName = name; } - void SetDirectDict( - std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict); + void SetDirectDict(std::unique_ptr<CPDF_Dictionary> pDict); void SetPropertiesDict(CPDF_Dictionary* pDict); private: CFX_ByteString m_MarkName; ParamType m_ParamType; CPDF_Dictionary* m_pPropertiesDict; // not owned. - std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> - m_pDirectDict; + std::unique_ptr<CPDF_Dictionary> m_pDirectDict; }; #endif // CORE_FPDFAPI_PAGE_CPDF_CONTENTMARKITEM_H_ diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp index 23c6e4f786..976d6d8c47 100644 --- a/core/fpdfapi/page/cpdf_image.cpp +++ b/core/fpdfapi/page/cpdf_image.cpp @@ -25,14 +25,16 @@ CPDF_Image::CPDF_Image(CPDF_Document* pDoc) : m_pDocument(pDoc) {} -CPDF_Image::CPDF_Image(CPDF_Document* pDoc, UniqueStream pStream) +CPDF_Image::CPDF_Image(CPDF_Document* pDoc, + std::unique_ptr<CPDF_Stream> pStream) : m_pDocument(pDoc), m_pStream(pStream.get()), m_pOwnedStream(std::move(pStream)) { if (!m_pStream) return; - m_pOwnedDict = ToDictionary(UniqueObject(m_pStream->GetDict()->Clone())); + m_pOwnedDict = + ToDictionary(std::unique_ptr<CPDF_Object>(m_pStream->GetDict()->Clone())); m_pDict = m_pOwnedDict.get(); FinishInitialization(); } @@ -61,13 +63,15 @@ void CPDF_Image::FinishInitialization() { CPDF_Image* CPDF_Image::Clone() { CPDF_Image* pImage = new CPDF_Image(m_pDocument); if (m_pOwnedStream) { - pImage->m_pOwnedStream = ToStream(UniqueObject(m_pOwnedStream->Clone())); + pImage->m_pOwnedStream = + ToStream(std::unique_ptr<CPDF_Object>(m_pOwnedStream->Clone())); pImage->m_pStream = pImage->m_pOwnedStream.get(); } else { pImage->m_pStream = m_pStream; } if (m_pOwnedDict) { - pImage->m_pOwnedDict = ToDictionary(UniqueObject(m_pOwnedDict->Clone())); + pImage->m_pOwnedDict = + ToDictionary(std::unique_ptr<CPDF_Object>(m_pOwnedDict->Clone())); pImage->m_pDict = pImage->m_pOwnedDict.get(); } else { pImage->m_pDict = m_pDict; @@ -289,10 +293,8 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) { pNewBitmap->Copy(pBitmap); pNewBitmap->ConvertFormat(FXDIB_Rgb); SetImage(pNewBitmap, iCompress); - if (pDict) { - pDict->Release(); - pDict = nullptr; - } + delete pDict; + pDict = nullptr; FX_Free(dest_buf); dest_buf = nullptr; dest_size = 0; diff --git a/core/fpdfapi/page/cpdf_image.h b/core/fpdfapi/page/cpdf_image.h index f619845597..02308db647 100644 --- a/core/fpdfapi/page/cpdf_image.h +++ b/core/fpdfapi/page/cpdf_image.h @@ -28,7 +28,7 @@ class IFX_SeekableWriteStream; class CPDF_Image { public: explicit CPDF_Image(CPDF_Document* pDoc); - CPDF_Image(CPDF_Document* pDoc, UniqueStream pStream); + CPDF_Image(CPDF_Document* pDoc, std::unique_ptr<CPDF_Stream> pStream); CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum); ~CPDF_Image(); @@ -84,8 +84,8 @@ class CPDF_Image { CPDF_Document* const m_pDocument; CPDF_Stream* m_pStream = nullptr; CPDF_Dictionary* m_pDict = nullptr; - UniqueStream m_pOwnedStream; - UniqueDictionary m_pOwnedDict; + std::unique_ptr<CPDF_Stream> m_pOwnedStream; + std::unique_ptr<CPDF_Dictionary> m_pOwnedDict; CPDF_Dictionary* m_pOC = nullptr; }; diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index ed6701382c..7618f8271f 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -180,12 +180,8 @@ CPDF_StreamContentParser::CPDF_StreamContentParser( CPDF_StreamContentParser::~CPDF_StreamContentParser() { ClearAllParams(); FX_Free(m_pPathPoints); - if (m_pLastImageDict) { - m_pLastImageDict->Release(); - } - if (m_pLastCloneImageDict) { - m_pLastCloneImageDict->Release(); - } + delete m_pLastImageDict; + delete m_pLastCloneImageDict; } int CPDF_StreamContentParser::GetNextParamPos() { @@ -194,10 +190,9 @@ int CPDF_StreamContentParser::GetNextParamPos() { if (m_ParamStartPos == kParamBufSize) { m_ParamStartPos = 0; } - if (m_ParamBuf[m_ParamStartPos].m_Type == 0) { - if (CPDF_Object* pObject = m_ParamBuf[m_ParamStartPos].m_pObject) - pObject->Release(); - } + if (m_ParamBuf[m_ParamStartPos].m_Type == 0) + delete m_ParamBuf[m_ParamStartPos].m_pObject; + return m_ParamStartPos; } int index = m_ParamStartPos + m_ParamCount; @@ -244,10 +239,9 @@ void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) { void CPDF_StreamContentParser::ClearAllParams() { uint32_t index = m_ParamStartPos; for (uint32_t i = 0; i < m_ParamCount; i++) { - if (m_ParamBuf[index].m_Type == 0) { - if (CPDF_Object* pObject = m_ParamBuf[index].m_pObject) - pObject->Release(); - } + if (m_ParamBuf[index].m_Type == 0) + delete m_ParamBuf[index].m_pObject; + index++; if (index == kParamBufSize) { index = 0; @@ -531,7 +525,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() { m_pSyntax->GetWordSize()); if (bsKeyword != "ID") { m_pSyntax->SetPos(savePos); - pDict->Release(); + delete pDict; return; } } @@ -540,8 +534,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() { } CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, m_pSyntax->GetWordSize() - 1); - std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( - m_pSyntax->ReadNextObject(false, 0)); + std::unique_ptr<CPDF_Object> pObj(m_pSyntax->ReadNextObject(false, 0)); if (!key.IsEmpty()) { uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; if (dwObjNum) @@ -566,7 +559,8 @@ void CPDF_StreamContentParser::Handle_BeginImage() { } } pDict->SetNameFor("Subtype", "Image"); - UniqueStream pStream(m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj)); + std::unique_ptr<CPDF_Stream> pStream( + m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj)); bool bGaveDictAway = !!pStream; while (1) { CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); @@ -583,7 +577,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() { } CPDF_ImageObject* pImgObj = AddImage(std::move(pStream)); if (!pImgObj && !bGaveDictAway) - pDict->Release(); + delete pDict; } void CPDF_StreamContentParser::Handle_BeginMarkedContent() { @@ -669,10 +663,10 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() { type = pXObject->GetDict()->GetStringFor("Subtype"); if (type == "Image") { - CPDF_ImageObject* pObj = - pXObject->IsInline() - ? AddImage(UniqueStream(ToStream(pXObject->Clone()))) - : AddImage(pXObject->GetObjNum()); + CPDF_ImageObject* pObj = pXObject->IsInline() + ? AddImage(std::unique_ptr<CPDF_Stream>( + ToStream(pXObject->Clone()))) + : AddImage(pXObject->GetObjNum()); m_LastImageName = name; m_pLastImage = pObj->GetImage(); @@ -704,7 +698,8 @@ void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) { m_pObjectHolder->GetPageObjectList()->push_back(std::move(pFormObj)); } -CPDF_ImageObject* CPDF_StreamContentParser::AddImage(UniqueStream pStream) { +CPDF_ImageObject* CPDF_StreamContentParser::AddImage( + std::unique_ptr<CPDF_Stream> pStream) { if (!pStream) return nullptr; diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.h b/core/fpdfapi/page/cpdf_streamcontentparser.h index 58008da96a..1ed2aaa4de 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.h +++ b/core/fpdfapi/page/cpdf_streamcontentparser.h @@ -97,7 +97,7 @@ class CPDF_StreamContentParser { void AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag); void AddPathRect(FX_FLOAT x, FX_FLOAT y, FX_FLOAT w, FX_FLOAT h); void AddPathObject(int FillType, bool bStroke); - CPDF_ImageObject* AddImage(UniqueStream pStream); + CPDF_ImageObject* AddImage(std::unique_ptr<CPDF_Stream> pStream); CPDF_ImageObject* AddImage(uint32_t streamObjNum); CPDF_ImageObject* AddImage(CPDF_Image* pImage); diff --git a/core/fpdfapi/page/fpdf_page_parser_old.cpp b/core/fpdfapi/page/fpdf_page_parser_old.cpp index 0d1db43825..51ffc11b03 100644 --- a/core/fpdfapi/page/fpdf_page_parser_old.cpp +++ b/core/fpdfapi/page/fpdf_page_parser_old.cpp @@ -138,9 +138,7 @@ CPDF_StreamParser::CPDF_StreamParser( m_pPool(pPool) {} CPDF_StreamParser::~CPDF_StreamParser() { - if (m_pLastObj) { - m_pLastObj->Release(); - } + delete m_pLastObj; } CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc, @@ -252,10 +250,8 @@ CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc, } CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() { - if (m_pLastObj) { - m_pLastObj->Release(); - m_pLastObj = nullptr; - } + delete m_pLastObj; + m_pLastObj = nullptr; m_WordSize = 0; bool bIsNumber = true; @@ -374,7 +370,7 @@ CPDF_Object* CPDF_StreamParser::ReadNextObject(bool bAllowNestedArray, break; if (!m_WordSize || m_WordBuffer[0] != '/') { - pDict->Release(); + delete pDict; return nullptr; } @@ -382,12 +378,12 @@ CPDF_Object* CPDF_StreamParser::ReadNextObject(bool bAllowNestedArray, PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)); CPDF_Object* pObj = ReadNextObject(true, 0); if (!pObj) { - pDict->Release(); + delete pDict; return nullptr; } if (key.IsEmpty()) - pObj->Release(); + delete pObj; else pDict->SetFor(key, pObj); } |