[Issue 16250] New: GCAllocator should be at least @safe, nothrow

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jul 7 15:18:19 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16250

          Issue ID: 16250
           Summary: GCAllocator should be at least @safe, nothrow
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: safe
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: greensunny12 at gmail.com

A common pattern for future APIs would be to allow to pass-in a custom
Allocator and have @safe and nothrow code if the GCAllocator was used. Ideally
I hope that the language might ease the use of custom allocators, but being
conveniently able to switch between safe and non-safe fast code would be a good
start. See e.g. this simple test for an example:

nothrow unittest
{
    import std.experimental.allocator: dispose, makeArray;
    import std.experimental.allocator.gc_allocator: GCAllocator;
    auto Allocator = GCAllocator.instance;

    auto safeFun() @safe
    {
        int[] arr = Allocator.makeArray!int(2);
        assert(arr == [0, 0]);
        return arr;
    }
    Allocator.dispose(safeFun());
}

Imho this test could also be `pure`, but that's not really important there .
There's is already an ongoing PR, but that lost its motion and needs to be
revived.

https://github.com/dlang/phobos/pull/3891


For no required shared in the GCAllocator, there is another ongoing effort: 
https://github.com/dlang/phobos/pull/4288

--


More information about the Digitalmars-d-bugs mailing list