Skip to content
Merged
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
16 changes: 14 additions & 2 deletions std/experimental/allocator/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ module std.experimental.allocator;
public import std.experimental.allocator.common,
std.experimental.allocator.typed;

// Fix issue 17806: this should always be the first unittest in this module
// in order to ensure that we use the `processAllocator` setter before the getter
@system unittest
{
import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator.gc_allocator : GCAllocator;
auto newAlloc = sharedAllocatorObject(Mallocator.instance);
processAllocator = newAlloc;
assert(processAllocator is newAlloc);
processAllocator = sharedAllocatorObject(GCAllocator.instance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not implicitly assume that it was the GCAllocator before and just reset it to the old value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would require the setter to return the previous allocator, which it currently doesn't. In order to change the API to do this, we'd need to guard with a lock. We can regard this as a best effort.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would require the setter to return the previous allocator, which it currently doesn't.

That would also be a potential landmine since for basic types the result of (a = b) is the post-modification value of a, not the pre-modification value of a.

}

// Example in the synopsis above
@system unittest
{
Expand Down Expand Up @@ -1058,10 +1070,10 @@ allocator can be cast to `shared`.

/// Ditto
@nogc nothrow @system
@property void processAllocator(RCISharedAllocator a)
@property void processAllocator(ref RCISharedAllocator a)
{
assert(!a.isNull);
_processAllocator = a;
processAllocator() = a;
}

@system unittest
Expand Down