aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-04-01 18:04:03 +0000
committerChris Lattner <sabre@nondot.org>2008-04-01 18:04:03 +0000
commit038112a4e0a9afd656f415ab397a230ae5921627 (patch)
tree1e533932de12cd50bf288f55438475ed736bdce8 /lib
parent8eedc9ee2ca3bb489957de68e3f907c88ca39efc (diff)
downloadexternal_llvm-038112a4e0a9afd656f415ab397a230ae5921627.zip
external_llvm-038112a4e0a9afd656f415ab397a230ae5921627.tar.gz
external_llvm-038112a4e0a9afd656f415ab397a230ae5921627.tar.bz2
Change the MemoryBuffer::getFile* methods to take just a pointer to the
start of a filename, not a filename+length. All clients can produce a null terminated name, and the system api's require null terminated strings anyway. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49041 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Archive/Archive.cpp5
-rw-r--r--lib/Archive/ArchiveWriter.cpp6
-rw-r--r--lib/AsmParser/Parser.cpp3
-rw-r--r--lib/Debugger/Debugger.cpp2
-rw-r--r--lib/Linker/Linker.cpp6
-rw-r--r--lib/Support/FileUtilities.cpp6
-rw-r--r--lib/Support/MemoryBuffer.cpp21
-rw-r--r--lib/VMCore/Core.cpp2
8 files changed, 20 insertions, 31 deletions
diff --git a/lib/Archive/Archive.cpp b/lib/Archive/Archive.cpp
index e32c716..a0e5eed 100644
--- a/lib/Archive/Archive.cpp
+++ b/lib/Archive/Archive.cpp
@@ -145,7 +145,7 @@ Archive::Archive(const sys::Path& filename)
bool
Archive::mapToMemory(std::string* ErrMsg) {
- mapfile = MemoryBuffer::getFile(archPath.c_str(), archPath.size(), ErrMsg);
+ mapfile = MemoryBuffer::getFile(archPath.c_str(), ErrMsg);
if (mapfile == 0)
return true;
base = mapfile->getBufferStart();
@@ -211,8 +211,7 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName,
std::vector<std::string>& symbols,
std::string* ErrMsg) {
std::auto_ptr<MemoryBuffer> Buffer(
- MemoryBuffer::getFileOrSTDIN(&fName.toString()[0],
- fName.toString().size()));
+ MemoryBuffer::getFileOrSTDIN(fName.c_str()));
if (!Buffer.get()) {
if (ErrMsg) *ErrMsg = "Could not open file '" + fName.toString() + "'";
return true;
diff --git a/lib/Archive/ArchiveWriter.cpp b/lib/Archive/ArchiveWriter.cpp
index afe9819..d3861f3 100644
--- a/lib/Archive/ArchiveWriter.cpp
+++ b/lib/Archive/ArchiveWriter.cpp
@@ -212,8 +212,7 @@ Archive::writeMember(
const char *data = (const char*)member.getData();
MemoryBuffer *mFile = 0;
if (!data) {
- mFile = MemoryBuffer::getFile(member.getPath().c_str(),
- member.getPath().size(), ErrMsg);
+ mFile = MemoryBuffer::getFile(member.getPath().c_str(), ErrMsg);
if (mFile == 0)
return true;
data = mFile->getBufferStart();
@@ -407,8 +406,7 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress,
// Map in the archive we just wrote.
{
- OwningPtr<MemoryBuffer> arch(MemoryBuffer::getFile(TmpArchive.c_str(),
- TmpArchive.size()));
+ OwningPtr<MemoryBuffer> arch(MemoryBuffer::getFile(TmpArchive.c_str()));
if (arch == 0) return true;
const char* base = arch->getBufferStart();
diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp
index 157a43b..0005e11 100644
--- a/lib/AsmParser/Parser.cpp
+++ b/lib/AsmParser/Parser.cpp
@@ -22,8 +22,7 @@ ParseError* TheParseError = 0; /// FIXME: Not threading friendly
Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError* Err) {
std::string ErrorStr;
- MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size(),
- &ErrorStr);
+ MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrorStr);
if (F == 0) {
if (Err)
Err->setError(Filename, "Could not open input file '" + Filename + "'");
diff --git a/lib/Debugger/Debugger.cpp b/lib/Debugger/Debugger.cpp
index e8194d9..78f48f6 100644
--- a/lib/Debugger/Debugger.cpp
+++ b/lib/Debugger/Debugger.cpp
@@ -47,7 +47,7 @@ std::string Debugger::getProgramPath() const {
static Module *
getMaterializedModuleProvider(const std::string &Filename) {
std::auto_ptr<MemoryBuffer> Buffer;
- Buffer.reset(MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size()));
+ Buffer.reset(MemoryBuffer::getFileOrSTDIN(Filename.c_str()));
if (Buffer.get())
return ParseBitcodeFile(Buffer.get());
return 0;
diff --git a/lib/Linker/Linker.cpp b/lib/Linker/Linker.cpp
index 64327e1..ef242e5 100644
--- a/lib/Linker/Linker.cpp
+++ b/lib/Linker/Linker.cpp
@@ -19,7 +19,8 @@
#include "llvm/Support/Streams.h"
using namespace llvm;
-Linker::Linker(const std::string& progname, const std::string& modname, unsigned flags)
+Linker::Linker(const std::string& progname, const std::string& modname,
+ unsigned flags)
: Composite(0)
, LibPaths()
, Flags(flags)
@@ -103,8 +104,7 @@ Linker::LoadObject(const sys::Path &FN) {
Module *Result = 0;
const std::string &FNS = FN.toString();
- std::auto_ptr<MemoryBuffer> Buffer(
- MemoryBuffer::getFileOrSTDIN(&FNS[0], FNS.size()));
+ std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(FNS.c_str()));
if (Buffer.get())
Result = ParseBitcodeFile(Buffer.get(), &ParseErrorMessage);
else
diff --git a/lib/Support/FileUtilities.cpp b/lib/Support/FileUtilities.cpp
index a765643..3340e8b 100644
--- a/lib/Support/FileUtilities.cpp
+++ b/lib/Support/FileUtilities.cpp
@@ -189,10 +189,8 @@ int llvm::DiffFilesWithTolerance(const sys::PathWithStatus &FileA,
// Now its safe to mmap the files into memory becasue both files
// have a non-zero size.
- OwningPtr<MemoryBuffer> F1(MemoryBuffer::getFile(FileA.c_str(), FileA.size(),
- Error));
- OwningPtr<MemoryBuffer> F2(MemoryBuffer::getFile(FileB.c_str(), FileB.size(),
- Error));
+ OwningPtr<MemoryBuffer> F1(MemoryBuffer::getFile(FileA.c_str(), Error));
+ OwningPtr<MemoryBuffer> F2(MemoryBuffer::getFile(FileB.c_str(), Error));
if (F1 == 0 || F2 == 0)
return 2;
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp
index 4e4dabc..7a60b85 100644
--- a/lib/Support/MemoryBuffer.cpp
+++ b/lib/Support/MemoryBuffer.cpp
@@ -132,12 +132,11 @@ MemoryBuffer *MemoryBuffer::getNewMemBuffer(unsigned Size,
/// if the Filename is "-". If an error occurs, this returns null and fills
/// in *ErrStr with a reason. If stdin is empty, this API (unlike getSTDIN)
/// returns an empty buffer.
-MemoryBuffer *MemoryBuffer::getFileOrSTDIN(const char *FilenameStart,
- unsigned FnSize,
+MemoryBuffer *MemoryBuffer::getFileOrSTDIN(const char *Filename,
std::string *ErrStr,
int64_t FileSize) {
- if (FnSize != 1 || FilenameStart[0] != '-')
- return getFile(FilenameStart, FnSize, ErrStr, FileSize);
+ if (Filename[0] != '-' || Filename[1] != 0)
+ return getFile(Filename, ErrStr, FileSize);
MemoryBuffer *M = getSTDIN();
if (M) return M;
@@ -172,17 +171,13 @@ public:
};
}
-MemoryBuffer *MemoryBuffer::getFile(const char *FilenameStart, unsigned FnSize,
- std::string *ErrStr, int64_t FileSize) {
- // Null terminate the filename.
- SmallString<1000> Filename(FilenameStart, FilenameStart+FnSize);
- Filename.push_back(0);
-
+MemoryBuffer *MemoryBuffer::getFile(const char *Filename, std::string *ErrStr,
+ int64_t FileSize) {
int OpenFlags = 0;
#ifdef O_BINARY
Flags |= O_BINARY; // Open input file in binary mode on win32.
#endif
- int FD = ::open(&Filename[0], O_RDONLY|OpenFlags);
+ int FD = ::open(Filename, O_RDONLY|OpenFlags);
if (FD == -1) {
if (ErrStr) *ErrStr = "could not open file";
return 0;
@@ -211,12 +206,12 @@ MemoryBuffer *MemoryBuffer::getFile(const char *FilenameStart, unsigned FnSize,
if (const char *Pages = sys::Path::MapInFilePages(FD, FileSize)) {
// Close the file descriptor, now that the whole file is in memory.
::close(FD);
- return new MemoryBufferMMapFile(&Filename[0], Pages, FileSize);
+ return new MemoryBufferMMapFile(Filename, Pages, FileSize);
}
}
OwningPtr<MemoryBuffer> SB;
- SB.reset(MemoryBuffer::getNewUninitMemBuffer(FileSize, &Filename[0]));
+ SB.reset(MemoryBuffer::getNewUninitMemBuffer(FileSize, Filename));
char *BufPtr = const_cast<char*>(SB->getBufferStart());
unsigned BytesLeft = FileSize;
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp
index 59b9b1a..c35c85d 100644
--- a/lib/VMCore/Core.cpp
+++ b/lib/VMCore/Core.cpp
@@ -1307,7 +1307,7 @@ int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
LLVMMemoryBufferRef *OutMemBuf,
char **OutMessage) {
std::string Error;
- if (MemoryBuffer *MB = MemoryBuffer::getFile(Path, strlen(Path), &Error)) {
+ if (MemoryBuffer *MB = MemoryBuffer::getFile(Path, &Error)) {
*OutMemBuf = wrap(MB);
return 0;
}