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

Filip Pizlo fpizlo at apple.com
Sat Oct 12 10:38:52 PDT 2013


On Oct 12, 2013, at 9:33 AM, Peter Zotov <whitequark at whitequark.org> wrote:

> 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?

Please!

> 
>> 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.
> _______________________________________________
> 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/0cd85408/attachment.html>


More information about the llvm-commits mailing list