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: 9 additions & 7 deletions std/experimental/allocator/mmap_allocator.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ struct MmapAllocator
version(Posix)
{
/// Allocator API.
nothrow @nogc @safe
void[] allocate(size_t bytes) shared
{
import core.sys.posix.sys.mman : mmap, MAP_ANON, PROT_READ,
PROT_WRITE, MAP_PRIVATE, MAP_FAILED;
if (!bytes) return null;
auto p = mmap(null, bytes, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
auto p = (() @trusted => mmap(null, bytes, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0))();
if (p is MAP_FAILED) return null;
return p[0 .. bytes];
return (() @trusted => p[0 .. bytes])();
}

/// Ditto
Expand All @@ -54,13 +55,14 @@ struct MmapAllocator
PAGE_READWRITE, MEM_RELEASE;

/// Allocator API.
nothrow @nogc @safe
void[] allocate(size_t bytes) shared
{
if (!bytes) return null;
auto p = VirtualAlloc(null, bytes, MEM_COMMIT, PAGE_READWRITE);
auto p = (() @trusted => VirtualAlloc(null, bytes, MEM_COMMIT, PAGE_READWRITE))();
if (p == null)
return null;
return p[0 .. bytes];
return (() @trusted => p[0 .. bytes])();
}

/// Ditto
Expand All @@ -72,10 +74,10 @@ struct MmapAllocator
}
}

@system unittest
nothrow @safe @nogc unittest
{
alias alloc = MmapAllocator.instance;
auto p = alloc.allocate(100);
assert(p.length == 100);
() nothrow @nogc { alloc.deallocate(p); }();
() @trusted { alloc.deallocate(p); p = null; }();
Copy link
Member

Choose a reason for hiding this comment

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

@aG0aep6G good point, operated the change myself

}