Kaydet (Commit) c5b7cc95 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski Kaydeden (comit) Michael Stahl

Add Python 3 compatibility to GDB pretty printers.

GDB on *buntu is linked against Python 3.3, which has many
incompatibilities to Python 2, resulting in broken code.

This patch uses the Python six library as a compatibility layer.

Change-Id: Icb4cc54a1d05afb119376bb5e1430c91cb794d08
Reviewed-on: https://gerrit.libreoffice.org/6688Reviewed-by: 's avatarMichael Stahl <mstahl@redhat.com>
Tested-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst 46dbc131
......@@ -19,6 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import gdb
import six
class Unordered(object):
'''Common representation of Boost.Unordered types'''
......@@ -57,7 +58,7 @@ class Unordered(object):
assert node_type != None
return node_type
class _iterator(object):
class _iterator(six.Iterator):
'''Iterator for Boost.Unordered types'''
def __init__(self, first_bucket, last_bucket, node_type, extractor):
......@@ -71,7 +72,7 @@ class Unordered(object):
def __iter__(self):
return self
def next(self):
def __next__(self):
if self.node:
self.node = self.node.dereference()['next_']
......
......@@ -20,6 +20,7 @@
import gdb
import six
from boost.lib.unordered import Map, Set
......@@ -59,7 +60,7 @@ class PtrStdPrinterBase(object):
def children(self):
return self._iterator(self.sequence, self.value.type.template_argument(0))
class _iterator(object):
class _iterator(six.Iterator):
def __init__(self, sequence, type):
self.impl = iter(sequence)
......@@ -68,7 +69,7 @@ class PtrStdPrinterBase(object):
def __iter__(self):
return self
def next(self):
def __next__(self):
(index, value) = self.impl.next()
return (index, value.cast(self.type).dereference())
......@@ -124,7 +125,7 @@ class PtrMapPrinter(PtrStdPrinterBase):
type = self.value.type
return self._iterator(self.sequence, type.template_argument(0), type.template_argument(1))
class _iterator(object):
class _iterator(six.Iterator):
def __init__(self, sequence, key_type, value_type):
self.impl = iter(sequence)
......@@ -135,7 +136,7 @@ class PtrMapPrinter(PtrStdPrinterBase):
def __iter__(self):
return self
def next(self):
def __next__(self):
(index, value) = self.impl.next()
if self.key:
value = value.cast(self.key_type)
......@@ -176,7 +177,7 @@ class PtrUnorderedMapPrinter(PtrBoostPrinterBase):
def display_hint(self):
return 'map'
class _iterator(object):
class _iterator(six.Iterator):
def __init__(self, impl, value_type):
self.impl = impl
......@@ -187,7 +188,7 @@ class PtrUnorderedMapPrinter(PtrBoostPrinterBase):
def __iter__(self):
return self
def next(self):
def __next__(self):
if self.step:
self.value = self.impl.next()
value = self.value[0]
......@@ -205,7 +206,7 @@ class PtrUnorderedSetPrinter(PtrBoostPrinterBase):
def display_hint(self):
return 'array'
class _iterator(object):
class _iterator(six.Iterator):
def __init__(self, impl, value_type):
self.impl = impl
......@@ -214,7 +215,7 @@ class PtrUnorderedSetPrinter(PtrBoostPrinterBase):
def __iter__(self):
return self
def next(self):
def __next__(self):
return ("", self.impl.next()[1].cast(self.value_type).dereference())
printer = None
......
......@@ -20,6 +20,7 @@
import gdb
import six
from boost.lib.unordered import Map, Set
......@@ -50,7 +51,7 @@ class UnorderedMapPrinter(PrinterBase):
def display_hint(self):
return 'map'
class _iterator(object):
class _iterator(six.Iterator):
def __init__(self, impl):
self.impl = impl
......@@ -60,7 +61,7 @@ class UnorderedMapPrinter(PrinterBase):
def __iter__(self):
return self
def next(self):
def __next__(self):
if self.step:
self.value = self.impl.next()
value = self.value[0]
......@@ -77,7 +78,7 @@ class UnorderedSetPrinter(PrinterBase):
def display_hint(self):
return 'array'
class _iterator(object):
class _iterator(six.Iterator):
def __init__(self, impl):
self.impl = impl
......@@ -85,7 +86,7 @@ class UnorderedSetPrinter(PrinterBase):
def __iter__(self):
return self
def next(self):
def __next__(self):
return ("", self.impl.next()[1])
printer = None
......
......@@ -22,6 +22,7 @@
from collections import Mapping
import gdb
import re
import six
from boost.util.compatibility import use_gdb_printing
......@@ -85,7 +86,7 @@ class FunctionLookup(Mapping):
return len(self.map)
def __getitem__(self, type):
for (test, printer) in self.map.iteritems():
for (test, printer) in six.iteritems(self.map):
if test(type):
return printer
return None
......
......@@ -8,6 +8,7 @@
#
import gdb
import six
from libreoffice.util import printing
......@@ -73,7 +74,7 @@ class B2DPolygonPrinter(object):
else:
return self._plainIterator(self._count(), self.value)
class _plainIterator(object):
class _plainIterator(six.Iterator):
def __init__(self, count, value):
self.count = count
self.value = value
......@@ -82,7 +83,7 @@ class B2DPolygonPrinter(object):
def __iter__(self):
return self
def next(self):
def __next__(self):
if self.index >= self.count:
raise StopIteration()
currPoint = gdb.parse_and_eval(
......@@ -95,7 +96,7 @@ class B2DPolygonPrinter(object):
return ('point %d' % (self.index-1),
'(%15f, %15f)' % (currPoint['mfX'], currPoint['mfY']))
class _bezierIterator(object):
class _bezierIterator(six.Iterator):
def __init__(self, count, value):
self.count = count
self.value = value
......@@ -104,7 +105,7 @@ class B2DPolygonPrinter(object):
def __iter__(self):
return self
def next(self):
def __next__(self):
if self.index >= self.count:
raise StopIteration()
currPoint = gdb.parse_and_eval(
......
......@@ -7,6 +7,8 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
import six
from libreoffice.util import printing
from libreoffice.util.uno import TypeClass, make_uno_type, uno_cast
......@@ -58,7 +60,7 @@ class UnoReferencePrinter(object):
class UnoSequencePrinter(object):
'''Prints UNO Sequence'''
class iterator(object):
class iterator(six.Iterator):
'''Sequence iterator'''
def __init__(self, first, size):
......@@ -69,7 +71,7 @@ class UnoSequencePrinter(object):
def __iter__(self):
return self
def next(self):
def __next__(self):
if self.count == self.size:
raise StopIteration
count = self.count
......
......@@ -9,6 +9,7 @@
import gdb
import gdb.types
import six
from libreoffice.util import printing
from libreoffice.util.string import StringPrinterHelper
......@@ -86,7 +87,7 @@ class OslFileStatusPrinter(object):
if etype is not None:
pretty_etype = '<unknown type>' # in case it's not one of the fields
for field_name, field_val in fields_to_enum_val.iteritems():
for field_name, field_val in six.iteritems(fields_to_enum_val):
if etype == field_val:
pretty_etype = self.pretty_file_type(field_name)
else:
......
......@@ -8,6 +8,7 @@
#
import gdb
import six
from libreoffice.util import printing
......@@ -30,7 +31,7 @@ class SvArrayPrinter(object):
def display_hint(self):
return 'array'
class _iterator(object):
class _iterator(six.Iterator):
def __init__(self, data, count):
self.data = data
......@@ -41,7 +42,7 @@ class SvArrayPrinter(object):
def __iter__(self):
return self
def next(self):
def __next__(self):
if self.pos == self.count:
raise StopIteration()
......
......@@ -7,6 +7,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
import six
from libreoffice.util import printing
class SwPositionPrinter(object):
......@@ -205,7 +206,7 @@ class BigPtrArrayPrinter(object):
return 'array'
class _iterator(object):
class _iterator(six.Iterator):
def __init__(self, array):
self.blocks = array['ppInf']
......@@ -255,7 +256,7 @@ class BigPtrArrayPrinter(object):
return "\n[%4d] %s%s%s %s" % (self.pos, cur_indent, \
node, self.max_indent[len(cur_indent):], value)
def next(self):
def __next__(self):
if self.pos == self.count:
raise StopIteration()
......
......@@ -8,6 +8,7 @@
#
import gdb
import six
from libreoffice.util import printing
......@@ -159,7 +160,7 @@ class TimePrinter(object):
def to_string(self):
return str(TimeImpl.parse(self.val))
class IteratorHelper(object):
class IteratorHelper(six.Iterator):
'''Implements a container iterator useable for both 'linear'
containers (like DynArray or List) and Tables
'''
......@@ -179,7 +180,7 @@ class IteratorHelper(object):
def __iter__(self):
return self
def next(self):
def __next__(self):
if self.pos == self.count:
raise StopIteration()
......
......@@ -10,6 +10,7 @@
from collections import Mapping
import gdb
import re
import six
from libreoffice.util.compatibility import use_gdb_printing
......@@ -73,7 +74,7 @@ class FunctionLookup(Mapping):
return len(self.map)
def __getitem__(self, type):
for (test, printer) in self.map.iteritems():
for (test, printer) in six.iteritems(self.map):
if test(type):
return printer
return None
......
......@@ -9,6 +9,7 @@
import gdb
import re
import six
class UnsupportedType(Exception):
'''Represents exception thrown when an unsupported UNO type(like
......@@ -295,7 +296,7 @@ class CompoundType(Type):
self.typename = self.uno2cpp(self.tag)
self._type = full_type
class _iterator(object):
class _iterator(six.Iterator):
def __init__(self, count, types, names):
self.count = count
......@@ -306,7 +307,7 @@ class CompoundType(Type):
def __iter__(self):
return self
def next(self):
def __next__(self):
assert self.pos >= 0 and self.pos <= self.count
if self.pos == self.count:
raise StopIteration
......@@ -349,7 +350,7 @@ class EnumType(Type):
self.typename = self.uno2cpp(self.tag)
self._type = full_type.cast(gdb.lookup_type('_typelib_EnumTypeDescription'))
class _iterator(object):
class _iterator(six.Iterator):
def __init__(self, count, values, names):
self.count = count
......@@ -360,7 +361,7 @@ class EnumType(Type):
def __iter__(self):
return self
def next(self):
def __next__(self):
assert self.pos >= 0 and self.pos <= self.count
if self.pos == self.count:
raise StopIteration
......@@ -405,7 +406,7 @@ class InterfaceMethodType(InterfaceMemberType):
self.oneway = full_type['bOneWay']
self._type = full_type
class _iterator(object):
class _iterator(six.Iterator):
def __init__(self, count, values):
self.count = count
......@@ -416,7 +417,7 @@ class InterfaceMethodType(InterfaceMemberType):
def __iter__(self):
return self
def next(self):
def __next__(self):
assert self.pos >= 0 and self.pos <= self.count
if self.pos == self.count:
raise StopIteration
......@@ -484,7 +485,7 @@ class InterfaceType(Type):
self.uik = full_type['aUik']
self._type = full_type
class _iterator(object):
class _iterator(six.Iterator):
def __init__(self, count, values):
assert values
......@@ -495,7 +496,7 @@ class InterfaceType(Type):
def __iter__(self):
return self
def next(self):
def __next__(self):
assert self.pos >= 0 and self.pos <= self.count
pvalue = self.values[self.pos]
assert pvalue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment