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

Fix Issue 18848 - std.allocator: Regions are non-copyable, yet are pa… #6509

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions std/experimental/allocator/building_blocks/free_list.d
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,9 @@ struct ContiguousFreeList(ParentAllocator,
import std.experimental.allocator.building_blocks.region : Region;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.typecons : Ternary;
alias A = ContiguousFreeList!(Region!GCAllocator, 0, 64);
auto a = A(Region!GCAllocator(1024 * 4), 1024);
alias A = ContiguousFreeList!(Region!GCAllocator*, 0, 64);
auto r = Region!GCAllocator(1024 * 4);
auto a = A(&r, 1024);

assert((() nothrow @safe @nogc => a.empty)() == Ternary.yes);

Expand Down
12 changes: 7 additions & 5 deletions std/experimental/allocator/building_blocks/region.d
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ struct Region(ParentAllocator = NullAllocator,
this(cast(ubyte[]) (parent.allocate(n.roundUpToAlignment(alignment))));
}

/*
TODO: The postblit of `BasicRegion` should be disabled because such objects
should not be copied around naively.
*/

/**
If `ParentAllocator` is not $(REF_ALTTEXT `NullAllocator`, NullAllocator, std,experimental,allocator,building_blocks,null_allocator) and defines `deallocate`,
the region defines a destructor that uses `ParentAllocator.deallocate` to free the
Expand All @@ -113,6 +108,13 @@ struct Region(ParentAllocator = NullAllocator,
parent.deallocate(_begin[0 .. _end - _begin]);
}

/**
`Region` deallocates on destruction (see above), therefore is not copyable.
*/
static if (!is(ParentAllocator == NullAllocator)
&& hasMember!(ParentAllocator, "deallocate"))
@disable this(this);

/**
Rounds the given size to a multiple of the `alignment`
*/
Expand Down