Patchwork PR libstdc++/55041 update python printers

login
register
mail settings
Submitter Jonathan Wakely
Date Oct. 28, 2012, 1:20 p.m.
Message ID <CAH6eHdRavVbb8ybQSnaYh9mPpV56CSgMSHdjX3xaxfyM0YRGag@mail.gmail.com>
Download mbox | patch
Permalink /patch/194700/
State New
Headers show

Comments

Jonathan Wakely - Oct. 28, 2012, 1:20 p.m.
This fixes part of PR 55041 by updating the hash table printers to
account for Francois's recent changes.

        PR libstdc++/55041
        * python/libstdcxx/v6/printers.py (Tr1UnorderedMapPrinter): Update
        to handle hashtable as member of unordered_map not base class.
        (Tr1UnorderedSetPrinter): Likewise.

Tested x86_64-linux and committed to trunk.
commit a554179e10f867f983ca1915455ceb23a9edad3d
Author: Jonathan Wakely <jwakely.gcc@gmail.com>
Date:   Sun Oct 28 13:16:31 2012 +0000

    	PR libstdc++/55041
    	* python/libstdcxx/v6/printers.py (Tr1UnorderedMapPrinter): Update
    	to handle hashtable as member of unordered_map not base class.
    	(Tr1UnorderedSetPrinter): Likewise.

Patch

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 0eac413..07a5ee6 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -633,8 +633,13 @@  class Tr1UnorderedSetPrinter:
         self.typename = typename
         self.val = val
 
+    def hashtable (self):
+        if self.typename.startswith('std::tr1'):
+            return self.val
+        return self.val['_M_h']
+
     def to_string (self):
-        return '%s with %d elements' % (self.typename, self.val['_M_element_count'])
+        return '%s with %d elements' % (self.typename, self.hashtable()['_M_element_count'])
 
     @staticmethod
     def format_count (i):
@@ -642,7 +647,7 @@  class Tr1UnorderedSetPrinter:
 
     def children (self):
         counter = itertools.imap (self.format_count, itertools.count())
-        return itertools.izip (counter, Tr1HashtableIterator (self.val))
+        return itertools.izip (counter, Tr1HashtableIterator (self.hashtable()))
 
 class Tr1UnorderedMapPrinter:
     "Print a tr1::unordered_map"
@@ -651,8 +656,13 @@  class Tr1UnorderedMapPrinter:
         self.typename = typename
         self.val = val
 
+    def hashtable (self):
+        if self.typename.startswith('std::tr1'):
+            return self.val
+        return self.val['_M_h']
+
     def to_string (self):
-        return '%s with %d elements' % (self.typename, self.val['_M_element_count'])
+        return '%s with %d elements' % (self.typename, self.hashtable()['_M_element_count'])
 
     @staticmethod
     def flatten (list):
@@ -671,7 +681,7 @@  class Tr1UnorderedMapPrinter:
     def children (self):
         counter = itertools.imap (self.format_count, itertools.count())
         # Map over the hash table and flatten the result.
-        data = self.flatten (itertools.imap (self.format_one, Tr1HashtableIterator (self.val)))
+        data = self.flatten (itertools.imap (self.format_one, Tr1HashtableIterator (self.hashtable())))
         # Zip the two iterators together.
         return itertools.izip (counter, data)