DIP 1028---Make @safe the Default---Community Review Round 1

Walter Bright newshound2 at digitalmars.com
Fri Jan 3 11:39:14 UTC 2020

On 1/2/2020 11:40 PM, H. S. Teoh wrote:
> Another issue is that taking the address of locals is verboten in @safe
> code. It's generally found in self-contained code, but becomes a problem
> across 3rd party library API boundaries: if an API requires a pointer
> there's not much you can do about it without waiting for an upstream fix
> (which will break API with older code).

In my experience, the fix for such things is to use `ref T` instead of `T*`. I 
know you can't change 3rd party code, so simply label those as @system and move 
on after filing an enhancement request to the 3rd party.

Or you can do this:

     ---- from 3rd Party ----
     module fromThirdParty;
     @system U thirdParty(T* p);

     ---- your code ----
     import fromThirdParty;
     @trusted U thirdParty(ref T t) { return fromThirdParty.thirdParty(&t); }
     @safe void myParty()
         T local;

Inlining will remove the wrapper call.

More information about the Digitalmars-d mailing list