[PATCH] D84858: [llvm-libtool-darwin] Refactor ArchiveWriter
Sameer Arora via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 07:17:57 PDT 2020
sameerarora101 updated this revision to Diff 281924.
sameerarora101 marked an inline comment as done.
sameerarora101 added a comment.
Making `writeArchiveInFD` `static`
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84858/new/
https://reviews.llvm.org/D84858
Files:
llvm/include/llvm/Object/ArchiveWriter.h
llvm/lib/Object/ArchiveWriter.cpp
Index: llvm/lib/Object/ArchiveWriter.cpp
===================================================================
--- llvm/lib/Object/ArchiveWriter.cpp
+++ llvm/lib/Object/ArchiveWriter.cpp
@@ -552,10 +552,11 @@
return std::string(Relative.str());
}
-Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
- bool WriteSymtab, object::Archive::Kind Kind,
- bool Deterministic, bool Thin,
- std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
+static Expected<sys::fs::TempFile>
+writeArchiveInFD(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
+ bool WriteSymtab, object::Archive::Kind Kind,
+ bool Deterministic, bool Thin,
+ std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
assert((!Thin || !isBSDLike(Kind)) && "Only the gnu format has a thin mode");
SmallString<0> SymNamesBuf;
@@ -566,7 +567,7 @@
Expected<std::vector<MemberData>> DataOrErr = computeMemberData(
StringTable, SymNames, Kind, Thin, Deterministic, NewMembers);
if (Error E = DataOrErr.takeError())
- return E;
+ return std::move(E);
std::vector<MemberData> &Data = *DataOrErr;
if (!StringTableBuf.empty())
@@ -639,7 +640,43 @@
// closed before we attempt to rename.
OldArchiveBuf.reset();
+ return Temp;
+}
+
+Error writeArchive(StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
+ bool WriteSymtab, object::Archive::Kind Kind,
+ bool Deterministic, bool Thin,
+ std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
+
+ Expected<sys::fs::TempFile> Temp =
+ writeArchiveInFD(ArcName, NewMembers, WriteSymtab, Kind, Deterministic,
+ Thin, std::move(OldArchiveBuf));
+ if (!Temp)
+ return Temp.takeError();
+
return Temp->keep(ArcName);
}
+Error writeArchiveBuffer(StringRef ArcName,
+ ArrayRef<NewArchiveMember> NewMembers,
+ bool WriteSymtab, object::Archive::Kind Kind,
+ bool Deterministic, bool Thin,
+ std::unique_ptr<MemoryBuffer> &ReturnBuffer,
+ std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
+
+ Expected<sys::fs::TempFile> Temp =
+ writeArchiveInFD(ArcName, NewMembers, WriteSymtab, Kind, Deterministic,
+ Thin, std::move(OldArchiveBuf));
+ if (!Temp)
+ return Temp.takeError();
+
+ ErrorOr<std::unique_ptr<MemoryBuffer>> Ret =
+ MemoryBuffer::getOpenFile(Temp->FD, ArcName, -1);
+ if (std::error_code EC = Ret.getError())
+ return errorCodeToError(EC);
+
+ ReturnBuffer = std::move(Ret.get());
+ return Temp->discard();
+}
+
} // namespace llvm
Index: llvm/include/llvm/Object/ArchiveWriter.h
===================================================================
--- llvm/include/llvm/Object/ArchiveWriter.h
+++ llvm/include/llvm/Object/ArchiveWriter.h
@@ -39,6 +39,13 @@
bool WriteSymtab, object::Archive::Kind Kind,
bool Deterministic, bool Thin,
std::unique_ptr<MemoryBuffer> OldArchiveBuf = nullptr);
+
+Error writeArchiveBuffer(StringRef ArcName,
+ ArrayRef<NewArchiveMember> NewMembers,
+ bool WriteSymtab, object::Archive::Kind Kind,
+ bool Deterministic, bool Thin,
+ std::unique_ptr<MemoryBuffer> &ReturnBuffer,
+ std::unique_ptr<MemoryBuffer> OldArchiveBuf = nullptr);
}
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84858.281924.patch
Type: text/x-patch
Size: 3577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200730/ae2e35d4/attachment.bin>
More information about the llvm-commits
mailing list