Check if the pointer is null/string is not utf8
This commit is contained in:
parent
bc4c5bac40
commit
80ca198212
1 changed files with 16 additions and 5 deletions
|
@ -228,14 +228,25 @@ pub fn handle_native_features(sess: &Session) -> Vec<String> {
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
let ptr = unsafe { llvm::LLVMGetHostCPUFeatures() };
|
let features_string = unsafe {
|
||||||
let str = unsafe { CStr::from_ptr(ptr).to_string_lossy() };
|
let ptr = llvm::LLVMGetHostCPUFeatures();
|
||||||
|
let features_string = if !ptr.is_null() {
|
||||||
|
CStr::from_ptr(ptr)
|
||||||
|
.to_str()
|
||||||
|
.unwrap_or_else(|e| {
|
||||||
|
bug!("LLVM returned a non-utf8 features string: {}", e);
|
||||||
|
})
|
||||||
|
.to_owned()
|
||||||
|
} else {
|
||||||
|
bug!("could not allocate host CPU features, LLVM returned a `null` string");
|
||||||
|
};
|
||||||
|
|
||||||
let features = str.split(",").map(|s| s.to_owned()).collect();
|
llvm::LLVMDisposeMessage(ptr);
|
||||||
|
|
||||||
unsafe { llvm::LLVMDisposeMessage(ptr) };
|
features_string
|
||||||
|
};
|
||||||
|
|
||||||
features
|
features_string.split(",").map(|s| s.to_owned()).collect()
|
||||||
}
|
}
|
||||||
None => vec![],
|
None => vec![],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue