diff options
author | tsepez <tsepez@chromium.org> | 2016-10-13 15:56:53 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-13 15:56:53 -0700 |
commit | 4e4d1a662b09d9ee1dc93dd8ee37694d3c4eb519 (patch) | |
tree | ef6c2b6e8915ac1463d7fb50f8275e3422d41506 /core/fpdfapi/parser | |
parent | 36bad2b022014ea7161fe888fec1191d2ba6b894 (diff) | |
download | pdfium-4e4d1a662b09d9ee1dc93dd8ee37694d3c4eb519.tar.xz |
Make CPDF_Image() constructors saner.chromium/2890
Introduce the UniqueDictionary typedef and friends, to allow
moving to unique_ptrs before the Release() deleter issue is
fully resolved. This will go away down the road.
Review-Url: https://codereview.chromium.org/2420743002
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r-- | core/fpdfapi/parser/cpdf_array.h | 9 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_dictionary.h | 12 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_object.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_stream.h | 10 |
4 files changed, 32 insertions, 1 deletions
diff --git a/core/fpdfapi/parser/cpdf_array.h b/core/fpdfapi/parser/cpdf_array.h index 46e9d47667..8cfa0333bb 100644 --- a/core/fpdfapi/parser/cpdf_array.h +++ b/core/fpdfapi/parser/cpdf_array.h @@ -69,6 +69,7 @@ class CPDF_Array : public CPDF_Object { std::vector<CPDF_Object*> m_Objects; }; +using UniqueArray = std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Object>>; inline CPDF_Array* ToArray(CPDF_Object* obj) { return obj ? obj->AsArray() : nullptr; @@ -78,4 +79,12 @@ inline const CPDF_Array* ToArray(const CPDF_Object* obj) { return obj ? obj->AsArray() : nullptr; } +inline UniqueArray ToArray(UniqueObject obj) { + CPDF_Array* pArray = ToArray(obj.get()); + if (!pArray) + return nullptr; + obj.release(); + return UniqueArray(pArray); +} + #endif // CORE_FPDFAPI_PARSER_CPDF_ARRAY_H_ diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h index 9cf575ddd4..fb8200f78c 100644 --- a/core/fpdfapi/parser/cpdf_dictionary.h +++ b/core/fpdfapi/parser/cpdf_dictionary.h @@ -15,6 +15,7 @@ #include "core/fxcrt/cfx_weak_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_string.h" +#include "third_party/base/ptr_util.h" class CPDF_IndirectObjectHolder; @@ -98,6 +99,9 @@ class CPDF_Dictionary : public CPDF_Object { std::map<CFX_ByteString, CPDF_Object*> m_Map; }; +using UniqueDictionary = + std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Object>>; + inline CPDF_Dictionary* ToDictionary(CPDF_Object* obj) { return obj ? obj->AsDictionary() : nullptr; } @@ -106,4 +110,12 @@ inline const CPDF_Dictionary* ToDictionary(const CPDF_Object* obj) { return obj ? obj->AsDictionary() : nullptr; } +inline UniqueDictionary ToDictionary(UniqueObject obj) { + CPDF_Dictionary* pDict = ToDictionary(obj.get()); + if (!pDict) + return nullptr; + obj.release(); + return UniqueDictionary(pDict); +} + #endif // CORE_FPDFAPI_PARSER_CPDF_DICTIONARY_H_ diff --git a/core/fpdfapi/parser/cpdf_object.h b/core/fpdfapi/parser/cpdf_object.h index 3cf23188a7..c888605d72 100644 --- a/core/fpdfapi/parser/cpdf_object.h +++ b/core/fpdfapi/parser/cpdf_object.h @@ -118,4 +118,6 @@ class CPDF_Object { CPDF_Object(const CPDF_Object& src) {} }; +using UniqueObject = std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>>; + #endif // CORE_FPDFAPI_PARSER_CPDF_OBJECT_H_ diff --git a/core/fpdfapi/parser/cpdf_stream.h b/core/fpdfapi/parser/cpdf_stream.h index 575a9ebe0b..756eccfba1 100644 --- a/core/fpdfapi/parser/cpdf_stream.h +++ b/core/fpdfapi/parser/cpdf_stream.h @@ -58,7 +58,7 @@ class CPDF_Stream : public CPDF_Object { IFX_FileRead* m_pFile = nullptr; }; -using UniqueStream = std::unique_ptr<CPDF_Stream, ReleaseDeleter<CPDF_Stream>>; +using UniqueStream = std::unique_ptr<CPDF_Stream, ReleaseDeleter<CPDF_Object>>; inline CPDF_Stream* ToStream(CPDF_Object* obj) { return obj ? obj->AsStream() : nullptr; @@ -68,4 +68,12 @@ inline const CPDF_Stream* ToStream(const CPDF_Object* obj) { return obj ? obj->AsStream() : nullptr; } +inline UniqueStream ToStream(UniqueObject obj) { + CPDF_Stream* pStream = ToStream(obj.get()); + if (!pStream) + return nullptr; + obj.release(); + return UniqueStream(pStream); +} + #endif // CORE_FPDFAPI_PARSER_CPDF_STREAM_H_ |