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