Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pool resources: respect max_blocks_per_chunk #3510

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions stl/inc/memory_resource
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ namespace pmr {

void _Increase_capacity(unsynchronized_pool_resource& _Pool_resource) {
// this pool has no free blocks; get a new chunk from upstream
if (_Next_capacity > _Pool_resource._Options.max_blocks_per_chunk) {
// This is a fresh pool, _Next_capacity hasn't yet been bounded by max_blocks_per_chunk:
_Next_capacity = _Pool_resource._Options.max_blocks_per_chunk;
}
const size_t _Size = _Size_for_capacity(_Next_capacity);
memory_resource* const _Resource = _Pool_resource.upstream_resource();
void* const _Ptr = _Resource->allocate(_Size, _Block_size);
Expand Down
15 changes: 15 additions & 0 deletions tests/std/tests/P0220R1_polymorphic_memory_resources/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,19 @@ namespace {
al.construct(static_cast<const volatile PairType*>(raw_ptr), mem_pair_conv{});
}
} // namespace map_containers

void test_gh3408() {
// We ignored the possibility that max_blocks_per_chunk could be less than _Default_next_capacity
recording_resource upstream;
std::pmr::pool_options options{};
options.max_blocks_per_chunk = 1;
std::pmr::unsynchronized_pool_resource res{options, &upstream};
const std::size_t size = 0x8009;
(void) res.allocate(size);
const allocation& alloc = upstream.allocations_[upstream.allocations_.size() - 1];
CHECK(alloc.size >= 0x10000);
CHECK(alloc.size < 2 * 0x10000);
}
} // unnamed namespace

int main() {
Expand Down Expand Up @@ -1591,4 +1604,6 @@ int main() {
map_containers::test();

map_containers::lwg3677_test();

test_gh3408();
}