nogc v0.5.0 - DIP1008 works!

Atila Neves atila.neves at gmail.com
Fri May 24 11:41:12 UTC 2019


I'd been holding off on announcing this until DIP1008 actually 
got implemented, and now it has:

https://code.dlang.org/packages/nogc

This dub package has a @nogc version of `std.conv.text` (which 
probably isn't as good yet) that, instead of returning a `string` 
returns an `automem.vector.Vector` of char. This handles managing 
memory allocation for the exception message itself in 
`NoGcException`, which does what it says on the tin. Confused? 
Here's some code:


@safe @nogc unittest {
     import nogc;
     import std.algorithm: equal;

     int a = 1, b = 2;
     try
         enforce(a == b, a, " was not equal to ", b);
     catch(NoGcException e) {
         assert(equal(e.msg, "1 was not equal to 2"));
     }

     try
         throw new NoGcException(42, " foobar ", 33.3);
     catch(NoGcException e) {
         assert(equal(e.msg, "42 foobar 33.300000"));
         assert(e.file == __FILE__);
         assert(e.line == __LINE__ - 4);
     }
}

It doesn't leak memory either, as proved by ldc's asan.



More information about the Digitalmars-d-announce mailing list