X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FObject%2FArchive.cpp;h=070fe812eec23781e7ce4bdb6eed273900bf625d;hb=bb69ce8c70f6a392fedc6ec520705f55b2e4fb0f;hp=6d09bdbac06ed0d4eafdc00e27b47c1d1cd71409;hpb=d2ae11527af77939ccbdc3f2d1b862ccc5d1fc23;p=oota-llvm.git diff --git a/lib/Object/Archive.cpp b/lib/Object/Archive.cpp index 6d09bdbac06..070fe812eec 100644 --- a/lib/Object/Archive.cpp +++ b/lib/Object/Archive.cpp @@ -109,7 +109,7 @@ Archive::Child Archive::Child::getNext() const { const char *NextLoc = Data.data() + SpaceToSkip; // Check to see if this is past the end of the archive. - if (NextLoc >= Parent->Data->getBufferEnd()) + if (NextLoc >= Parent->Data.getBufferEnd()) return Child(Parent, nullptr); return Child(Parent, NextLoc); @@ -159,46 +159,36 @@ ErrorOr Archive::Child::getName() const { return name; } -ErrorOr> -Archive::Child::getMemoryBuffer(bool FullPath) const { +ErrorOr Archive::Child::getMemoryBufferRef() const { ErrorOr NameOrErr = getName(); if (std::error_code EC = NameOrErr.getError()) return EC; StringRef Name = NameOrErr.get(); - SmallString<128> Path; - std::unique_ptr Ret(MemoryBuffer::getMemBuffer( - getBuffer(), - FullPath - ? (Twine(Parent->getFileName()) + "(" + Name + ")").toStringRef(Path) - : Name, - false)); - return std::move(Ret); + return MemoryBufferRef(getBuffer(), Name); } ErrorOr> Archive::Child::getAsBinary(LLVMContext *Context) const { - std::unique_ptr ret; - ErrorOr> BuffOrErr = getMemoryBuffer(); + ErrorOr BuffOrErr = getMemoryBufferRef(); if (std::error_code EC = BuffOrErr.getError()) return EC; - std::unique_ptr Buff(BuffOrErr.get().release()); - return createBinary(Buff, Context); + return createBinary(BuffOrErr.get(), Context); } -ErrorOr Archive::create(std::unique_ptr Source) { +ErrorOr> Archive::create(MemoryBufferRef Source) { std::error_code EC; - std::unique_ptr Ret(new Archive(std::move(Source), EC)); + std::unique_ptr Ret(new Archive(Source, EC)); if (EC) return EC; - return Ret.release(); + return std::move(Ret); } -Archive::Archive(std::unique_ptr Source, std::error_code &ec) - : Binary(Binary::ID_Archive, std::move(Source)), SymbolTable(child_end()) { +Archive::Archive(MemoryBufferRef Source, std::error_code &ec) + : Binary(Binary::ID_Archive, Source), SymbolTable(child_end()) { // Check for sufficient magic. - if (Data->getBufferSize() < 8 || - StringRef(Data->getBufferStart(), 8) != Magic) { + if (Data.getBufferSize() < 8 || + StringRef(Data.getBufferStart(), 8) != Magic) { ec = object_error::invalid_file_type; return; } @@ -312,13 +302,13 @@ Archive::Archive(std::unique_ptr Source, std::error_code &ec) } Archive::child_iterator Archive::child_begin(bool SkipInternal) const { - if (Data->getBufferSize() == 8) // empty archive. + if (Data.getBufferSize() == 8) // empty archive. return child_end(); if (SkipInternal) return FirstRegular; - const char *Loc = Data->getBufferStart() + strlen(Magic); + const char *Loc = Data.getBufferStart() + strlen(Magic); Child c(this, Loc); return c; }