On 8/16/20 6:07 AM, Simen Kjærås wrote:
On Saturday, 15 August 2020 at 23:59:36 UTC, Joel wrote:
../../JMiscLib/source/jmisc/base.d(176,2): Error: @safe function jmisc.base.upDateStatus!string.upDateStatus cannot call @system function std.stdio.makeGlobal!"core.stdc.stdio.stdout".makeGlobal /Library/D/dmd/src/phobos/std/stdio.d(4837,20): std.stdio.makeGlobal!"core.stdc.stdio.stdout".makeGlobal is declared here

I got around it by avoiding 'stdout'.

First, what's wrong with using writeln and friends instead of directly mucking about with stdout? :p

stdout is __gshared, so it's available on any thread at any time. That's not @safe, so it's @system.

If you know you're not using stdout from multiple threads, or don't care (it might be perfectly safe even though it's possible to misuse), you can use this code:

@property File trustedStdout() @trusted
{
     return stdout;
}

That's a @trusted wrapper that you can call from @safe code. It's not actually safe though, as multiple threads could be using trustedStdout at the same time. In many use cases, this is unlikely to matter, but it's wroth keeping in mind.

Technically, there's nothing unsafe about reading stdout, as long as you are not setting it. Otherwise, writeln wouldn't be @safe (as all it does is call a private trustedStdout).

The whole thing is messy IMO, and should be revisited.

-Steve

Reply via email to