This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Improve handling of pool_options::largest_required_pool_block
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 13 Nov 2018 23:44:44 +0000
- Subject: Re: [PATCH] Improve handling of pool_options::largest_required_pool_block
- References: <20181113225909.GA23808@redhat.com>
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.
commit 01882ab88871d2bcb34ad141505b96b317eefccb
Author: Jonathan Wakely <jwakely@redhat.com>
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;
}