all OS functions should be "nothrow @trusted @nogc"
Moritz Maxeiner via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jul 25 07:24:20 PDT 2017
On Tuesday, 25 July 2017 at 13:50:16 UTC, Shachar Shemesh wrote:
> The title really does says it all.
Since you explicitly state *all* OS functions:
nothrow: Should be OK (only callbacks could violate this and they
should be nothrow, anyway).
@trusted: This can only be done for those functions that don't
take arguments open to memory corruption. Take a look at POSIX
read, it can never be trusted (same as any C function taking
pointer+length of pointed to).
@nogc: This can only be done for those functions that are
statically known to never call a D callback that's not also
@nogc. Take a look at pthread_create vor pthread_join, they can
never be @nogc, because that would mean threads may never
allocate with the GC.
> I keep copying OS function declarations into my code, just so I
> can add those attributes to them. Otherwise I simply cannot
> call "signalfd" and "sigemptyset" (to name a couple from my
> most recent history) from @safe code.
---
auto result = () @trusted { return systemFunction(...) }();
---
More information about the Digitalmars-d
mailing list