From 6eef8e01c7654acf417d3ad81fb6cb5cfc6edc2f Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 4 Sep 2019 18:59:13 +0000 Subject: [PATCH] [Python] Implement __next__ for value_iter Python 3 iteration calls the next() method instead of next() and value_iter only implemented the Python 2 version. Differential revision: https://reviews.llvm.org/D67184 llvm-svn: 370954 --- .../Python/lldbsuite/test/python_api/value/TestValueAPI.py | 7 +++++++ lldb/scripts/Python/python-extensions.swig | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py b/lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py index d67905a..bf8cbe3 100644 --- a/lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py +++ b/lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py @@ -169,6 +169,13 @@ class ValueAPITestCase(TestBase): self.assertTrue(int(lldb.value(frame0.FindVariable('sinthex'))) == -526164208, 'sinthex == -526164208') + # Check value_iter works correctly. + for v in [ + lldb.value(frame0.FindVariable('uinthex')), + lldb.value(frame0.FindVariable('sinthex')) + ]: + self.assertTrue(v) + self.assertTrue( frame0.FindVariable('uinthex').GetValueAsUnsigned() == 3768803088, 'unsigned uinthex == 3768803088') diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig index 13bb582..7823dc4 100644 --- a/lldb/scripts/Python/python-extensions.swig +++ b/lldb/scripts/Python/python-extensions.swig @@ -946,13 +946,16 @@ class value_iter(object): def __iter__(self): return self - def next(self): + def __next__(self): if self.index >= self.length: raise StopIteration() child_sbvalue = self.sbvalue.GetChildAtIndex(self.index) self.index += 1 return value(child_sbvalue) + def next(self): + return self.__next__() + def __init__(self,value): self.index = 0 self.sbvalue = value -- 2.7.4