[LLVM 4.0] rustllvm archive support
Error handling is being transitioned from ErrorOr<T> to Expected<T> which has a different API and requires explicitly handling all errors
This commit is contained in:
parent
692d7cfb0c
commit
25564dcda7
1 changed files with 19 additions and 0 deletions
|
@ -163,9 +163,20 @@ LLVMRustArchiveIteratorFree(LLVMRustArchiveIteratorRef rai) {
|
||||||
|
|
||||||
extern "C" const char*
|
extern "C" const char*
|
||||||
LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) {
|
LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) {
|
||||||
|
#if LLVM_VERSION_GE(4, 0)
|
||||||
|
Expected<StringRef> name_or_err = child->getName();
|
||||||
|
if (!name_or_err) {
|
||||||
|
// rustc_llvm currently doesn't use this error string, but it might be useful
|
||||||
|
// in the future, and in the mean time this tells LLVM that the error was
|
||||||
|
// not ignored and that it shouldn't abort the process.
|
||||||
|
LLVMRustSetLastError(toString(name_or_err.takeError()).c_str());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
ErrorOr<StringRef> name_or_err = child->getName();
|
ErrorOr<StringRef> name_or_err = child->getName();
|
||||||
if (name_or_err.getError())
|
if (name_or_err.getError())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#endif
|
||||||
StringRef name = name_or_err.get();
|
StringRef name = name_or_err.get();
|
||||||
*size = name.size();
|
*size = name.size();
|
||||||
return name.data();
|
return name.data();
|
||||||
|
@ -174,11 +185,19 @@ LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) {
|
||||||
extern "C" const char*
|
extern "C" const char*
|
||||||
LLVMRustArchiveChildData(LLVMRustArchiveChildRef child, size_t *size) {
|
LLVMRustArchiveChildData(LLVMRustArchiveChildRef child, size_t *size) {
|
||||||
StringRef buf;
|
StringRef buf;
|
||||||
|
#if LLVM_VERSION_GE(4, 0)
|
||||||
|
Expected<StringRef> buf_or_err = child->getBuffer();
|
||||||
|
if (!buf_or_err) {
|
||||||
|
LLVMRustSetLastError(toString(buf_or_err.takeError()).c_str());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
ErrorOr<StringRef> buf_or_err = child->getBuffer();
|
ErrorOr<StringRef> buf_or_err = child->getBuffer();
|
||||||
if (buf_or_err.getError()) {
|
if (buf_or_err.getError()) {
|
||||||
LLVMRustSetLastError(buf_or_err.getError().message().c_str());
|
LLVMRustSetLastError(buf_or_err.getError().message().c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
buf = buf_or_err.get();
|
buf = buf_or_err.get();
|
||||||
*size = buf.size();
|
*size = buf.size();
|
||||||
return buf.data();
|
return buf.data();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue