From patchwork Tue Feb 14 20:16:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 141181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 8BEAB1007D1 for ; Wed, 15 Feb 2012 07:16:55 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1329855416; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Subject:CC:Date:Message-ID:User-Agent: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=53irGTkOSpvQsgjWuXgi+rWdY5o=; b=IXgfjtl7fyIxWoj hbLznOCBbgAbmObHDplIKCQLIJzqKT28p5LfI54/ny4KNeS+WV2aDn1r+OkVn4JS c+CbSqVCx3qdUrzYdEAYASUtjET9Xt07Wh0nhEgq/zgA2gte5VI/CHIYpW9BIfof U7J4fbJZM4tig0/Bh3YFfRSVstTw= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Subject:CC:Date:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=SZodTgysFrP8fiZ74AlEVaGHEW8PKVQCc9d3NBNuMAOoAb1FlwLVu+9bw37ofj hz2QyNmfTasvomYUOXClDipgtnkd4IG5sNX6fJx91yZ9epKT4q/5aBMipbLTltdl bfqQro5NVSSOa0+9rYKI3aejXmtymERtC1EkDZKC1u5AA=; Received: (qmail 7130 invoked by alias); 14 Feb 2012 20:16:42 -0000 Received: (qmail 7110 invoked by uid 22791); 14 Feb 2012 20:16:38 -0000 X-SWARE-Spam-Status: No, hits=-7.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Feb 2012 20:16:25 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q1EKGPhP005402 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 14 Feb 2012 15:16:25 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q1EKGOBo026212; Tue, 14 Feb 2012 15:16:24 -0500 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id q1EKGNEL012359; Tue, 14 Feb 2012 15:16:23 -0500 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: Patch: fix std::unordered_map (et al) pretty printer CC: libstdc Date: Tue, 14 Feb 2012 13:16:22 -0700 Message-ID: <8739adp3vt.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.93 (gnu/linux) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Jakub mentioned a while back that the std::unordered_map pretty printer in libstdc++ was not working properly. This patch fixes the problems with this printer (and other printers using Tr1HashtableIterator). The problem was incorrect iteration of the hash table; I think all the nodes in the hash table are linked together via their _M_nxt fields, so I have simplified the iterator to just do this. I've included some new test cases. Tested on x86-64 Fedora 16. Ok? Tom 2012-02-14 Tom Tromey * testsuite/libstdc++-prettyprinters/cxx11.cc (main): Add new tests. * python/libstdcxx/v6/printers.py (Tr1HashtableIterator.__init__): Rewrite. (Tr1HashtableIterator.update): Remove. (Tr1HashtableIterator.next): Rewrite. Index: python/libstdcxx/v6/printers.py =================================================================== --- python/libstdcxx/v6/printers.py (revision 184215) +++ python/libstdcxx/v6/printers.py (working copy) @@ -610,38 +610,18 @@ class Tr1HashtableIterator: def __init__ (self, hash): - self.count = 0 - self.n_buckets = hash['_M_element_count'] - if self.n_buckets == 0: - self.node = False - else: - self.bucket = hash['_M_buckets'] - self.node = self.bucket[0] - self.update () + self.node = hash['_M_before_begin']['_M_nxt'] + self.node_type = find_type(hash.type, '_Node').pointer() def __iter__ (self): return self - def update (self): - # If we advanced off the end of the chain, move to the next - # bucket. - 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 - def next (self): - if not self.node: + if self.node == 0: raise StopIteration - result = self.node.dereference()['_M_v'] - self.node = self.node.dereference()['_M_next'] - self.update () + node = self.node.cast(self.node_type) + result = node.dereference()['_M_v'] + self.node = node.dereference()['_M_nxt'] return result class Tr1UnorderedSetPrinter: Index: testsuite/libstdc++-prettyprinters/cxx11.cc =================================================================== --- testsuite/libstdc++-prettyprinters/cxx11.cc (revision 184215) +++ testsuite/libstdc++-prettyprinters/cxx11.cc (working copy) @@ -1,7 +1,7 @@ // { dg-do run } // { dg-options "-std=gnu++11 -g" } -// Copyright (C) 2011 Free Software Foundation, Inc. +// Copyright (C) 2011, 2012 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -68,6 +68,24 @@ std::unordered_multiset eums; // { dg-final { note-test eums "std::unordered_multiset with 0 elements" } } + std::unordered_map uom; + uom[5] = "three"; + uom[3] = "seven"; +// { dg-final { note-test uom {std::unordered_map with 2 elements = {[3] = "seven", [5] = "three"}} } } + + std::unordered_multimap uomm; + uomm.insert(std::pair (5, "three")); + uomm.insert(std::pair (5, "seven")); +// { dg-final { note-test uomm {std::unordered_multimap with 2 elements = {[5] = "seven", [5] = "three"}} } } + + std::unordered_set uos; + uos.insert(5); +// { dg-final { note-test uos {std::unordered_set with 1 elements = {[0] = 5}} } } + + std::unordered_multiset uoms; + uoms.insert(5); +// { dg-final { note-test uoms {std::unordered_multiset with 1 elements = {[0] = 5}} } } + placeholder(""); // Mark SPOT use(efl); use(fl);