From 0d50598d71c5cc81c0e777a0ddf3e692e634f565 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 24 Jun 2014 13:56:32 +0000 Subject: Pass a unique_ptr to the constructors in the Binary hierarchy. Once the objects are constructed, they own the buffer. Passing a unique_ptr makes that clear. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211595 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/Archive.h | 4 ++-- include/llvm/Object/Binary.h | 2 +- include/llvm/Object/COFF.h | 2 +- include/llvm/Object/ELFObjectFile.h | 9 +++++---- include/llvm/Object/IRObjectFile.h | 3 ++- include/llvm/Object/MachO.h | 4 ++-- include/llvm/Object/MachOUniversal.h | 6 ++++-- include/llvm/Object/ObjectFile.h | 5 +++-- include/llvm/Object/SymbolicFile.h | 7 ++++--- 9 files changed, 24 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/include/llvm/Object/Archive.h b/include/llvm/Object/Archive.h index 4fe44a7769..af6c995c1d 100644 --- a/include/llvm/Object/Archive.h +++ b/include/llvm/Object/Archive.h @@ -164,8 +164,8 @@ public: } }; - Archive(MemoryBuffer *source, std::error_code &ec); - static ErrorOr create(MemoryBuffer *Source); + Archive(std::unique_ptr Source, std::error_code &EC); + static ErrorOr create(std::unique_ptr Source); enum Kind { K_GNU, diff --git a/include/llvm/Object/Binary.h b/include/llvm/Object/Binary.h index 258a885d4f..9be2fbe083 100644 --- a/include/llvm/Object/Binary.h +++ b/include/llvm/Object/Binary.h @@ -36,7 +36,7 @@ private: protected: std::unique_ptr Data; - Binary(unsigned int Type, MemoryBuffer *Source); + Binary(unsigned int Type, std::unique_ptr Source); enum { ID_Archive, diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index 1f45ab05db..e2da070d47 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -420,7 +420,7 @@ protected: StringRef &Result) const override; public: - COFFObjectFile(MemoryBuffer *Object, std::error_code &EC); + COFFObjectFile(std::unique_ptr Object, std::error_code &EC); basic_symbol_iterator symbol_begin_impl() const override; basic_symbol_iterator symbol_end_impl() const override; library_iterator needed_library_begin() const override; diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index 72f7216110..ae74ebc02c 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -177,7 +177,7 @@ protected: bool isDyldELFObject; public: - ELFObjectFile(MemoryBuffer *Object, std::error_code &EC); + ELFObjectFile(std::unique_ptr Object, std::error_code &EC); const Elf_Sym *getSymbol(DataRefImpl Symb) const; @@ -773,12 +773,13 @@ ELFObjectFile::getRela(DataRefImpl Rela) const { } template -ELFObjectFile::ELFObjectFile(MemoryBuffer *Object, std::error_code &ec) +ELFObjectFile::ELFObjectFile(std::unique_ptr Object, + std::error_code &EC) : ObjectFile(getELFType(static_cast(ELFT::TargetEndianness) == support::little, ELFT::Is64Bits), - Object), - EF(Object, ec) {} + std::move(Object)), + EF(Data.get(), EC) {} template basic_symbol_iterator ELFObjectFile::symbol_begin_impl() const { diff --git a/include/llvm/Object/IRObjectFile.h b/include/llvm/Object/IRObjectFile.h index 97a75b763d..3e6817554e 100644 --- a/include/llvm/Object/IRObjectFile.h +++ b/include/llvm/Object/IRObjectFile.h @@ -27,7 +27,8 @@ class IRObjectFile : public SymbolicFile { std::unique_ptr Mang; public: - IRObjectFile(MemoryBuffer *Object, std::error_code &EC, LLVMContext &Context); + IRObjectFile(std::unique_ptr Object, std::error_code &EC, + LLVMContext &Context); ~IRObjectFile(); void moveSymbolNext(DataRefImpl &Symb) const override; std::error_code printSymbolName(raw_ostream &OS, diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 182815f49a..8b7f904c57 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -56,8 +56,8 @@ public: MachO::load_command C; // The command itself. }; - MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, bool Is64Bits, - std::error_code &EC); + MachOObjectFile(std::unique_ptr Object, bool IsLittleEndian, + bool Is64Bits, std::error_code &EC); void moveSymbolNext(DataRefImpl &Symb) const override; std::error_code getSymbolName(DataRefImpl Symb, diff --git a/include/llvm/Object/MachOUniversal.h b/include/llvm/Object/MachOUniversal.h index 94fe99deec..268e1c839e 100644 --- a/include/llvm/Object/MachOUniversal.h +++ b/include/llvm/Object/MachOUniversal.h @@ -83,8 +83,10 @@ public: } }; - MachOUniversalBinary(MemoryBuffer *Source, std::error_code &ec); - static ErrorOr create(MemoryBuffer *Source); + MachOUniversalBinary(std::unique_ptr Source, + std::error_code &ec); + static ErrorOr + create(std::unique_ptr Source); object_iterator begin_objects() const { return ObjectForArch(this, 0); diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index 56799eb681..646abf80f8 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -208,7 +208,7 @@ class ObjectFile : public SymbolicFile { ObjectFile(const ObjectFile &other) LLVM_DELETED_FUNCTION; protected: - ObjectFile(unsigned int Type, MemoryBuffer *Source); + ObjectFile(unsigned int Type, std::unique_ptr Source); const uint8_t *base() const { return reinterpret_cast(Data->getBufferStart()); @@ -347,7 +347,8 @@ public: } public: - static ErrorOr createCOFFObjectFile(MemoryBuffer *Object); + static ErrorOr + createCOFFObjectFile(std::unique_ptr Object); static ErrorOr createELFObjectFile(std::unique_ptr &Object); static ErrorOr diff --git a/include/llvm/Object/SymbolicFile.h b/include/llvm/Object/SymbolicFile.h index 24908cde19..e48bf372a6 100644 --- a/include/llvm/Object/SymbolicFile.h +++ b/include/llvm/Object/SymbolicFile.h @@ -115,7 +115,7 @@ const uint64_t UnknownAddressOrSize = ~0ULL; class SymbolicFile : public Binary { public: virtual ~SymbolicFile(); - SymbolicFile(unsigned int Type, MemoryBuffer *Source); + SymbolicFile(unsigned int Type, std::unique_ptr Source); // virtual interface. virtual void moveSymbolNext(DataRefImpl &Symb) const = 0; @@ -142,8 +142,9 @@ public: } // construction aux. - static ErrorOr createIRObjectFile(MemoryBuffer *Object, - LLVMContext &Context); + static ErrorOr + createIRObjectFile(std::unique_ptr Object, + LLVMContext &Context); static ErrorOr createSymbolicFile(std::unique_ptr &Object, -- cgit v1.2.3