summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-11-16 12:26:06 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-16 12:26:06 -0800
commit8a3aa459fc5284f51bcd7e98e95bf6214f47bb67 (patch)
tree13fb383936d679aded19054f4e7a0387dd52de76 /core/fpdfapi/parser
parent14a60c50b10de1d9e4edd3629ea210a816940a75 (diff)
downloadpdfium-8a3aa459fc5284f51bcd7e98e95bf6214f47bb67.tar.xz
Make CPDF_Array take unique_ptrs
BUG= Review-Url: https://codereview.chromium.org/2498223005
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r--core/fpdfapi/parser/cpdf_array.cpp82
-rw-r--r--core/fpdfapi/parser/cpdf_array.h39
-rw-r--r--core/fpdfapi/parser/cpdf_array_unittest.cpp32
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp8
-rw-r--r--core/fpdfapi/parser/cpdf_dictionary.cpp20
-rw-r--r--core/fpdfapi/parser/cpdf_document.cpp54
-rw-r--r--core/fpdfapi/parser/cpdf_document_unittest.cpp38
-rw-r--r--core/fpdfapi/parser/cpdf_object_unittest.cpp129
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.cpp4
9 files changed, 194 insertions, 212 deletions
diff --git a/core/fpdfapi/parser/cpdf_array.cpp b/core/fpdfapi/parser/cpdf_array.cpp
index f8ec46acc9..3edb3bb0ef 100644
--- a/core/fpdfapi/parser/cpdf_array.cpp
+++ b/core/fpdfapi/parser/cpdf_array.cpp
@@ -19,12 +19,11 @@
CPDF_Array::CPDF_Array() {}
CPDF_Array::~CPDF_Array() {
- // Mark the object as deleted so that it will not be deleted again
- // in case of cyclic references.
+ // Break cycles for cyclic references.
m_ObjNum = kInvalidObjNum;
for (auto& it : m_Objects) {
- if (it && it->GetObjNum() != kInvalidObjNum)
- delete it;
+ if (it && it->GetObjNum() == kInvalidObjNum)
+ it.release();
}
}
@@ -53,11 +52,9 @@ std::unique_ptr<CPDF_Object> CPDF_Array::CloneNonCyclic(
std::set<const CPDF_Object*>* pVisited) const {
pVisited->insert(this);
auto pCopy = pdfium::MakeUnique<CPDF_Array>();
- for (CPDF_Object* value : m_Objects) {
- if (!pdfium::ContainsKey(*pVisited, value)) {
- pCopy->m_Objects.push_back(
- value->CloneNonCyclic(bDirect, pVisited).release());
- }
+ for (const auto& pValue : m_Objects) {
+ if (!pdfium::ContainsKey(*pVisited, pValue.get()))
+ pCopy->m_Objects.push_back(pValue->CloneNonCyclic(bDirect, pVisited));
}
return std::move(pCopy);
}
@@ -87,7 +84,7 @@ CFX_Matrix CPDF_Array::GetMatrix() {
CPDF_Object* CPDF_Array::GetObjectAt(size_t i) const {
if (i >= m_Objects.size())
return nullptr;
- return m_Objects[i];
+ return m_Objects[i].get();
}
CPDF_Object* CPDF_Array::GetDirectObjectAt(size_t i) const {
@@ -140,9 +137,6 @@ void CPDF_Array::RemoveAt(size_t i, size_t nCount) {
if (nCount <= 0 || nCount > m_Objects.size() - i)
return;
- for (size_t j = 0; j < nCount; ++j)
- delete m_Objects[i + j];
-
m_Objects.erase(m_Objects.begin() + i, m_Objects.begin() + i + nCount);
}
@@ -151,67 +145,45 @@ void CPDF_Array::ConvertToIndirectObjectAt(size_t i,
if (i >= m_Objects.size())
return;
- CPDF_Object* pObj = m_Objects[i];
- if (!pObj || pObj->IsReference())
+ if (!m_Objects[i] || m_Objects[i]->IsReference())
return;
- CPDF_Object* pNew = pHolder->AddIndirectObject(pdfium::WrapUnique(pObj));
- m_Objects[i] = new CPDF_Reference(pHolder, pNew->GetObjNum());
+ CPDF_Object* pNew = pHolder->AddIndirectObject(std::move(m_Objects[i]));
+ m_Objects[i] = pdfium::MakeUnique<CPDF_Reference>(pHolder, pNew->GetObjNum());
}
-void CPDF_Array::SetAt(size_t i, CPDF_Object* pObj) {
+CPDF_Object* CPDF_Array::SetAt(size_t i, std::unique_ptr<CPDF_Object> pObj) {
ASSERT(IsArray());
- CHECK(!pObj || pObj->IsInline());
+ ASSERT(!pObj || pObj->IsInline());
if (i >= m_Objects.size()) {
ASSERT(false);
- return;
+ return nullptr;
}
- delete m_Objects[i];
- m_Objects[i] = pObj;
+ CPDF_Object* pRet = pObj.get();
+ m_Objects[i] = std::move(pObj);
+ return pRet;
}
-void CPDF_Array::InsertAt(size_t index, CPDF_Object* pObj) {
+CPDF_Object* CPDF_Array::InsertAt(size_t index,
+ std::unique_ptr<CPDF_Object> pObj) {
ASSERT(IsArray());
CHECK(!pObj || pObj->IsInline());
+ CPDF_Object* pRet = pObj.get();
if (index >= m_Objects.size()) {
// Allocate space first.
- m_Objects.resize(index + 1, nullptr);
- m_Objects[index] = pObj;
+ m_Objects.resize(index + 1);
+ m_Objects[index] = std::move(pObj);
} else {
// Directly insert.
- m_Objects.insert(m_Objects.begin() + index, pObj);
+ m_Objects.insert(m_Objects.begin() + index, std::move(pObj));
}
+ return pRet;
}
-void CPDF_Array::Add(CPDF_Object* pObj) {
+CPDF_Object* CPDF_Array::Add(std::unique_ptr<CPDF_Object> pObj) {
ASSERT(IsArray());
CHECK(!pObj || pObj->IsInline());
- m_Objects.push_back(pObj);
-}
-
-void CPDF_Array::AddName(const CFX_ByteString& str) {
- Add(new CPDF_Name(str));
-}
-
-void CPDF_Array::AddString(const CFX_ByteString& str) {
- Add(new CPDF_String(str, false));
-}
-
-void CPDF_Array::AddInteger(int i) {
- Add(new CPDF_Number(i));
-}
-
-void CPDF_Array::AddNumber(FX_FLOAT f) {
- Add(new CPDF_Number(f));
-}
-
-void CPDF_Array::AddReference(CPDF_IndirectObjectHolder* pDoc,
- uint32_t objnum) {
- Add(new CPDF_Reference(pDoc, objnum));
-}
-
-void CPDF_Array::AddReference(CPDF_IndirectObjectHolder* pDoc,
- CPDF_Object* pObj) {
- ASSERT(!pObj->IsInline());
- Add(new CPDF_Reference(pDoc, pObj->GetObjNum()));
+ CPDF_Object* pRet = pObj.get();
+ m_Objects.push_back(std::move(pObj));
+ return pRet;
}
diff --git a/core/fpdfapi/parser/cpdf_array.h b/core/fpdfapi/parser/cpdf_array.h
index bf4b8a626d..b7aec7e190 100644
--- a/core/fpdfapi/parser/cpdf_array.h
+++ b/core/fpdfapi/parser/cpdf_array.h
@@ -7,6 +7,7 @@
#ifndef CORE_FPDFAPI_PARSER_CPDF_ARRAY_H_
#define CORE_FPDFAPI_PARSER_CPDF_ARRAY_H_
+#include <memory>
#include <set>
#include <vector>
@@ -14,11 +15,12 @@
#include "core/fpdfapi/parser/cpdf_object.h"
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_coordinates.h"
+#include "third_party/base/ptr_util.h"
class CPDF_Array : public CPDF_Object {
public:
- using iterator = std::vector<CPDF_Object*>::iterator;
- using const_iterator = std::vector<CPDF_Object*>::const_iterator;
+ using const_iterator =
+ std::vector<std::unique_ptr<CPDF_Object>>::const_iterator;
CPDF_Array();
~CPDF_Array() override;
@@ -44,21 +46,28 @@ class CPDF_Array : public CPDF_Object {
CFX_Matrix GetMatrix();
CFX_FloatRect GetRect();
- void SetAt(size_t index, CPDF_Object* pObj);
- void InsertAt(size_t index, CPDF_Object* pObj);
+ // Takes ownership of |pObj|, returns unowned pointer to it.
+ CPDF_Object* Add(std::unique_ptr<CPDF_Object> pObj);
+ CPDF_Object* SetAt(size_t index, std::unique_ptr<CPDF_Object> pObj);
+ CPDF_Object* InsertAt(size_t index, std::unique_ptr<CPDF_Object> pObj);
+
+ // Creates object owned by the array, returns unowned pointer to it.
+ template <typename T, typename... Args>
+ T* AddNew(Args... args) {
+ return static_cast<T*>(Add(pdfium::MakeUnique<T>(args...)));
+ }
+ template <typename T, typename... Args>
+ T* SetNewAt(size_t index, Args... args) {
+ return static_cast<T*>(SetAt(index, pdfium::MakeUnique<T>(args...)));
+ }
+ template <typename T, typename... Args>
+ T* InsertNewAt(size_t index, Args... args) {
+ return static_cast<T*>(InsertAt(index, pdfium::MakeUnique<T>(args...)));
+ }
+
void RemoveAt(size_t index, size_t nCount = 1);
void ConvertToIndirectObjectAt(size_t index, CPDF_IndirectObjectHolder* pDoc);
- void Add(CPDF_Object* pObj);
- void AddNumber(FX_FLOAT f);
- void AddInteger(int i);
- void AddString(const CFX_ByteString& str);
- void AddName(const CFX_ByteString& str);
- void AddReference(CPDF_IndirectObjectHolder* pDoc, uint32_t objnum);
- void AddReference(CPDF_IndirectObjectHolder* pDoc, CPDF_Object* pObj);
-
- iterator begin() { return m_Objects.begin(); }
- iterator end() { return m_Objects.end(); }
const_iterator begin() const { return m_Objects.begin(); }
const_iterator end() const { return m_Objects.end(); }
@@ -67,7 +76,7 @@ class CPDF_Array : public CPDF_Object {
bool bDirect,
std::set<const CPDF_Object*>* pVisited) const override;
- std::vector<CPDF_Object*> m_Objects;
+ std::vector<std::unique_ptr<CPDF_Object>> m_Objects;
};
inline CPDF_Array* ToArray(CPDF_Object* obj) {
diff --git a/core/fpdfapi/parser/cpdf_array_unittest.cpp b/core/fpdfapi/parser/cpdf_array_unittest.cpp
index acb1bd89a9..866e961351 100644
--- a/core/fpdfapi/parser/cpdf_array_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_array_unittest.cpp
@@ -16,7 +16,7 @@ TEST(cpdf_array, RemoveAt) {
int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
for (size_t i = 0; i < FX_ArraySize(elems); ++i)
- arr->AddInteger(elems[i]);
+ arr->AddNew<CPDF_Number>(elems[i]);
arr->RemoveAt(3, 3);
int expected[] = {1, 2, 3, 7, 8, 9, 10};
EXPECT_EQ(FX_ArraySize(expected), arr->GetCount());
@@ -33,7 +33,7 @@ TEST(cpdf_array, RemoveAt) {
int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
for (size_t i = 0; i < FX_ArraySize(elems); ++i)
- arr->AddInteger(elems[i]);
+ arr->AddNew<CPDF_Number>(elems[i]);
arr->RemoveAt(8, 5);
EXPECT_EQ(FX_ArraySize(elems), arr->GetCount());
for (size_t i = 0; i < FX_ArraySize(elems); ++i)
@@ -48,15 +48,15 @@ TEST(cpdf_array, RemoveAt) {
TEST(cpdf_array, InsertAt) {
{
int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < FX_ArraySize(elems); ++i)
- arr->InsertAt(i, new CPDF_Number(elems[i]));
+ arr->InsertNewAt<CPDF_Number>(i, elems[i]);
EXPECT_EQ(FX_ArraySize(elems), arr->GetCount());
for (size_t i = 0; i < FX_ArraySize(elems); ++i)
EXPECT_EQ(elems[i], arr->GetIntegerAt(i));
- arr->InsertAt(3, new CPDF_Number(33));
- arr->InsertAt(6, new CPDF_Number(55));
- arr->InsertAt(12, new CPDF_Number(12));
+ arr->InsertNewAt<CPDF_Number>(3, 33);
+ arr->InsertNewAt<CPDF_Number>(6, 55);
+ arr->InsertNewAt<CPDF_Number>(12, 12);
int expected[] = {1, 2, 3, 33, 4, 5, 55, 6, 7, 8, 9, 10, 12};
EXPECT_EQ(FX_ArraySize(expected), arr->GetCount());
for (size_t i = 0; i < FX_ArraySize(expected); ++i)
@@ -67,10 +67,10 @@ TEST(cpdf_array, InsertAt) {
// an element is inserted at that position while other unfilled
// positions have nullptr.
int elems[] = {1, 2};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < FX_ArraySize(elems); ++i)
- arr->InsertAt(i, new CPDF_Number(elems[i]));
- arr->InsertAt(10, new CPDF_Number(10));
+ arr->InsertNewAt<CPDF_Number>(i, elems[i]);
+ arr->InsertNewAt<CPDF_Number>(10, 10);
EXPECT_EQ(11u, arr->GetCount());
for (size_t i = 0; i < FX_ArraySize(elems); ++i)
EXPECT_EQ(elems[i], arr->GetIntegerAt(i));
@@ -84,9 +84,9 @@ TEST(cpdf_array, Clone) {
{
// Basic case.
int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < FX_ArraySize(elems); ++i)
- arr->InsertAt(i, new CPDF_Number(elems[i]));
+ arr->InsertNewAt<CPDF_Number>(i, elems[i]);
std::unique_ptr<CPDF_Array> arr2 = ToArray(arr->Clone());
EXPECT_EQ(arr->GetCount(), arr2->GetCount());
for (size_t i = 0; i < FX_ArraySize(elems); ++i) {
@@ -106,16 +106,16 @@ TEST(cpdf_array, Clone) {
std::unique_ptr<CPDF_IndirectObjectHolder> obj_holder(
new CPDF_IndirectObjectHolder());
for (size_t i = 0; i < kNumOfRows; ++i) {
- CPDF_Array* arr_elem = new CPDF_Array;
+ auto arr_elem = pdfium::MakeUnique<CPDF_Array>();
for (size_t j = 0; j < kNumOfRowElems; ++j) {
std::unique_ptr<CPDF_Number> obj(new CPDF_Number(elems[i][j]));
// Starts object number from 1.
int obj_num = i * kNumOfRowElems + j + 1;
obj_holder->ReplaceIndirectObjectIfHigherGeneration(obj_num,
std::move(obj));
- arr_elem->InsertAt(j, new CPDF_Reference(obj_holder.get(), obj_num));
+ arr_elem->InsertNewAt<CPDF_Reference>(j, obj_holder.get(), obj_num);
}
- arr->InsertAt(i, arr_elem);
+ arr->InsertAt(i, std::move(arr_elem));
}
ASSERT_EQ(kNumOfRows, arr->GetCount());
// Not dereferencing reference objects means just creating new references
@@ -169,7 +169,7 @@ TEST(cpdf_array, Iterator) {
0, 7895330, -12564334, 10000, -100000};
std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
for (size_t i = 0; i < FX_ArraySize(elems); ++i)
- arr->InsertAt(i, new CPDF_Number(elems[i]));
+ arr->InsertNewAt<CPDF_Number>(i, elems[i]);
size_t index = 0;
for (const auto& it : *arr)
EXPECT_EQ(elems[index++], it->AsNumber()->GetInteger());
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index c1d17a98ed..6af2da6ff0 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -470,15 +470,13 @@ bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) {
CPDF_Array* pArray = ToArray(pObj.get());
if (pArray) {
- for (CPDF_Object* pArrayObj : *pArray) {
- if (CPDF_Reference* pRef = ToReference(pArrayObj))
+ for (const auto& pArrayObj : *pArray) {
+ if (CPDF_Reference* pRef = ToReference(pArrayObj.get()))
UnavailObjList.Add(pRef->GetRefObjNum());
}
}
-
- if (!pObj->IsDictionary()) {
+ if (!pObj->IsDictionary())
continue;
- }
CFX_ByteString type = pObj->GetDict()->GetStringFor("Type");
if (type == "Pages") {
diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp
index 02cdfa37da..f28507e2e4 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.cpp
+++ b/core/fpdfapi/parser/cpdf_dictionary.cpp
@@ -270,22 +270,22 @@ void CPDF_Dictionary::SetBooleanFor(const CFX_ByteString& key, bool bValue) {
void CPDF_Dictionary::SetRectFor(const CFX_ByteString& key,
const CFX_FloatRect& rect) {
CPDF_Array* pArray = new CPDF_Array;
- pArray->AddNumber(rect.left);
- pArray->AddNumber(rect.bottom);
- pArray->AddNumber(rect.right);
- pArray->AddNumber(rect.top);
+ pArray->AddNew<CPDF_Number>(rect.left);
+ pArray->AddNew<CPDF_Number>(rect.bottom);
+ pArray->AddNew<CPDF_Number>(rect.right);
+ pArray->AddNew<CPDF_Number>(rect.top);
SetFor(key, pArray);
}
void CPDF_Dictionary::SetMatrixFor(const CFX_ByteString& key,
const CFX_Matrix& matrix) {
CPDF_Array* pArray = new CPDF_Array;
- pArray->AddNumber(matrix.a);
- pArray->AddNumber(matrix.b);
- pArray->AddNumber(matrix.c);
- pArray->AddNumber(matrix.d);
- pArray->AddNumber(matrix.e);
- pArray->AddNumber(matrix.f);
+ pArray->AddNew<CPDF_Number>(matrix.a);
+ pArray->AddNew<CPDF_Number>(matrix.b);
+ pArray->AddNew<CPDF_Number>(matrix.c);
+ pArray->AddNew<CPDF_Number>(matrix.d);
+ pArray->AddNew<CPDF_Number>(matrix.e);
+ pArray->AddNew<CPDF_Number>(matrix.f);
SetFor(key, pArray);
}
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index 35c18997b9..83123b27c6 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -18,6 +18,7 @@
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_linearized_header.h"
+#include "core/fpdfapi/parser/cpdf_name.h"
#include "core/fpdfapi/parser/cpdf_number.h"
#include "core/fpdfapi/parser/cpdf_parser.h"
#include "core/fpdfapi/parser/cpdf_reference.h"
@@ -194,13 +195,12 @@ void InsertWidthArrayImpl(int* widths, int size, CPDF_Array* pWidthArray) {
}
if (i == size) {
int first = pWidthArray->GetIntegerAt(pWidthArray->GetCount() - 1);
- pWidthArray->AddInteger(first + size - 1);
- pWidthArray->AddInteger(*widths);
+ pWidthArray->AddNew<CPDF_Number>(first + size - 1);
+ pWidthArray->AddNew<CPDF_Number>(*widths);
} else {
- CPDF_Array* pWidthArray1 = new CPDF_Array;
- pWidthArray->Add(pWidthArray1);
+ CPDF_Array* pWidthArray1 = pWidthArray->AddNew<CPDF_Array>();
for (i = 0; i < size; i++)
- pWidthArray1->AddInteger(widths[i]);
+ pWidthArray1->AddNew<CPDF_Number>(widths[i]);
}
FX_Free(widths);
}
@@ -688,7 +688,7 @@ bool CPDF_Document::InsertDeletePDFPage(CPDF_Dictionary* pPages,
continue;
}
if (bInsert) {
- pKidList->InsertAt(i, new CPDF_Reference(this, pPageDict->GetObjNum()));
+ pKidList->InsertNewAt<CPDF_Reference>(i, this, pPageDict->GetObjNum());
pPageDict->SetReferenceFor("Parent", this, pPages->GetObjNum());
} else {
pKidList->RemoveAt(i);
@@ -733,7 +733,7 @@ bool CPDF_Document::InsertNewPage(int iPage, CPDF_Dictionary* pPageDict) {
pPagesList = new CPDF_Array;
pPages->SetFor("Kids", pPagesList);
}
- pPagesList->Add(new CPDF_Reference(this, pPageDict->GetObjNum()));
+ pPagesList->AddNew<CPDF_Reference>(this, pPageDict->GetObjNum());
pPages->SetIntegerFor("Count", nPages + 1);
pPageDict->SetReferenceFor("Parent", this, pPages->GetObjNum());
ResetTraversal();
@@ -785,12 +785,12 @@ size_t CPDF_Document::CalculateEncodingDict(int charset,
pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding");
CPDF_Array* pArray = new CPDF_Array;
- pArray->AddInteger(128);
+ pArray->AddNew<CPDF_Number>(128);
const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes;
for (int j = 0; j < 128; j++) {
CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]);
- pArray->AddName(name.IsEmpty() ? ".notdef" : name);
+ pArray->AddNew<CPDF_Name>(name.IsEmpty() ? ".notdef" : name);
}
pEncodingDict->SetFor("Differences", pArray);
pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict);
@@ -813,36 +813,36 @@ CPDF_Dictionary* CPDF_Document::ProcessbCJK(
cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H";
ordering = "CNS1";
supplement = 4;
- pWidthArray->AddInteger(1);
+ pWidthArray->AddNew<CPDF_Number>(1);
Insert(0x20, 0x7e, pWidthArray);
break;
case FXFONT_GB2312_CHARSET:
cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H";
ordering = "GB1";
supplement = 2;
- pWidthArray->AddInteger(7716);
+ pWidthArray->AddNew<CPDF_Number>(7716);
Insert(0x20, 0x20, pWidthArray);
- pWidthArray->AddInteger(814);
+ pWidthArray->AddNew<CPDF_Number>(814);
Insert(0x21, 0x7e, pWidthArray);
break;
case FXFONT_HANGUL_CHARSET:
cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H";
ordering = "Korea1";
supplement = 2;
- pWidthArray->AddInteger(1);
+ pWidthArray->AddNew<CPDF_Number>(1);
Insert(0x20, 0x7e, pWidthArray);
break;
case FXFONT_SHIFTJIS_CHARSET:
cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H";
ordering = "Japan1";
supplement = 5;
- pWidthArray->AddInteger(231);
+ pWidthArray->AddNew<CPDF_Number>(231);
Insert(0x20, 0x7d, pWidthArray);
- pWidthArray->AddInteger(326);
+ pWidthArray->AddNew<CPDF_Number>(326);
Insert(0xa0, 0xa0, pWidthArray);
- pWidthArray->AddInteger(327);
+ pWidthArray->AddNew<CPDF_Number>(327);
Insert(0xa1, 0xdf, pWidthArray);
- pWidthArray->AddInteger(631);
+ pWidthArray->AddNew<CPDF_Number>(631);
Insert(0x7e, 0x7e, pWidthArray);
break;
}
@@ -860,7 +860,7 @@ CPDF_Dictionary* CPDF_Document::ProcessbCJK(
pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo);
CPDF_Array* pArray = new CPDF_Array;
pBaseDict->SetFor("DescendantFonts", pArray);
- pArray->AddReference(this, pFontDict->GetObjNum());
+ pArray->AddNew<CPDF_Reference>(this, pFontDict->GetObjNum());
return pFontDict;
}
@@ -888,7 +888,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) {
for (int charcode = 32; charcode < 128; charcode++) {
int glyph_index = pEncoding->GlyphFromCharCode(charcode);
int char_width = pFont->GetGlyphWidth(glyph_index);
- pWidths->AddInteger(char_width);
+ pWidths->AddNew<CPDF_Number>(char_width);
}
if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_DEFAULT_CHARSET ||
charset == FXFONT_SYMBOL_CHARSET) {
@@ -896,7 +896,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) {
for (int charcode = 128; charcode <= 255; charcode++) {
int glyph_index = pEncoding->GlyphFromCharCode(charcode);
int char_width = pFont->GetGlyphWidth(glyph_index);
- pWidths->AddInteger(char_width);
+ pWidths->AddNew<CPDF_Number>(char_width);
}
} else {
size_t i = CalculateEncodingDict(charset, pBaseDict);
@@ -905,7 +905,7 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) {
for (int j = 0; j < 128; j++) {
int glyph_index = pEncoding->GlyphFromCharCode(pUnicodes[j]);
int char_width = pFont->GetGlyphWidth(glyph_index);
- pWidths->AddInteger(char_width);
+ pWidths->AddNew<CPDF_Number>(char_width);
}
}
}
@@ -924,10 +924,10 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) {
FX_RECT bbox;
pFont->GetBBox(bbox);
CPDF_Array* pBBox = new CPDF_Array;
- pBBox->AddInteger(bbox.left);
- pBBox->AddInteger(bbox.bottom);
- pBBox->AddInteger(bbox.right);
- pBBox->AddInteger(bbox.top);
+ pBBox->AddNew<CPDF_Number>(bbox.left);
+ pBBox->AddNew<CPDF_Number>(bbox.bottom);
+ pBBox->AddNew<CPDF_Number>(bbox.right);
+ pBBox->AddNew<CPDF_Number>(bbox.top);
int32_t nStemV = 0;
if (pFont->GetSubstFont()) {
nStemV = pFont->GetSubstFont()->m_Weight / 5;
@@ -1023,7 +1023,7 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont,
GetCharWidth(hDC, 32, 255, char_widths);
CPDF_Array* pWidths = new CPDF_Array;
for (size_t i = 0; i < 224; i++)
- pWidths->AddInteger(char_widths[i]);
+ pWidths->AddNew<CPDF_Number>(char_widths[i]);
ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM,
pLogFont->lfItalic != 0, basefont, pWidths);
} else {
@@ -1035,7 +1035,7 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont,
}
CPDF_Array* pBBox = new CPDF_Array;
for (int i = 0; i < 4; i++)
- pBBox->AddInteger(bbox[i]);
+ pBBox->AddNew<CPDF_Number>(bbox[i]);
std::unique_ptr<CPDF_Dictionary> pFontDesc =
CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend,
pBBox, pLogFont->lfWeight / 5);
diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp
index 048a9fead2..df90875c3c 100644
--- a/core/fpdfapi/parser/cpdf_document_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp
@@ -11,6 +11,7 @@
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_linearized_header.h"
#include "core/fpdfapi/parser/cpdf_parser.h"
+#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fxcrt/fx_memory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/base/ptr_util.h"
@@ -42,31 +43,38 @@ class CPDF_TestDocumentForPages : public CPDF_Document {
CPDF_TestDocumentForPages() : CPDF_Document(nullptr) {
// Set up test
auto zeroToTwo = pdfium::MakeUnique<CPDF_Array>();
- zeroToTwo->AddReference(this, AddIndirectObject(CreateNumberedPage(0)));
- zeroToTwo->AddReference(this, AddIndirectObject(CreateNumberedPage(1)));
- zeroToTwo->AddReference(this, AddIndirectObject(CreateNumberedPage(2)));
+ zeroToTwo->AddNew<CPDF_Reference>(
+ this, AddIndirectObject(CreateNumberedPage(0))->GetObjNum());
+ zeroToTwo->AddNew<CPDF_Reference>(
+ this, AddIndirectObject(CreateNumberedPage(1))->GetObjNum());
+ zeroToTwo->AddNew<CPDF_Reference>(
+ this, AddIndirectObject(CreateNumberedPage(2))->GetObjNum());
CPDF_Dictionary* branch1 =
CreatePageTreeNode(std::move(zeroToTwo), this, 3);
auto zeroToThree = pdfium::MakeUnique<CPDF_Array>();
- zeroToThree->AddReference(this, branch1->GetObjNum());
- zeroToThree->AddReference(this, AddIndirectObject(CreateNumberedPage(3)));
+ zeroToThree->AddNew<CPDF_Reference>(this, branch1->GetObjNum());
+ zeroToThree->AddNew<CPDF_Reference>(
+ this, AddIndirectObject(CreateNumberedPage(3))->GetObjNum());
CPDF_Dictionary* branch2 =
CreatePageTreeNode(std::move(zeroToThree), this, 4);
auto fourFive = pdfium::MakeUnique<CPDF_Array>();
- fourFive->AddReference(this, AddIndirectObject(CreateNumberedPage(4)));
- fourFive->AddReference(this, AddIndirectObject(CreateNumberedPage(5)));
+ fourFive->AddNew<CPDF_Reference>(
+ this, AddIndirectObject(CreateNumberedPage(4))->GetObjNum());
+ fourFive->AddNew<CPDF_Reference>(
+ this, AddIndirectObject(CreateNumberedPage(5))->GetObjNum());
CPDF_Dictionary* branch3 = CreatePageTreeNode(std::move(fourFive), this, 2);
auto justSix = pdfium::MakeUnique<CPDF_Array>();
- justSix->AddReference(this, AddIndirectObject(CreateNumberedPage(6)));
+ justSix->AddNew<CPDF_Reference>(
+ this, AddIndirectObject(CreateNumberedPage(6))->GetObjNum());
CPDF_Dictionary* branch4 = CreatePageTreeNode(std::move(justSix), this, 1);
auto allPages = pdfium::MakeUnique<CPDF_Array>();
- allPages->AddReference(this, branch2);
- allPages->AddReference(this, branch3);
- allPages->AddReference(this, branch4);
+ allPages->AddNew<CPDF_Reference>(this, branch2->GetObjNum());
+ allPages->AddNew<CPDF_Reference>(this, branch3->GetObjNum());
+ allPages->AddNew<CPDF_Reference>(this, branch4->GetObjNum());
CPDF_Dictionary* pagesDict =
CreatePageTreeNode(std::move(allPages), this, 7);
@@ -85,10 +93,12 @@ class CPDF_TestDocumentWithPageWithoutPageNum : public CPDF_Document {
CPDF_TestDocumentWithPageWithoutPageNum() : CPDF_Document(nullptr) {
// Set up test
auto allPages = pdfium::MakeUnique<CPDF_Array>();
- allPages->AddReference(this, AddIndirectObject(CreateNumberedPage(0)));
- allPages->AddReference(this, AddIndirectObject(CreateNumberedPage(1)));
+ allPages->AddNew<CPDF_Reference>(
+ this, AddIndirectObject(CreateNumberedPage(0))->GetObjNum());
+ allPages->AddNew<CPDF_Reference>(
+ this, AddIndirectObject(CreateNumberedPage(1))->GetObjNum());
// Page without pageNum.
- allPages->Add(CreateNumberedPage(2).release());
+ allPages->Add(CreateNumberedPage(2));
CPDF_Dictionary* pagesDict =
CreatePageTreeNode(std::move(allPages), this, 3);
m_pOwnedRootDict.reset(new CPDF_Dictionary());
diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp
index 4145f248fa..c341284602 100644
--- a/core/fpdfapi/parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp
@@ -59,8 +59,8 @@ class PDFObjectsTest : public testing::Test {
CPDF_Name* name_obj = new CPDF_Name("space");
// Array object.
m_ArrayObj = new CPDF_Array;
- m_ArrayObj->InsertAt(0, new CPDF_Number(8902));
- m_ArrayObj->InsertAt(1, new CPDF_Name("address"));
+ m_ArrayObj->InsertNewAt<CPDF_Number>(0, 8902);
+ m_ArrayObj->InsertNewAt<CPDF_Name>(1, "address");
// Dictionary object.
m_DictObj = new CPDF_Dictionary();
m_DictObj->SetFor("bool", new CPDF_Boolean(false));
@@ -388,11 +388,11 @@ TEST(PDFArrayTest, GetMatrix) {
{2.3f, 4.05f, 3, -2, -3, 0.0f},
{0.05f, 0.1f, 0.56f, 0.67f, 1.34f, 99.9f}};
for (size_t i = 0; i < FX_ArraySize(elems); ++i) {
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
CFX_Matrix matrix(elems[i][0], elems[i][1], elems[i][2], elems[i][3],
elems[i][4], elems[i][5]);
for (size_t j = 0; j < 6; ++j)
- arr->AddNumber(elems[i][j]);
+ arr->AddNew<CPDF_Number>(elems[i][j]);
CFX_Matrix arr_matrix = arr->GetMatrix();
EXPECT_EQ(matrix.GetA(), arr_matrix.GetA());
EXPECT_EQ(matrix.GetB(), arr_matrix.GetB());
@@ -409,10 +409,10 @@ TEST(PDFArrayTest, GetRect) {
{2.3f, 4.05f, -3, 0.0f},
{0.05f, 0.1f, 1.34f, 99.9f}};
for (size_t i = 0; i < FX_ArraySize(elems); ++i) {
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
CFX_FloatRect rect(elems[i]);
for (size_t j = 0; j < 4; ++j)
- arr->AddNumber(elems[i][j]);
+ arr->AddNew<CPDF_Number>(elems[i][j]);
CFX_FloatRect arr_rect = arr->GetRect();
EXPECT_EQ(rect.left, arr_rect.left);
EXPECT_EQ(rect.right, arr_rect.right);
@@ -425,9 +425,9 @@ TEST(PDFArrayTest, GetTypeAt) {
{
// Boolean array.
const bool vals[] = {true, false, false, true, true};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < FX_ArraySize(vals); ++i)
- arr->InsertAt(i, new CPDF_Boolean(vals[i]));
+ arr->InsertNewAt<CPDF_Boolean>(i, vals[i]);
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
TestArrayAccessors(arr.get(), i, // Array and index.
vals[i] ? "true" : "false", // String value.
@@ -442,9 +442,9 @@ TEST(PDFArrayTest, GetTypeAt) {
{
// Integer array.
const int vals[] = {10, 0, -345, 2089345456, -1000000000, 567, 93658767};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < FX_ArraySize(vals); ++i)
- arr->InsertAt(i, new CPDF_Number(vals[i]));
+ arr->InsertNewAt<CPDF_Number>(i, vals[i]);
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
char buf[33];
TestArrayAccessors(arr.get(), i, // Array and index.
@@ -463,10 +463,9 @@ TEST(PDFArrayTest, GetTypeAt) {
897.34f, -2.5f, -1.0f, -345.0f, -0.0f};
const char* const expected_str[] = {
"0", "0", "10", "10", "0.0345", "897.34", "-2.5", "-1", "-345", "0"};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
- for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
- arr->InsertAt(i, new CPDF_Number(vals[i]));
- }
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
+ for (size_t i = 0; i < FX_ArraySize(vals); ++i)
+ arr->InsertNewAt<CPDF_Number>(i, vals[i]);
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
TestArrayAccessors(arr.get(), i, // Array and index.
expected_str[i], // String value.
@@ -485,8 +484,8 @@ TEST(PDFArrayTest, GetTypeAt) {
std::unique_ptr<CPDF_Array> string_array(new CPDF_Array);
std::unique_ptr<CPDF_Array> name_array(new CPDF_Array);
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
- string_array->InsertAt(i, new CPDF_String(vals[i], false));
- name_array->InsertAt(i, new CPDF_Name(vals[i]));
+ string_array->InsertNewAt<CPDF_String>(i, vals[i], false);
+ name_array->InsertNewAt<CPDF_Name>(i, vals[i]);
}
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
TestArrayAccessors(string_array.get(), i, // Array and index.
@@ -509,9 +508,9 @@ TEST(PDFArrayTest, GetTypeAt) {
}
{
// Null element array.
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < 3; ++i)
- arr->InsertAt(i, new CPDF_Null);
+ arr->InsertNewAt<CPDF_Null>(i);
for (size_t i = 0; i < 3; ++i) {
TestArrayAccessors(arr.get(), i, // Array and index.
"", // String value.
@@ -526,14 +525,13 @@ TEST(PDFArrayTest, GetTypeAt) {
{
// Array of array.
CPDF_Array* vals[3];
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < 3; ++i) {
- vals[i] = new CPDF_Array;
+ vals[i] = arr->AddNew<CPDF_Array>();
for (size_t j = 0; j < 3; ++j) {
int value = j + 100;
- vals[i]->InsertAt(i, new CPDF_Number(value));
+ vals[i]->InsertNewAt<CPDF_Number>(i, value);
}
- arr->InsertAt(i, vals[i]);
}
for (size_t i = 0; i < 3; ++i) {
TestArrayAccessors(arr.get(), i, // Array and index.
@@ -549,9 +547,9 @@ TEST(PDFArrayTest, GetTypeAt) {
{
// Dictionary array.
CPDF_Dictionary* vals[3];
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < 3; ++i) {
- vals[i] = new CPDF_Dictionary();
+ vals[i] = arr->AddNew<CPDF_Dictionary>();
for (size_t j = 0; j < 3; ++j) {
std::string key("key");
char buf[33];
@@ -559,7 +557,6 @@ TEST(PDFArrayTest, GetTypeAt) {
int value = j + 200;
vals[i]->SetFor(key.c_str(), new CPDF_Number(value));
}
- arr->InsertAt(i, vals[i]);
}
for (size_t i = 0; i < 3; ++i) {
TestArrayAccessors(arr.get(), i, // Array and index.
@@ -576,7 +573,7 @@ TEST(PDFArrayTest, GetTypeAt) {
// Stream array.
CPDF_Dictionary* vals[3];
CPDF_Stream* stream_vals[3];
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < 3; ++i) {
vals[i] = new CPDF_Dictionary();
for (size_t j = 0; j < 3; ++j) {
@@ -590,8 +587,7 @@ TEST(PDFArrayTest, GetTypeAt) {
size_t data_size = FX_ArraySize(content);
uint8_t* data = reinterpret_cast<uint8_t*>(malloc(data_size));
memcpy(data, content, data_size);
- stream_vals[i] = new CPDF_Stream(data, data_size, vals[i]);
- arr->InsertAt(i, stream_vals[i]);
+ stream_vals[i] = arr->AddNew<CPDF_Stream>(data, data_size, vals[i]);
}
for (size_t i = 0; i < 3; ++i) {
TestArrayAccessors(arr.get(), i, // Array and index.
@@ -606,27 +602,27 @@ TEST(PDFArrayTest, GetTypeAt) {
}
{
// Mixed array.
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
- // Array arr will take ownership of all the objects inserted.
- arr->InsertAt(0, new CPDF_Boolean(true));
- arr->InsertAt(1, new CPDF_Boolean(false));
- arr->InsertAt(2, new CPDF_Number(0));
- arr->InsertAt(3, new CPDF_Number(-1234));
- arr->InsertAt(4, new CPDF_Number(2345.0f));
- arr->InsertAt(5, new CPDF_Number(0.05f));
- arr->InsertAt(6, new CPDF_String("", false));
- arr->InsertAt(7, new CPDF_String("It is a test!", false));
- arr->InsertAt(8, new CPDF_Name("NAME"));
- arr->InsertAt(9, new CPDF_Name("test"));
- arr->InsertAt(10, new CPDF_Null());
- CPDF_Array* arr_val = new CPDF_Array;
- arr_val->AddNumber(1);
- arr_val->AddNumber(2);
- arr->InsertAt(11, arr_val);
- CPDF_Dictionary* dict_val = new CPDF_Dictionary();
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
+ arr->InsertNewAt<CPDF_Boolean>(0, true);
+ arr->InsertNewAt<CPDF_Boolean>(1, false);
+ arr->InsertNewAt<CPDF_Number>(2, 0);
+ arr->InsertNewAt<CPDF_Number>(3, -1234);
+ arr->InsertNewAt<CPDF_Number>(4, 2345.0f);
+ arr->InsertNewAt<CPDF_Number>(5, 0.05f);
+ arr->InsertNewAt<CPDF_String>(6, "", false);
+ arr->InsertNewAt<CPDF_String>(7, "It is a test!", false);
+ arr->InsertNewAt<CPDF_Name>(8, "NAME");
+ arr->InsertNewAt<CPDF_Name>(9, "test");
+ arr->InsertNewAt<CPDF_Null>(10);
+
+ CPDF_Array* arr_val = arr->InsertNewAt<CPDF_Array>(11);
+ arr_val->AddNew<CPDF_Number>(1);
+ arr_val->AddNew<CPDF_Number>(2);
+
+ CPDF_Dictionary* dict_val = arr->InsertNewAt<CPDF_Dictionary>(12);
dict_val->SetFor("key1", new CPDF_String("Linda", false));
dict_val->SetFor("key2", new CPDF_String("Zoe", false));
- arr->InsertAt(12, dict_val);
+
CPDF_Dictionary* stream_dict = new CPDF_Dictionary();
stream_dict->SetFor("key1", new CPDF_String("John", false));
stream_dict->SetFor("key2", new CPDF_String("King", false));
@@ -636,8 +632,8 @@ TEST(PDFArrayTest, GetTypeAt) {
size_t buf_size = sizeof(data);
uint8_t* buf = reinterpret_cast<uint8_t*>(malloc(buf_size));
memcpy(buf, data, buf_size);
- CPDF_Stream* stream_val = new CPDF_Stream(buf, buf_size, stream_dict);
- arr->InsertAt(13, stream_val);
+ CPDF_Stream* stream_val =
+ arr->InsertNewAt<CPDF_Stream>(13, buf, buf_size, stream_dict);
const char* const expected_str[] = {
"true", "false", "0", "-1234", "2345", "0.05", "",
"It is a test!", "NAME", "test", "", "", "", ""};
@@ -671,9 +667,9 @@ TEST(PDFArrayTest, GetTypeAt) {
TEST(PDFArrayTest, AddNumber) {
float vals[] = {1.0f, -1.0f, 0, 0.456734f,
12345.54321f, 0.5f, 1000, 0.000045f};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < FX_ArraySize(vals); ++i)
- arr->AddNumber(vals[i]);
+ arr->AddNew<CPDF_Number>(vals[i]);
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
EXPECT_EQ(CPDF_Object::NUMBER, arr->GetObjectAt(i)->GetType());
EXPECT_EQ(vals[i], arr->GetObjectAt(i)->GetNumber());
@@ -682,9 +678,9 @@ TEST(PDFArrayTest, AddNumber) {
TEST(PDFArrayTest, AddInteger) {
int vals[] = {0, 1, 934435456, 876, 10000, -1, -24354656, -100};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < FX_ArraySize(vals); ++i)
- arr->AddInteger(vals[i]);
+ arr->AddNew<CPDF_Number>(vals[i]);
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
EXPECT_EQ(CPDF_Object::NUMBER, arr->GetObjectAt(i)->GetType());
EXPECT_EQ(vals[i], arr->GetObjectAt(i)->GetNumber());
@@ -697,8 +693,8 @@ TEST(PDFArrayTest, AddStringAndName) {
std::unique_ptr<CPDF_Array> string_array(new CPDF_Array);
std::unique_ptr<CPDF_Array> name_array(new CPDF_Array);
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
- string_array->AddString(vals[i]);
- name_array->AddName(vals[i]);
+ string_array->AddNew<CPDF_String>(vals[i], false);
+ name_array->AddNew<CPDF_Name>(vals[i]);
}
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
EXPECT_EQ(CPDF_Object::STRING, string_array->GetObjectAt(i)->GetType());
@@ -720,14 +716,14 @@ TEST(PDFArrayTest, AddReferenceAndGetObjectAt) {
CPDF_Object* indirect_objs[] = {boolean_obj, int_obj, float_obj,
str_obj, name_obj, null_obj};
unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
std::unique_ptr<CPDF_Array> arr1(new CPDF_Array);
// Create two arrays of references by different AddReference() APIs.
for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) {
holder->ReplaceIndirectObjectIfHigherGeneration(
obj_nums[i], pdfium::WrapUnique<CPDF_Object>(indirect_objs[i]));
- arr->AddReference(holder.get(), obj_nums[i]);
- arr1->AddReference(holder.get(), indirect_objs[i]->GetObjNum());
+ arr->AddNew<CPDF_Reference>(holder.get(), obj_nums[i]);
+ arr1->AddNew<CPDF_Reference>(holder.get(), indirect_objs[i]->GetObjNum());
}
// Check indirect objects.
for (size_t i = 0; i < FX_ArraySize(obj_nums); ++i)
@@ -747,7 +743,7 @@ TEST(PDFArrayTest, AddReferenceAndGetObjectAt) {
TEST(PDFArrayTest, CloneDirectObject) {
CPDF_IndirectObjectHolder objects_holder;
std::unique_ptr<CPDF_Array> array(new CPDF_Array);
- array->AddReference(&objects_holder, 1234);
+ array->AddNew<CPDF_Reference>(&objects_holder, 1234);
ASSERT_EQ(1U, array->GetCount());
CPDF_Object* obj = array->GetObjectAt(0);
ASSERT_TRUE(obj);
@@ -766,9 +762,8 @@ TEST(PDFArrayTest, CloneDirectObject) {
TEST(PDFArrayTest, ConvertIndirect) {
CPDF_IndirectObjectHolder objects_holder;
- std::unique_ptr<CPDF_Array> array(new CPDF_Array);
- CPDF_Object* pObj = new CPDF_Number(42);
- array->Add(pObj);
+ auto array = pdfium::MakeUnique<CPDF_Array>();
+ CPDF_Object* pObj = array->AddNew<CPDF_Number>(42);
array->ConvertToIndirectObjectAt(0, &objects_holder);
CPDF_Object* pRef = array->GetObjectAt(0);
CPDF_Object* pNum = array->GetDirectObjectAt(0);
@@ -802,11 +797,9 @@ TEST(PDFDictionaryTest, CloneDirectObject) {
TEST(PDFObjectTest, CloneCheckLoop) {
{
// Create a dictionary/array pair with a reference loop.
- CPDF_Dictionary* dict_obj = new CPDF_Dictionary();
- std::unique_ptr<CPDF_Array> arr_obj(new CPDF_Array);
+ auto arr_obj = pdfium::MakeUnique<CPDF_Array>();
+ CPDF_Dictionary* dict_obj = arr_obj->InsertNewAt<CPDF_Dictionary>(0);
dict_obj->SetFor("arr", arr_obj.get());
- arr_obj->InsertAt(0, dict_obj);
-
// Clone this object to see whether stack overflow will be triggered.
std::unique_ptr<CPDF_Array> cloned_array = ToArray(arr_obj->Clone());
// Cloned object should be the same as the original.
@@ -840,8 +833,8 @@ TEST(PDFObjectTest, CloneCheckLoop) {
// Create an object with a reference loop.
CPDF_Dictionary* dict_obj = objects_holder.NewIndirect<CPDF_Dictionary>();
std::unique_ptr<CPDF_Array> arr_obj = pdfium::MakeUnique<CPDF_Array>();
- arr_obj->InsertAt(
- 0, new CPDF_Reference(&objects_holder, dict_obj->GetObjNum()));
+ arr_obj->InsertNewAt<CPDF_Reference>(0, &objects_holder,
+ dict_obj->GetObjNum());
CPDF_Object* elem0 = arr_obj->GetObjectAt(0);
dict_obj->SetFor("arr", arr_obj.release());
EXPECT_EQ(1u, dict_obj->GetObjNum());
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 842ef2b222..6a3db60286 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -414,7 +414,7 @@ std::unique_ptr<CPDF_Object> CPDF_SyntaxParser::GetObject(
std::unique_ptr<CPDF_Array> pArray = pdfium::MakeUnique<CPDF_Array>();
while (std::unique_ptr<CPDF_Object> pObj =
GetObject(pObjList, objnum, gennum, true)) {
- pArray->Add(pObj.release());
+ pArray->Add(std::move(pObj));
}
return std::move(pArray);
}
@@ -534,7 +534,7 @@ std::unique_ptr<CPDF_Object> CPDF_SyntaxParser::GetObjectForStrict(
std::unique_ptr<CPDF_Array> pArray = pdfium::MakeUnique<CPDF_Array>();
while (std::unique_ptr<CPDF_Object> pObj =
GetObject(pObjList, objnum, gennum, true)) {
- pArray->Add(pObj.release());
+ pArray->Add(std::move(pObj));
}
return m_WordBuffer[0] == ']' ? std::move(pArray) : nullptr;
}