diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-07-18 07:07:15 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-24 11:31:28 -0700 |
| commit | b29d106b7ca57214f30bef0ab49bb7c3399230fe (patch) | |
| tree | 40f3df1d2bd0f9ec5b0e49d10a1995202b853041 /src/rustllvm/RustWrapper.cpp | |
| parent | 4461f03a36a7a2d0ce2d6e3b50c92a7d75ccb40d (diff) | |
| download | rust-b29d106b7ca57214f30bef0ab49bb7c3399230fe.tar.gz rust-b29d106b7ca57214f30bef0ab49bb7c3399230fe.zip | |
rustllvm: Don't require null terminators in files
Apparently the default getFile implementation for a memory buffer in LLVM ends up requiring a null terminator at the end of the file. This isn't true a good bit of the time apparently on OSX. There have been a number of failed nightly/snapshot builds recently with this strange assertion. This modifies the calls to MemoryBuffer::getFile to explicitly not ask for a null terminator.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
| -rw-r--r-- | src/rustllvm/RustWrapper.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index a4437ea7c7b..e28a78b1ee7 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -31,16 +31,30 @@ using namespace llvm::object; static char *LastError; +#if LLVM_VERSION_MINOR >= 5 +extern "C" LLVMMemoryBufferRef +LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) { + ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile(Path, + -1, + false); + if (!buf_or) { + LLVMRustSetLastError(buf_or.getError().message().c_str()); + return nullptr; + } + return wrap(buf_or.get().release()); +} +#else extern "C" LLVMMemoryBufferRef LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) { - LLVMMemoryBufferRef MemBuf = NULL; - char *err = NULL; - LLVMCreateMemoryBufferWithContentsOfFile(Path, &MemBuf, &err); - if (err != NULL) { - LLVMRustSetLastError(err); + OwningPtr<MemoryBuffer> buf; + error_code err = MemoryBuffer::getFile(Path, buf, -1, false); + if (err) { + LLVMRustSetLastError(err.message().c_str()); + return NULL; } - return MemBuf; + return wrap(buf.take()); } +#endif extern "C" char *LLVMRustGetLastError(void) { char *ret = LastError; @@ -658,10 +672,12 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) { #if LLVM_VERSION_MINOR >= 5 extern "C" void* LLVMRustOpenArchive(char *path) { - ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile(path); + ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile(path, + -1, + false); if (!buf_or) { LLVMRustSetLastError(buf_or.getError().message().c_str()); - return NULL; + return nullptr; } std::error_code err; @@ -676,7 +692,7 @@ LLVMRustOpenArchive(char *path) { extern "C" void* LLVMRustOpenArchive(char *path) { OwningPtr<MemoryBuffer> buf; - error_code err = MemoryBuffer::getFile(path, buf); + error_code err = MemoryBuffer::getFile(path, buf, -1, false); if (err) { LLVMRustSetLastError(err.message().c_str()); return NULL; |
