Skip to content

Commit 27f3d37

Browse files
committed
Revert "A third alternative."
This reverts commit f2654ae.
1 parent f2654ae commit 27f3d37

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

lld/MachO/InputFiles.cpp

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

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

llvm/lib/Object/Archive.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ 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 = MemoryBuffer::getFile(FullName);
587+
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf =
588+
MemoryBuffer::getFile(FullName, false, /*RequiresNullTerminator=*/false);
588589
if (std::error_code EC = Buf.getError())
589590
return errorCodeToError(EC);
590591
Parent->ThinBuffers.push_back(std::move(*Buf));

llvm/lib/Support/MemoryBuffer.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,8 @@ 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 IsText,
270-
bool RequiresNullTerminator, bool IsVolatile,
271-
std::optional<Align> Alignment);
269+
uint64_t MapSize, int64_t Offset, bool RequiresNullTerminator,
270+
bool IsVolatile, std::optional<Align> Alignment);
272271

273272
template <typename MB>
274273
static ErrorOr<std::unique_ptr<MB>>
@@ -281,8 +280,7 @@ getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
281280
return errorToErrorCode(FDOrErr.takeError());
282281
sys::fs::file_t FD = *FDOrErr;
283282
auto Ret = getOpenFileImpl<MB>(FD, Filename, /*FileSize=*/-1, MapSize, Offset,
284-
IsText, RequiresNullTerminator, IsVolatile,
285-
Alignment);
283+
RequiresNullTerminator, IsVolatile, Alignment);
286284
sys::fs::closeFile(FD);
287285
return Ret;
288286
}
@@ -470,9 +468,8 @@ WriteThroughMemoryBuffer::getFileSlice(const Twine &Filename, uint64_t MapSize,
470468
template <typename MB>
471469
static ErrorOr<std::unique_ptr<MB>>
472470
getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
473-
uint64_t MapSize, int64_t Offset, bool IsText,
474-
bool RequiresNullTerminator, bool IsVolatile,
475-
std::optional<Align> Alignment) {
471+
uint64_t MapSize, int64_t Offset, bool RequiresNullTerminator,
472+
bool IsVolatile, std::optional<Align> Alignment) {
476473
static int PageSize = sys::Process::getPageSizeEstimate();
477474

478475
// Default is to map the full file.
@@ -509,7 +506,7 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
509506
// from the page cache that are not properly filled with trailing zeroes,
510507
// if some prior user of the page wrote non-zero bytes. Detect this and
511508
// don't use mmap in that case.
512-
if (!IsText || *Result->getBufferEnd() == '\0')
509+
if (!RequiresNullTerminator || *Result->getBufferEnd() == '\0')
513510
return std::move(Result);
514511
}
515512
}
@@ -558,16 +555,16 @@ MemoryBuffer::getOpenFile(sys::fs::file_t FD, const Twine &Filename,
558555
uint64_t FileSize, bool RequiresNullTerminator,
559556
bool IsVolatile, std::optional<Align> Alignment) {
560557
return getOpenFileImpl<MemoryBuffer>(FD, Filename, FileSize, FileSize, 0,
561-
false, RequiresNullTerminator,
562-
IsVolatile, Alignment);
558+
RequiresNullTerminator, IsVolatile,
559+
Alignment);
563560
}
564561

565562
ErrorOr<std::unique_ptr<MemoryBuffer>> MemoryBuffer::getOpenFileSlice(
566563
sys::fs::file_t FD, const Twine &Filename, uint64_t MapSize, int64_t Offset,
567564
bool IsVolatile, std::optional<Align> Alignment) {
568565
assert(MapSize != uint64_t(-1));
569566
return getOpenFileImpl<MemoryBuffer>(FD, Filename, -1, MapSize, Offset, false,
570-
false, IsVolatile, Alignment);
567+
IsVolatile, Alignment);
571568
}
572569

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

0 commit comments

Comments
 (0)