Skip to content

Commit f2654ae

Browse files
committed
A third alternative.
1 parent 80767a2 commit f2654ae

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

lld/MachO/InputFiles.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ std::optional<MemoryBufferRef> macho::readFile(StringRef path) {
217217
if (entry != cachedReads.end())
218218
return entry->second;
219219

220-
ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr =
221-
MemoryBuffer::getFile(path, false, /*RequiresNullTerminator=*/false);
220+
ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr = MemoryBuffer::getFile(path);
222221
if (std::error_code ec = mbOrErr.getError()) {
223222
error("cannot open " + path + ": " + ec.message());
224223
return std::nullopt;

llvm/lib/Object/Archive.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,7 @@ Expected<StringRef> Archive::Child::getBuffer() const {
584584
if (!FullNameOrErr)
585585
return FullNameOrErr.takeError();
586586
const std::string &FullName = *FullNameOrErr;
587-
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf =
588-
MemoryBuffer::getFile(FullName, false, /*RequiresNullTerminator=*/false);
587+
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = MemoryBuffer::getFile(FullName);
589588
if (std::error_code EC = Buf.getError())
590589
return errorCodeToError(EC);
591590
Parent->ThinBuffers.push_back(std::move(*Buf));

llvm/lib/Support/MemoryBuffer.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@ MemoryBuffer::getFile(const Twine &Filename, bool IsText,
266266
template <typename MB>
267267
static ErrorOr<std::unique_ptr<MB>>
268268
getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
269-
uint64_t MapSize, int64_t Offset, bool RequiresNullTerminator,
270-
bool IsVolatile, std::optional<Align> Alignment);
269+
uint64_t MapSize, int64_t Offset, bool IsText,
270+
bool RequiresNullTerminator, bool IsVolatile,
271+
std::optional<Align> Alignment);
271272

272273
template <typename MB>
273274
static ErrorOr<std::unique_ptr<MB>>
@@ -280,7 +281,8 @@ getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
280281
return errorToErrorCode(FDOrErr.takeError());
281282
sys::fs::file_t FD = *FDOrErr;
282283
auto Ret = getOpenFileImpl<MB>(FD, Filename, /*FileSize=*/-1, MapSize, Offset,
283-
RequiresNullTerminator, IsVolatile, Alignment);
284+
IsText, RequiresNullTerminator, IsVolatile,
285+
Alignment);
284286
sys::fs::closeFile(FD);
285287
return Ret;
286288
}
@@ -468,8 +470,9 @@ WriteThroughMemoryBuffer::getFileSlice(const Twine &Filename, uint64_t MapSize,
468470
template <typename MB>
469471
static ErrorOr<std::unique_ptr<MB>>
470472
getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
471-
uint64_t MapSize, int64_t Offset, bool RequiresNullTerminator,
472-
bool IsVolatile, std::optional<Align> Alignment) {
473+
uint64_t MapSize, int64_t Offset, bool IsText,
474+
bool RequiresNullTerminator, bool IsVolatile,
475+
std::optional<Align> Alignment) {
473476
static int PageSize = sys::Process::getPageSizeEstimate();
474477

475478
// Default is to map the full file.
@@ -506,7 +509,7 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
506509
// from the page cache that are not properly filled with trailing zeroes,
507510
// if some prior user of the page wrote non-zero bytes. Detect this and
508511
// don't use mmap in that case.
509-
if (!RequiresNullTerminator || *Result->getBufferEnd() == '\0')
512+
if (!IsText || *Result->getBufferEnd() == '\0')
510513
return std::move(Result);
511514
}
512515
}
@@ -555,16 +558,16 @@ MemoryBuffer::getOpenFile(sys::fs::file_t FD, const Twine &Filename,
555558
uint64_t FileSize, bool RequiresNullTerminator,
556559
bool IsVolatile, std::optional<Align> Alignment) {
557560
return getOpenFileImpl<MemoryBuffer>(FD, Filename, FileSize, FileSize, 0,
558-
RequiresNullTerminator, IsVolatile,
559-
Alignment);
561+
false, RequiresNullTerminator,
562+
IsVolatile, Alignment);
560563
}
561564

562565
ErrorOr<std::unique_ptr<MemoryBuffer>> MemoryBuffer::getOpenFileSlice(
563566
sys::fs::file_t FD, const Twine &Filename, uint64_t MapSize, int64_t Offset,
564567
bool IsVolatile, std::optional<Align> Alignment) {
565568
assert(MapSize != uint64_t(-1));
566569
return getOpenFileImpl<MemoryBuffer>(FD, Filename, -1, MapSize, Offset, false,
567-
IsVolatile, Alignment);
570+
false, IsVolatile, Alignment);
568571
}
569572

570573
ErrorOr<std::unique_ptr<MemoryBuffer>> MemoryBuffer::getSTDIN() {

0 commit comments

Comments
 (0)