mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
Add pretty printer for hashtables
This commit is contained in:
parent
2e8768d9a5
commit
2b8943237f
64
glib/glib.py
64
glib/glib.py
@ -69,6 +69,68 @@ class GListPrinter:
|
||||
def display_hint (self):
|
||||
return "array"
|
||||
|
||||
class GHashPrinter:
|
||||
"Prints a GHashTable"
|
||||
|
||||
class _iterator:
|
||||
def __init__(self, ht, keys_are_strings):
|
||||
self.ht = ht
|
||||
if ht != 0:
|
||||
self.array = ht["nodes"]
|
||||
self.size = ht["size"]
|
||||
self.pos = 0
|
||||
self.keys_are_strings = keys_are_strings
|
||||
self.value = None
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
if self.ht == 0:
|
||||
raise StopIteration
|
||||
if self.value != None:
|
||||
v = self.value
|
||||
self.value = None
|
||||
return v
|
||||
while long(self.pos) < long(self.size):
|
||||
node = self.array[self.pos]
|
||||
self.pos = self.pos + 1
|
||||
if long (node["key_hash"]) >= 2:
|
||||
key = node["key"]
|
||||
val = node["value"]
|
||||
|
||||
if self.keys_are_strings:
|
||||
key = key.cast (gdb.lookup_type("char").pointer())
|
||||
|
||||
# Queue value for next result
|
||||
self.value = ('[%dv]'% (self.pos), val)
|
||||
|
||||
# Return key
|
||||
return ('[%dk]'% (self.pos), key)
|
||||
raise StopIteration
|
||||
|
||||
def __init__ (self, val):
|
||||
self.val = val
|
||||
self.keys_are_strings = False
|
||||
try:
|
||||
string_hash = read_global_var ("g_str_hash")
|
||||
except:
|
||||
try:
|
||||
string_hash = read_global_var ("IA__g_str_hash")
|
||||
except:
|
||||
string_hash = None
|
||||
if self.val != 0 and string_hash != None and self.val["hash_func"] == string_hash:
|
||||
self.keys_are_strings = True
|
||||
|
||||
def children(self):
|
||||
return self._iterator(self.val, self.keys_are_strings)
|
||||
|
||||
def to_string (self):
|
||||
return "0x%x" % (long(self.val))
|
||||
|
||||
def display_hint (self):
|
||||
return "map"
|
||||
|
||||
def pretty_printer_lookup (val):
|
||||
if is_g_type_instance (val):
|
||||
return GTypePrettyPrinter (val)
|
||||
@ -89,6 +151,8 @@ def pretty_printer_lookup (val):
|
||||
return GListPrinter(val, "GList")
|
||||
if t == "GSList":
|
||||
return GListPrinter(val, "GSList")
|
||||
if t == "GHashTable":
|
||||
return GHashPrinter(val)
|
||||
else:
|
||||
t = str(type)
|
||||
if t == "GList":
|
||||
|
Loading…
Reference in New Issue
Block a user