[llvm-commits] CVS: llvm/lib/Support/MemoryBuffer.cpp
Chris Lattner
sabre at nondot.org
Sun May 6 16:32:59 PDT 2007
Changes in directory llvm/lib/Support:
MemoryBuffer.cpp updated: 1.4 -> 1.5
---
Log message:
Enhance MemoryBuffer to return error messages in strings if they occur.
---
Diffs of the changes: (+11 -7)
MemoryBuffer.cpp | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
Index: llvm/lib/Support/MemoryBuffer.cpp
diff -u llvm/lib/Support/MemoryBuffer.cpp:1.4 llvm/lib/Support/MemoryBuffer.cpp:1.5
--- llvm/lib/Support/MemoryBuffer.cpp:1.4 Sun May 6 02:24:46 2007
+++ llvm/lib/Support/MemoryBuffer.cpp Sun May 6 18:32:36 2007
@@ -113,7 +113,7 @@
public:
MemoryBufferMMapFile() {}
- bool open(const sys::Path &Filename);
+ bool open(const sys::Path &Filename, std::string *ErrStr);
virtual const char *getBufferIdentifier() const {
return File.path().c_str();
@@ -123,13 +123,15 @@
};
}
-bool MemoryBufferMMapFile::open(const sys::Path &Filename) {
+bool MemoryBufferMMapFile::open(const sys::Path &Filename,
+ std::string *ErrStr) {
// FIXME: This does an extra stat syscall to figure out the size, but we
// already know the size!
- bool Failure = File.open(Filename);
+ bool Failure = File.open(Filename, sys::MappedFile::READ_ACCESS, ErrStr);
if (Failure) return true;
- File.map();
+ if (!File.map(ErrStr))
+ return true;
size_t Size = File.size();
@@ -161,11 +163,13 @@
//===----------------------------------------------------------------------===//
MemoryBuffer *MemoryBuffer::getFile(const char *FilenameStart, unsigned FnSize,
- int64_t FileSize) {
+ std::string *ErrStr, int64_t FileSize){
+ // FIXME: it would be nice if PathWithStatus didn't copy the filename into a
+ // temporary string. :(
sys::PathWithStatus P(FilenameStart, FnSize);
#if 1
MemoryBufferMMapFile *M = new MemoryBufferMMapFile();
- if (!M->open(P))
+ if (!M->open(P, ErrStr))
return M;
delete M;
return 0;
@@ -186,7 +190,7 @@
// If the file is larger than some threshold, use mmap, otherwise use 'read'.
if (FileSize >= 4096*4) {
MemoryBufferMMapFile *M = new MemoryBufferMMapFile();
- if (!M->open(P))
+ if (!M->open(P, ErrStr))
return M;
delete M;
return 0;
More information about the llvm-commits
mailing list