[cfe-commits] [PATCH] python bindings: Fix infinite iteration of compilation database CompileCommands

David Röthlisberger david at rothlis.net
Mon Jul 9 04:52:34 PDT 2012


On 9 Jul 2012, at 10:23, Arnaud de Grandmaison wrote:
> Do you want me to commit your patch ?

Yes please! :-)


> On 07/09/2012 09:27 AM, David Röthlisberger wrote:
>> `for c in db.getCompileCommands(file)` was an infinite loop.
>> ---
>> bindings/python/clang/cindex.py          | 2 +-
>> bindings/python/tests/cindex/test_cdb.py | 8 ++++++++
>> 2 files changed, 9 insertions(+), 1 deletion(-)
>> 
>> diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
>> index 295f1a7..5bee974 100644
>> --- a/bindings/python/clang/cindex.py
>> +++ b/bindings/python/clang/cindex.py
>> @@ -2162,7 +2162,7 @@ class CompileCommands(object):
>> 
>>     def __getitem__(self, i):
>>         cc = CompileCommands_getCommand(self.ccmds, i)
>> -        if cc is None:
>> +        if not cc:
>>             raise IndexError
>>         return CompileCommand(cc, self)
>> 
>> diff --git a/bindings/python/tests/cindex/test_cdb.py b/bindings/python/tests/cindex/test_cdb.py
>> index c59c439..d0f580e 100644
>> --- a/bindings/python/tests/cindex/test_cdb.py
>> +++ b/bindings/python/tests/cindex/test_cdb.py
>> @@ -61,6 +61,14 @@ def test_2_compilecommand():
>>         for arg, exp in zip(cmds[i].arguments, expected[i]['line']):
>>             assert arg == exp
>> 
>> +def test_compilecommand_iterator_stops():
>> +    """Check that iterator stops after the correct number of elements"""
>> +    cdb = CompilationDatabase.fromDirectory(kInputsDir)
>> +    count = 0
>> +    for cmd in cdb.getCompileCommands('/home/john.doe/MyProject/project2.cpp'):
>> +        count += 1
>> +        assert count <= 2
>> +
>> def test_compilationDB_references():
>>     """Ensure CompilationsCommands are independent of the database"""
>>     cdb = CompilationDatabase.fromDirectory(kInputsDir)






More information about the cfe-commits mailing list