[PATCH] C API: return NULL from LLVMGetFirstTarget instead of asserting

Peter Zotov whitequark at whitequark.org
Sat Oct 12 09:33:27 PDT 2013


Sylvestre Ledru писал 12.10.2013 20:30:
> Hello,
> 
>  General to your recent patches, you should not mix comestic changes
> and feature changes.

Sorry, this slipped in accidentally. Should I redo the patch?

> 
>  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 [1]
>> 
>> 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 [2]
> 
> 
> 
> Links:
> ------
> [1] http://llvm-reviews.chandlerc.com/D1908
> [2] http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-- 
   WBR, Peter Zotov.



More information about the llvm-commits mailing list