[Object] Replace TimeValue with std::chrono

Summary:
Most of the changes are very straight-forward. The only choice I had to make was
to use second-precision time points in the Archive classes. I did this because
the archive files use that precision in the on-disk representation anyway.

Reviewers: rafael, zturner

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D25773

llvm-svn: 284974
This commit is contained in:
Pavel Labath 2016-10-24 13:38:27 +00:00
parent 504bf334b0
commit bff47b51b6
5 changed files with 32 additions and 30 deletions

View File

@ -18,11 +18,11 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Object/Binary.h"
#include "llvm/Support/Chrono.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/TimeValue.h"
namespace llvm {
namespace object {
@ -46,7 +46,7 @@ public:
Expected<uint32_t> getSize() const;
Expected<sys::fs::perms> getAccessMode() const;
Expected<sys::TimeValue> getLastModified() const;
Expected<sys::TimePoint<std::chrono::seconds>> getLastModified() const;
llvm::StringRef getRawLastModified() const {
return StringRef(ArMemHdr->LastModified,
sizeof(ArMemHdr->LastModified)).rtrim(' ');
@ -103,7 +103,7 @@ public:
Expected<StringRef> getName() const;
Expected<std::string> getFullName() const;
Expected<StringRef> getRawName() const { return Header.getRawName(); }
Expected<sys::TimeValue> getLastModified() const {
Expected<sys::TimePoint<std::chrono::seconds>> getLastModified() const {
return Header.getLastModified();
}
StringRef getRawLastModified() const {

View File

@ -22,7 +22,7 @@ namespace llvm {
struct NewArchiveMember {
std::unique_ptr<MemoryBuffer> Buf;
sys::TimeValue ModTime = sys::TimeValue::PosixZeroTime();
sys::TimePoint<std::chrono::seconds> ModTime;
unsigned UID = 0, GID = 0, Perms = 0644;
NewArchiveMember() = default;

View File

@ -239,7 +239,8 @@ Expected<sys::fs::perms> ArchiveMemberHeader::getAccessMode() const {
return static_cast<sys::fs::perms>(Ret);
}
Expected<sys::TimeValue> ArchiveMemberHeader::getLastModified() const {
Expected<sys::TimePoint<std::chrono::seconds>>
ArchiveMemberHeader::getLastModified() const {
unsigned Seconds;
if (StringRef(ArMemHdr->LastModified,
sizeof(ArMemHdr->LastModified)).rtrim(' ')
@ -256,9 +257,7 @@ Expected<sys::TimeValue> ArchiveMemberHeader::getLastModified() const {
"archive member header at offset " + Twine(Offset));
}
sys::TimeValue Ret;
Ret.fromEpochTime(Seconds);
return Ret;
return sys::toTimePoint(Seconds);
}
Expected<unsigned> ArchiveMemberHeader::getUID() const {

View File

@ -47,7 +47,7 @@ NewArchiveMember::getOldMember(const object::Archive::Child &OldMember,
NewArchiveMember M;
M.Buf = MemoryBuffer::getMemBuffer(*BufOrErr, false);
if (!Deterministic) {
Expected<sys::TimeValue> ModTimeOrErr = OldMember.getLastModified();
auto ModTimeOrErr = OldMember.getLastModified();
if (!ModTimeOrErr)
return ModTimeOrErr.takeError();
M.ModTime = ModTimeOrErr.get();
@ -95,7 +95,8 @@ Expected<NewArchiveMember> NewArchiveMember::getFile(StringRef FileName,
NewArchiveMember M;
M.Buf = std::move(*MemberBufferOrErr);
if (!Deterministic) {
M.ModTime = Status.getLastModificationTime();
M.ModTime = std::chrono::time_point_cast<std::chrono::seconds>(
Status.getLastModificationTime());
M.UID = Status.getUser();
M.GID = Status.getGroup();
M.Perms = Status.permissions();
@ -127,11 +128,10 @@ static void print32(raw_ostream &Out, object::Archive::Kind Kind,
support::endian::Writer<support::little>(Out).write(Val);
}
static void printRestOfMemberHeader(raw_fd_ostream &Out,
const sys::TimeValue &ModTime, unsigned UID,
unsigned GID, unsigned Perms,
unsigned Size) {
printWithSpacePadding(Out, ModTime.toEpochTime(), 12);
static void printRestOfMemberHeader(
raw_fd_ostream &Out, const sys::TimePoint<std::chrono::seconds> &ModTime,
unsigned UID, unsigned GID, unsigned Perms, unsigned Size) {
printWithSpacePadding(Out, sys::toTimeT(ModTime), 12);
printWithSpacePadding(Out, UID, 6, true);
printWithSpacePadding(Out, GID, 6, true);
printWithSpacePadding(Out, format("%o", Perms), 8);
@ -139,17 +139,20 @@ static void printRestOfMemberHeader(raw_fd_ostream &Out,
Out << "`\n";
}
static void printGNUSmallMemberHeader(raw_fd_ostream &Out, StringRef Name,
const sys::TimeValue &ModTime,
unsigned UID, unsigned GID,
unsigned Perms, unsigned Size) {
static void
printGNUSmallMemberHeader(raw_fd_ostream &Out, StringRef Name,
const sys::TimePoint<std::chrono::seconds> &ModTime,
unsigned UID, unsigned GID, unsigned Perms,
unsigned Size) {
printWithSpacePadding(Out, Twine(Name) + "/", 16);
printRestOfMemberHeader(Out, ModTime, UID, GID, Perms, Size);
}
static void printBSDMemberHeader(raw_fd_ostream &Out, StringRef Name,
const sys::TimeValue &ModTime, unsigned UID,
unsigned GID, unsigned Perms, unsigned Size) {
static void
printBSDMemberHeader(raw_fd_ostream &Out, StringRef Name,
const sys::TimePoint<std::chrono::seconds> &ModTime,
unsigned UID, unsigned GID, unsigned Perms,
unsigned Size) {
uint64_t PosAfterHeader = Out.tell() + 60 + Name.size();
// Pad so that even 64 bit object files are aligned.
unsigned Pad = OffsetToAlignment(PosAfterHeader, 8);
@ -171,8 +174,8 @@ static void
printMemberHeader(raw_fd_ostream &Out, object::Archive::Kind Kind, bool Thin,
StringRef Name,
std::vector<unsigned>::iterator &StringMapIndexIter,
const sys::TimeValue &ModTime, unsigned UID, unsigned GID,
unsigned Perms, unsigned Size) {
const sys::TimePoint<std::chrono::seconds> &ModTime,
unsigned UID, unsigned GID, unsigned Perms, unsigned Size) {
if (Kind == object::Archive::K_BSD)
return printBSDMemberHeader(Out, Name, ModTime, UID, GID, Perms, Size);
if (!useStringTable(Thin, Name))
@ -239,12 +242,12 @@ static void writeStringTable(raw_fd_ostream &Out, StringRef ArcName,
Out.seek(Pos);
}
static sys::TimeValue now(bool Deterministic) {
static sys::TimePoint<std::chrono::seconds> now(bool Deterministic) {
using namespace std::chrono;
if (!Deterministic)
return sys::TimeValue::now();
sys::TimeValue TV;
TV.fromEpochTime(0);
return TV;
return time_point_cast<seconds>(system_clock::now());
return sys::TimePoint<seconds>();
}
// Returns the offset of the first reference to a member offset.

View File

@ -528,7 +528,7 @@ static InsertAction computeInsertAction(ArchiveOperation Operation,
failIfError(sys::fs::status(*MI, Status), *MI);
auto ModTimeOrErr = Member.getLastModified();
failIfError(ModTimeOrErr.takeError());
if (sys::TimeValue(Status.getLastModificationTime()) < ModTimeOrErr.get()) {
if (Status.getLastModificationTime() < ModTimeOrErr.get()) {
if (PosName.empty())
return IA_AddOldMember;
return IA_MoveOldMember;