From patchwork Thu Oct 18 20:13:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 192430 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 2FC682C0089 for ; Fri, 19 Oct 2012 07:14:00 +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=1351196041; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC: Subject:References:In-Reply-To:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=Ijto2amPKbbN5gAEG/stTswAizo=; b=JQiasyqi1BYieTHm0R7K9TwP7yIYA1NjY9PrzzJEQKh0IosYBSknL8TKZD+v6G EpTQXTzqtLzUbp5Aty0PfU2AyQjP0kM3GtIHfJZ+J3dFuC1EBWh1YzZUpKqwcWQA TG1W0BB8dwv1LqBgoDRzEiQB66KNQQ91D7UTxsyTWXKg8= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=OPH/IUieRclx0xUpVdBOdu5JUPBaTeOgiQYLhGkYg44Ni7RNspWmlXfRfZ41o1 hbISHn+NRpGIr9xeG0FUksBtpDG2BlUXF1xKwMnmAvTQLXwKI18RXI+sVAqkC3kV fM0Wz4ctsh/me4LwfA6M3G+3rt/3lY328cYWceWDA6P0E=; Received: (qmail 9003 invoked by alias); 18 Oct 2012 20:13:53 -0000 Received: (qmail 8956 invoked by uid 22791); 18 Oct 2012 20:13:52 -0000 X-SWARE-Spam-Status: No, hits=-3.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, URIBL_BLACK X-Spam-Check-By: sourceware.org Received: from mail-ea0-f175.google.com (HELO mail-ea0-f175.google.com) (209.85.215.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 18 Oct 2012 20:13:45 +0000 Received: by mail-ea0-f175.google.com with SMTP id c1so2430712eaa.20 for ; Thu, 18 Oct 2012 13:13:43 -0700 (PDT) Received: by 10.14.182.5 with SMTP id n5mr818481eem.5.1350591223800; Thu, 18 Oct 2012 13:13:43 -0700 (PDT) Received: from localhost.localdomain ([82.237.250.248]) by mx.google.com with ESMTPS id 42sm41546337eee.0.2012.10.18.13.13.41 (version=SSLv3 cipher=OTHER); Thu, 18 Oct 2012 13:13:42 -0700 (PDT) Message-ID: <508062F2.3070206@gmail.com> Date: Thu, 18 Oct 2012 22:13:38 +0200 From: =?ISO-8859-1?Q?Fran=E7ois_Dumont?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120829 Thunderbird/15.0 MIME-Version: 1.0 To: Paolo Carlini CC: "libstdc++@gcc.gnu.org" , gcc-patches Subject: Re: Yet another debug check for unordered containers References: <507F0F7E.6080208@gmail.com> <507FC80E.9050304@oracle.com> In-Reply-To: <507FC80E.9050304@oracle.com> 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 On 10/18/2012 11:12 AM, Paolo Carlini wrote: > On 10/17/2012 10:05 PM, François Dumont wrote: >> Ok to commit ? > Ok, thanks. > > Paolo. > Attached patch applied. 2012-10-18 François Dumont * include/debug/formatter.h (_Debug_msg_id): Add __msg_valid_load_factor. * include/debug/macros.h (__glibcxx_check_max_load_factor): New. * include/debug/unordered_set (unordered_set<>::max_load_factor(float)): Check max load factor is positive. (unordered_multiset<>::max_load_factor(float)): Likewise. * include/debug/unordered_map (unordered_map<>::max_load_factor(float)): Likewise. (unordered_multimap<>::max_load_factor(float)): Likewise. * testsuite/23_containers/unordered_map/debug/max_load_factor_neg.cc: New. * testsuite/23_containers/unordered_multimap/debug/ max_load_factor_neg.cc: New. * testsuite/23_containers/unordered_set/debug/max_load_factor_neg.cc: New. * testsuite/23_containers/unordered_multiset/debug/ max_load_factor_neg.cc: New. François Index: src/c++11/debug.cc =================================================================== --- src/c++11/debug.cc (revision 192512) +++ src/c++11/debug.cc (working copy) @@ -180,7 +180,8 @@ "function requires a non-empty iterator range [%1.name;, %2.name;)", "attempt to self move assign", "attempt to access container with out-of-bounds bucket index %2;," - " container only holds %3; buckets" + " container only holds %3; buckets", + "load factor shall be positive" }; void Index: include/debug/formatter.h =================================================================== --- include/debug/formatter.h (revision 192512) +++ include/debug/formatter.h (working copy) @@ -113,7 +113,8 @@ // self move assign __msg_self_move_assign, // unordered container buckets - __msg_bucket_index_oob + __msg_bucket_index_oob, + __msg_valid_load_factor }; class _Error_formatter Index: include/debug/unordered_set =================================================================== --- include/debug/unordered_set (revision 192512) +++ include/debug/unordered_set (working copy) @@ -230,6 +230,17 @@ return _Base::bucket_size(__b); } + float + max_load_factor() const noexcept + { return _Base::max_load_factor(); } + + void + max_load_factor(float __f) + { + __glibcxx_check_max_load_factor(__f); + _Base::max_load_factor(__f); + } + template std::pair emplace(_Args&&... __args) @@ -665,6 +676,17 @@ return _Base::bucket_size(__b); } + float + max_load_factor() const noexcept + { return _Base::max_load_factor(); } + + void + max_load_factor(float __f) + { + __glibcxx_check_max_load_factor(__f); + _Base::max_load_factor(__f); + } + template iterator emplace(_Args&&... __args) Index: include/debug/macros.h =================================================================== --- include/debug/macros.h (revision 192512) +++ include/debug/macros.h (working copy) @@ -324,9 +324,15 @@ // Verify that the container is not self move assigned #define __glibcxx_check_self_move_assign(_Other) \ _GLIBCXX_DEBUG_VERIFY(this != &_Other, \ - _M_message(__gnu_debug::__msg_self_move_assign) \ + _M_message(__gnu_debug::__msg_self_move_assign) \ ._M_sequence(*this, "this")) +// Verify that load factor is position +#define __glibcxx_check_max_load_factor(_F) \ +_GLIBCXX_DEBUG_VERIFY(_F > 0.0f, \ + _M_message(__gnu_debug::__msg_valid_load_factor) \ + ._M_sequence(*this, "this")) + #ifdef _GLIBCXX_DEBUG_PEDANTIC # define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_ASSERT(_String != 0) # define __glibcxx_check_string_len(_String,_Len) \ Index: include/debug/unordered_map =================================================================== --- include/debug/unordered_map (revision 192512) +++ include/debug/unordered_map (working copy) @@ -230,6 +230,17 @@ return _Base::bucket_size(__b); } + float + max_load_factor() const noexcept + { return _Base::max_load_factor(); } + + void + max_load_factor(float __f) + { + __glibcxx_check_max_load_factor(__f); + _Base::max_load_factor(__f); + } + template std::pair emplace(_Args&&... __args) @@ -670,6 +681,17 @@ return _Base::bucket_size(__b); } + float + max_load_factor() const noexcept + { return _Base::max_load_factor(); } + + void + max_load_factor(float __f) + { + __glibcxx_check_max_load_factor(__f); + _Base::max_load_factor(__f); + } + template iterator emplace(_Args&&... __args) Index: testsuite/23_containers/unordered_map/debug/max_load_factor_neg.cc =================================================================== --- testsuite/23_containers/unordered_map/debug/max_load_factor_neg.cc (revision 0) +++ testsuite/23_containers/unordered_map/debug/max_load_factor_neg.cc (revision 0) @@ -0,0 +1,34 @@ +// Copyright (C) 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 +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . +// +// { dg-require-debug-mode "" } +// { dg-options "-std=c++11" } +// { dg-do run { xfail *-*-* } } + +#include + +void test01() +{ + std::unordered_multimap um; + um.max_load_factor(-1.0f); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/unordered_multimap/debug/max_load_factor_neg.cc =================================================================== --- testsuite/23_containers/unordered_multimap/debug/max_load_factor_neg.cc (revision 0) +++ testsuite/23_containers/unordered_multimap/debug/max_load_factor_neg.cc (revision 0) @@ -0,0 +1,34 @@ +// Copyright (C) 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 +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . +// +// { dg-require-debug-mode "" } +// { dg-options "-std=c++11" } +// { dg-do run { xfail *-*-* } } + +#include + +void test01() +{ + std::unordered_map um; + um.max_load_factor(-1.0f); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/unordered_multiset/debug/max_load_factor_neg.cc =================================================================== --- testsuite/23_containers/unordered_multiset/debug/max_load_factor_neg.cc (revision 0) +++ testsuite/23_containers/unordered_multiset/debug/max_load_factor_neg.cc (revision 0) @@ -0,0 +1,34 @@ +// Copyright (C) 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 +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . +// +// { dg-require-debug-mode "" } +// { dg-options "-std=c++11" } +// { dg-do run { xfail *-*-* } } + +#include + +void test01() +{ + std::unordered_multiset us; + us.max_load_factor(-1.0f); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/unordered_set/debug/max_load_factor_neg.cc =================================================================== --- testsuite/23_containers/unordered_set/debug/max_load_factor_neg.cc (revision 0) +++ testsuite/23_containers/unordered_set/debug/max_load_factor_neg.cc (revision 0) @@ -0,0 +1,34 @@ +// Copyright (C) 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 +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . +// +// { dg-require-debug-mode "" } +// { dg-options "-std=c++11" } +// { dg-do run { xfail *-*-* } } + +#include + +void test01() +{ + std::unordered_set us; + us.max_load_factor(-1.0f); +} + +int main() +{ + test01(); + return 0; +}