[PATCH] C API: return NULL from LLVMGetFirstTarget instead of asserting
Sylvestre Ledru
sylvestre at debian.org
Sat Oct 12 09:30:17 PDT 2013
Hello,
General to your recent patches, you should not mix comestic changes and
feature changes.
Sylvestre
On 12/10/2013 17:48, Peter Zotov wrote:
> If no targets are registered, LLVMGetFirstTarget currently fails with an assertion. This patch makes it return NULL instead, similarly to how LLVMGetNextTarget would.
>
> http://llvm-reviews.chandlerc.com/D1908
>
> Files:
> lib/Target/TargetMachineC.cpp
>
> Index: lib/Target/TargetMachineC.cpp
> ===================================================================
> --- lib/Target/TargetMachineC.cpp
> +++ lib/Target/TargetMachineC.cpp
> @@ -48,21 +48,29 @@
> inline TargetMachine *unwrap(LLVMTargetMachineRef P) {
> return reinterpret_cast<TargetMachine*>(P);
> }
> +
> inline Target *unwrap(LLVMTargetRef P) {
> return reinterpret_cast<Target*>(P);
> }
> +
> inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
> return
> reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine*>(P));
> }
> +
> inline LLVMTargetRef wrap(const Target * P) {
> return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P));
> }
>
> LLVMTargetRef LLVMGetFirstTarget() {
> - const Target* target = &*TargetRegistry::begin();
> - return wrap(target);
> + if(TargetRegistry::begin() == TargetRegistry::end()) {
> + return NULL;
> + }
> +
> + const Target* target = &*TargetRegistry::begin();
> + return wrap(target);
> }
> +
> LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T) {
> return wrap(unwrap(T)->getNext());
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131012/3f49b75e/attachment.html>
More information about the llvm-commits
mailing list