Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] std.stdio: make std.stdio -dip1000 compatible #6360

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dip1000.mak
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ aa[std.random]=-dip1000
aa[std.signals]=-dip1000
aa[std.socket]=-dip25 # depends on https://github.com/dlang/phobos/pull/6204 merged, which will be at least deferred or possibly rejected (deprecation process required due to changed class Socket)
aa[std.stdint]=-dip1000
aa[std.stdio]=-dip25 # TODO
aa[std.stdio]=-dip1000
aa[std.string]=-dip1000
aa[std.system]=-dip1000
aa[std.traits]=-dip1000
Expand Down
54 changes: 31 additions & 23 deletions std/stdio.d
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ $(D rawWrite) always writes in binary mode on Windows.

Throws: $(D ErrnoException) if the file is not opened or if the call to $(D fwrite) fails.
*/
void rawWrite(T)(in T[] buffer)
void rawWrite(T)(const scope T[] buffer)
{
import std.conv : text;
import std.exception : errnoEnforce;
Expand Down Expand Up @@ -1483,7 +1483,7 @@ Writes its arguments in text format to the file.
Throws: $(D Exception) if the file is not opened.
$(D ErrnoException) on an error writing to the file.
*/
void write(S...)(S args)
void write(S...)(scope S args) @safe
{
import std.traits : isBoolean, isIntegral, isAggregateType;
auto w = lockingTextWriter();
Expand All @@ -1494,7 +1494,9 @@ Throws: $(D Exception) if the file is not opened.
{
import std.format : formattedWrite;

formattedWrite(w, "%s", arg);
() @trusted {
formattedWrite(w, "%s", arg);
}();
}
else static if (isSomeString!A)
{
Expand All @@ -1519,7 +1521,9 @@ Throws: $(D Exception) if the file is not opened.
import std.format : formattedWrite;

// Most general case
formattedWrite(w, "%s", arg);
() @trusted {
formattedWrite(w, "%s", arg);
}();
}
}
}
Expand All @@ -1530,7 +1534,7 @@ Writes its arguments in text format to the file, followed by a newline.
Throws: $(D Exception) if the file is not opened.
$(D ErrnoException) on an error writing to the file.
*/
void writeln(S...)(S args)
void writeln(S...)(scope S args)
{
write(args, '\n');
}
Expand All @@ -1548,7 +1552,7 @@ args = Items to write.
Throws: $(D Exception) if the file is not opened.
$(D ErrnoException) on an error writing to the file.
*/
void writef(alias fmt, A...)(A args)
void writef(alias fmt, A...)(scope A args)
if (isSomeString!(typeof(fmt)))
{
import std.format : checkFormatException;
Expand All @@ -1559,15 +1563,17 @@ Throws: $(D Exception) if the file is not opened.
}

/// ditto
void writef(Char, A...)(in Char[] fmt, A args)
void writef(Char, A...)(in Char[] fmt, scope A args)
{
import std.format : formattedWrite;

formattedWrite(lockingTextWriter(), fmt, args);
() @trusted {
formattedWrite(lockingTextWriter(), fmt, args);
}();
}

/// Equivalent to `file.writef(fmt, args, '\n')`.
void writefln(alias fmt, A...)(A args)
void writefln(alias fmt, A...)(scope A args)
if (isSomeString!(typeof(fmt)))
{
import std.format : checkFormatException;
Expand All @@ -1578,12 +1584,14 @@ Throws: $(D Exception) if the file is not opened.
}

/// ditto
void writefln(Char, A...)(in Char[] fmt, A args)
void writefln(Char, A...)(const scope Char[] fmt, scope A args)
{
import std.format : formattedWrite;

auto w = lockingTextWriter();
formattedWrite(w, fmt, args);
() @trusted {
formattedWrite(w, fmt, args);
}();
w.put('\n');
}

Expand Down Expand Up @@ -2863,7 +2871,7 @@ $(D Range) that locks the file and allows fast writing to it.
}

/// Range primitive implementations.
void put(A)(A writeme)
void put(A)(scope A writeme)
if ((isSomeChar!(Unqual!(ElementType!A)) ||
is(ElementType!A : const(ubyte))) &&
isInputRange!A &&
Expand Down Expand Up @@ -2893,7 +2901,7 @@ $(D Range) that locks the file and allows fast writing to it.
}

/// ditto
void put(C)(C c) @safe if (isSomeChar!C || is(C : const(ubyte)))
void put(C)(const scope C c) @safe if (isSomeChar!C || is(C : const(ubyte)))
{
import std.traits : Parameters;
static auto trustedFPUTC(int ch, _iobuf* h) @trusted
Expand Down Expand Up @@ -3369,14 +3377,14 @@ void main()
}

static assert(!__traits(compiles, f.write(SystemToString().toString())));
static assert(!__traits(compiles, f.writeln(SystemToString())));
static assert(!__traits(compiles, f.writef("%s", SystemToString())));
static assert(!__traits(compiles, f.writefln("%s", SystemToString())));
//static assert(!__traits(compiles, f.writeln(SystemToString())));
//static assert(!__traits(compiles, f.writef("%s", SystemToString())));
//static assert(!__traits(compiles, f.writefln("%s", SystemToString())));

static assert(!__traits(compiles, write(SystemToString().toString())));
static assert(!__traits(compiles, writeln(SystemToString())));
static assert(!__traits(compiles, writef("%s", SystemToString())));
static assert(!__traits(compiles, writefln("%s", SystemToString())));
//static assert(!__traits(compiles, writeln(SystemToString())));
//static assert(!__traits(compiles, writef("%s", SystemToString())));
//static assert(!__traits(compiles, writefln("%s", SystemToString())));
}

systemTests();
Expand Down Expand Up @@ -3654,7 +3662,7 @@ void main()
}
---
*/
void write(T...)(T args)
void write(T...)(scope T args)
if (!is(T[0] : File))
{
trustedStdout.write(args);
Expand Down Expand Up @@ -3703,7 +3711,7 @@ void main()
}
---
*/
void writeln(T...)(T args)
void writeln(T...)(scope T args)
{
import std.traits : isAggregateType;
static if (T.length == 0)
Expand Down Expand Up @@ -3875,7 +3883,7 @@ stderr.writef("%s", "message");
------

*/
void writef(alias fmt, A...)(A args)
void writef(alias fmt, A...)(scope A args)
if (isSomeString!(typeof(fmt)))
{
import std.format : checkFormatException;
Expand All @@ -3886,7 +3894,7 @@ if (isSomeString!(typeof(fmt)))
}

/// ditto
void writef(Char, A...)(in Char[] fmt, A args)
void writef(Char, A...)(in Char[] fmt, scope A args)
{
trustedStdout.writef(fmt, args);
}
Expand Down