mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
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.
This commit is contained in:
parent
4461f03a36
commit
b29d106b7c
@ -31,16 +31,30 @@ using namespace llvm::object;
|
|||||||
|
|
||||||
static char *LastError;
|
static char *LastError;
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MINOR >= 5
|
||||||
extern "C" LLVMMemoryBufferRef
|
extern "C" LLVMMemoryBufferRef
|
||||||
LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
|
LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
|
||||||
LLVMMemoryBufferRef MemBuf = NULL;
|
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile(Path,
|
||||||
char *err = NULL;
|
-1,
|
||||||
LLVMCreateMemoryBufferWithContentsOfFile(Path, &MemBuf, &err);
|
false);
|
||||||
if (err != NULL) {
|
if (!buf_or) {
|
||||||
LLVMRustSetLastError(err);
|
LLVMRustSetLastError(buf_or.getError().message().c_str());
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
return MemBuf;
|
return wrap(buf_or.get().release());
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
extern "C" LLVMMemoryBufferRef
|
||||||
|
LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
|
||||||
|
OwningPtr<MemoryBuffer> buf;
|
||||||
|
error_code err = MemoryBuffer::getFile(Path, buf, -1, false);
|
||||||
|
if (err) {
|
||||||
|
LLVMRustSetLastError(err.message().c_str());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return wrap(buf.take());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
extern "C" char *LLVMRustGetLastError(void) {
|
extern "C" char *LLVMRustGetLastError(void) {
|
||||||
char *ret = LastError;
|
char *ret = LastError;
|
||||||
@ -658,10 +672,12 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
|
|||||||
#if LLVM_VERSION_MINOR >= 5
|
#if LLVM_VERSION_MINOR >= 5
|
||||||
extern "C" void*
|
extern "C" void*
|
||||||
LLVMRustOpenArchive(char *path) {
|
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) {
|
if (!buf_or) {
|
||||||
LLVMRustSetLastError(buf_or.getError().message().c_str());
|
LLVMRustSetLastError(buf_or.getError().message().c_str());
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_code err;
|
std::error_code err;
|
||||||
@ -676,7 +692,7 @@ LLVMRustOpenArchive(char *path) {
|
|||||||
extern "C" void*
|
extern "C" void*
|
||||||
LLVMRustOpenArchive(char *path) {
|
LLVMRustOpenArchive(char *path) {
|
||||||
OwningPtr<MemoryBuffer> buf;
|
OwningPtr<MemoryBuffer> buf;
|
||||||
error_code err = MemoryBuffer::getFile(path, buf);
|
error_code err = MemoryBuffer::getFile(path, buf, -1, false);
|
||||||
if (err) {
|
if (err) {
|
||||||
LLVMRustSetLastError(err.message().c_str());
|
LLVMRustSetLastError(err.message().c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user