Index: libcxx/test/pretty_printers/gdb_pretty_printer_test.py =================================================================== --- libcxx/test/pretty_printers/gdb_pretty_printer_test.py +++ libcxx/test/pretty_printers/gdb_pretty_printer_test.py @@ -17,6 +17,13 @@ from __future__ import print_function import re import gdb +import sys + +if sys.version_info >= (3, 0): + py3k = True +else: + py3k = False + test_failures = 0 @@ -50,8 +57,11 @@ check_literal = expectation_val.string() test_fails = not re.match(check_literal, value) else: - check_literal_string = expectation_val.string(encoding="utf-8") - check_literal = check_literal_string.encode("utf-8") + if not py3k: + check_literal_string = expectation_val.string(encoding="utf-8") + check_literal = check_literal_string.encode("utf-8") + else: + check_literal = expectation_val.string(encoding="utf-8") test_fails = value != check_literal if test_fails: Index: libcxx/utils/gdb/libcxx/printers.py =================================================================== --- libcxx/utils/gdb/libcxx/printers.py +++ libcxx/utils/gdb/libcxx/printers.py @@ -15,6 +15,12 @@ import re import gdb +import sys + +if sys.version_info >= (3, 0): + py3k = True +else: + py3k = False # One under-documented feature of the gdb pretty-printer API # is that clients can call any other member of the API @@ -136,13 +142,19 @@ def __iter__(self): return self - def next(self): + def __next__(self): # child_iter raises StopIteration when appropriate. - field_name = self.child_iter.next() + if not py3k: + field_name = self.child_iter.next() + else: + field_name = self.child_iter.__next__() child = self.val["__base_"][field_name]["__value_"] self.count += 1 return ("[%d]" % self.count, child) + if not py3k: + next = __next__ + def __init__(self, val): self.val = val @@ -315,7 +327,7 @@ def __iter__(self): return self - def next(self): + def __next__(self): """Retrieve the next element.""" self.count += 1 @@ -332,6 +344,9 @@ self.offset = 0 return ("[%d]" % self.count, outbit) + if not py3k: + next = __next__ + class _VectorIterator(object): """Class to iterate over the non-bool vector's children.""" @@ -343,7 +358,7 @@ def __iter__(self): return self - def next(self): + def __next__(self): self.count += 1 if self.item == self.end: raise StopIteration @@ -351,6 +366,9 @@ self.item += 1 return ("[%d]" % self.count, entry) + if not py3k: + next = __next__ + def __init__(self, val): """Set val, length, capacity, and iterator for bool and normal vectors.""" self.val = val @@ -404,7 +422,7 @@ while value: index += 1 will_yield = value % 2 - value /= 2 + value //= 2 if will_yield: yield index