Skip to content

Commit 7c82e60

Browse files
authored
Merge pull request #5718 from WalterBright/betterC-stdout
stdio: remove reliance on std*** being aliasable merged-on-behalf-of: MetaLang <MetaLang@users.noreply.github.com>
2 parents 96888c6 + 2326af4 commit 7c82e60

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

std/stdio.d

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,7 +4518,7 @@ Initialize with a message and an error code.
45184518
}
45194519

45204520
// Undocumented but public because the std* handles are aliasing it.
4521-
@property ref File makeGlobal(alias handle)()
4521+
@property ref File makeGlobal(int _iob)()
45224522
{
45234523
__gshared File.Impl impl;
45244524
__gshared File result;
@@ -4537,7 +4537,9 @@ Initialize with a message and an error code.
45374537
break;
45384538
if (atomicOp!"+="(spinlock, 1) == 1)
45394539
{
4540-
impl.handle = handle;
4540+
impl.handle = _iob == 0 ? core.stdc.stdio.stdin :
4541+
_iob == 1 ? core.stdc.stdio.stdout :
4542+
core.stdc.stdio.stderr;
45414543
result._p = &impl;
45424544
atomicOp!"+="(spinlock, uint.max / 2);
45434545
break;
@@ -4554,7 +4556,7 @@ Initialize with a message and an error code.
45544556
it is thread un-safe to reassign `stdin` to a different `File` instance
45554557
than the default.
45564558
*/
4557-
alias stdin = makeGlobal!(core.stdc.stdio.stdin);
4559+
alias stdin = makeGlobal!(0);
45584560

45594561
///
45604562
@safe unittest
@@ -4582,7 +4584,7 @@ alias stdin = makeGlobal!(core.stdc.stdio.stdin);
45824584
it is thread un-safe to reassign `stdout` to a different `File` instance
45834585
than the default.
45844586
*/
4585-
alias stdout = makeGlobal!(core.stdc.stdio.stdout);
4587+
alias stdout = makeGlobal!(1);
45864588

45874589
/**
45884590
The standard error stream.
@@ -4591,7 +4593,7 @@ alias stdout = makeGlobal!(core.stdc.stdio.stdout);
45914593
it is thread un-safe to reassign `stderr` to a different `File` instance
45924594
than the default.
45934595
*/
4594-
alias stderr = makeGlobal!(core.stdc.stdio.stderr);
4596+
alias stderr = makeGlobal!(2);
45954597

45964598
@system unittest
45974599
{

0 commit comments

Comments
 (0)