diff --git a/std/experimental/allocator/mmap_allocator.d b/std/experimental/allocator/mmap_allocator.d index a35847cbf04..0867cd3f861 100644 --- a/std/experimental/allocator/mmap_allocator.d +++ b/std/experimental/allocator/mmap_allocator.d @@ -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 @@ -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 @@ -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; }(); }