From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 51033 invoked by alias); 13 Nov 2018 23:44:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 51010 invoked by uid 89); 13 Nov 2018 23:44:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Nov 2018 23:44:47 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B43E688307; Tue, 13 Nov 2018 23:44:45 +0000 (UTC) Received: from localhost (unknown [10.33.36.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 623585C89D; Tue, 13 Nov 2018 23:44:45 +0000 (UTC) Date: Tue, 13 Nov 2018 23:44:00 -0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Improve handling of pool_options::largest_required_pool_block Message-ID: <20181113234444.GM3098@redhat.com> References: <20181113225909.GA23808@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ABTtc+pdwF7KHXCz" Content-Disposition: inline In-Reply-To: <20181113225909.GA23808@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.2 (2017-12-15) X-SW-Source: 2018-11/txt/msg01166.txt.bz2 --ABTtc+pdwF7KHXCz Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-length: 650 On 13/11/18 22:59 +0000, Jonathan Wakely wrote: >@@ -898,9 +907,10 @@ namespace pmr > { > auto p = std::lower_bound(std::begin(pool_sizes), std::end(pool_sizes), > opts.largest_required_pool_block); >- if (int npools = p - std::begin(pool_sizes)) >- return npools; >- return 1; >+ const int n = p - std::begin(pool_sizes); >+ if (p == std::end(pool_sizes) || *p == opts.largest_required_pool_block) This is wrong, it still chooses one pool too few when the block_size matches an element of pool_sizes[]. >+ return n; >+ return n + 1; > } Fixed by this patch, tested x86_64-linux and committed to trunk. --ABTtc+pdwF7KHXCz Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-length: 938 commit 01882ab88871d2bcb34ad141505b96b317eefccb Author: Jonathan Wakely Date: Tue Nov 13 23:26:08 2018 +0000 Fix error when selecting number of memory pools * src/c++17/memory_resource.cc (select_num_pools): Fix off-by-one error when block_size is equal to one of the values in the array. diff --git a/libstdc++-v3/src/c++17/memory_resource.cc b/libstdc++-v3/src/c++17/memory_resource.cc index cb91e5147ce..605bdd53950 100644 --- a/libstdc++-v3/src/c++17/memory_resource.cc +++ b/libstdc++-v3/src/c++17/memory_resource.cc @@ -892,7 +892,7 @@ namespace pmr auto p = std::lower_bound(std::begin(pool_sizes), std::end(pool_sizes), opts.largest_required_pool_block); const int n = p - std::begin(pool_sizes); - if (p == std::end(pool_sizes) || *p == opts.largest_required_pool_block) + if (p == std::end(pool_sizes)) return n; return n + 1; } --ABTtc+pdwF7KHXCz--