This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[python] [ref] Patch for libstdcxx printer's Tr1HashtableIterator
- From: Phil Muldoon <pmuldoon at redhat dot com>
- To: Project Archer <archer at sourceware dot org>
- Date: Fri, 20 Feb 2009 16:15:10 +0000
- Subject: [python] [ref] Patch for libstdcxx printer's Tr1HashtableIterator
Please find enclosed patch for Tr1HashtableIterator. This is used by
both Tr1UnorderedSetPrinter and Tr1UnorderedMapPrinter.
Two small fixes:
- The first Tom pointed out a few weeks ago. The number of buckets was
sourcing the count from the incorrect variable.
- The second fix concerns iterating through the buckets in the class.
Both the increment of self.count, and the comparison to self.n_buckets
should have been done outside of the loop. Otherwise self.count will be
incorrect (it will be the cumulative count between buckets, not the
count of buckets that have been iterated.)
Thanks
Phil
2009-02-20 Phil Muldoon <pmuldoon@redhat.com>
* python/lib/gdb/libstdcxx/v6/printers.py
(Tr1HashtableIterator.update): Only increment self.count after
self.node == 0.
(Tr1HashtableIterator.__init__): Source number of buckets from
_M_element_count.
diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
index b8c6d6f..701eec2 100644
--- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py
+++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
@@ -464,7 +464,7 @@ class StdStringPrinter:
class Tr1HashtableIterator:
def __init__ (self, hash):
self.count = 0
- self.n_buckets = hash['_M_bucket_count']
+ self.n_buckets = hash['_M_element_count']
if self.n_buckets == 0:
self.node = False
else:
@@ -481,11 +481,13 @@ class Tr1HashtableIterator:
while self.node == 0:
self.bucket = self.bucket + 1
self.node = self.bucket[0]
+
+ # If we advanced off the end of the bucket array, then
+ # we're done.
+ if self.count == self.n_buckets:
+ self.node = False
+ else:
self.count = self.count + 1
- # If we advanced off the end of the bucket array, then
- # we're done.
- if self.count == self.n_buckets:
- self.node = False
def next (self):
if not self.node: