Skip to content

Commit a5ffceb

Browse files
JDevlieghereadrian-prantl
authored andcommitted
[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 (cherry picked from commit 6eef8e0)
1 parent 5fad792 commit a5ffceb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ def test(self):
169169
self.assertTrue(int(lldb.value(frame0.FindVariable('sinthex')))
170170
== -526164208, 'sinthex == -526164208')
171171

172+
# Check value_iter works correctly.
173+
for v in [
174+
lldb.value(frame0.FindVariable('uinthex')),
175+
lldb.value(frame0.FindVariable('sinthex'))
176+
]:
177+
self.assertTrue(v)
178+
172179
self.assertTrue(
173180
frame0.FindVariable('uinthex').GetValueAsUnsigned() == 3768803088,
174181
'unsigned uinthex == 3768803088')

lldb/scripts/Python/python-extensions.swig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,13 +946,16 @@ class value_iter(object):
946946
def __iter__(self):
947947
return self
948948

949-
def next(self):
949+
def __next__(self):
950950
if self.index >= self.length:
951951
raise StopIteration()
952952
child_sbvalue = self.sbvalue.GetChildAtIndex(self.index)
953953
self.index += 1
954954
return value(child_sbvalue)
955955

956+
def next(self):
957+
return self.__next__()
958+
956959
def __init__(self,value):
957960
self.index = 0
958961
self.sbvalue = value

0 commit comments

Comments
 (0)