[cfe-commits] [PATCH] python bindings: Fix infinite iteration of compilation database CompileCommands
Arnaud de Grandmaison
arnaud.allarddegrandmaison at parrot.com
Mon Jul 9 02:22:50 PDT 2012
Good catch.
Do you want me to commit your patch ?
Cheers,
--
Arnaud de Grandmaison
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)
--
Arnaud de Grandmaison
Senior CPU engineer
Business Unit Digital Tuner
Parrot S.A.
174, quai de Jemmapes
75010 Paris - France
Phone: +33 1 48 03 84 59
More information about the cfe-commits
mailing list