From 3d01055d96158095d96acea6f2618d1db1a49a90 Mon Sep 17 00:00:00 2001 From: alexrp Date: Sun, 10 Jun 2012 10:08:40 +0200 Subject: [PATCH 1/3] Mark some std.stdio.File members pure/nothrow. --- std/stdio.d | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/std/stdio.d b/std/stdio.d index 6adb48aa0c6..b893dca8e7b 100644 --- a/std/stdio.d +++ b/std/stdio.d @@ -343,7 +343,7 @@ opengroup.org/onlinepubs/007908799/xsh/_popen.html, _popen). } /** Returns $(D true) if the file is opened. */ - @property bool isOpen() const + @property bool isOpen() const pure nothrow { return p !is null && p.handle; } @@ -353,14 +353,14 @@ Returns $(D true) if the file is at end (see $(WEB cplusplus.com/reference/clibrary/cstdio/feof.html, feof)). The file must be opened, otherwise an exception is thrown. */ - @property bool eof() const + @property bool eof() const pure { enforce(p && p.handle, "Calling eof() against an unopened file."); return .feof(cast(FILE*) p.handle) != 0; } /** Returns the name of the file, if any. */ - @property string name() const + @property string name() const pure nothrow { return p.name; } @@ -370,7 +370,7 @@ If the file is not opened, returns $(D false). Otherwise, returns $(WEB cplusplus.com/reference/clibrary/cstdio/ferror.html, ferror) for the file handle. */ - @property bool error() const + @property bool error() const pure nothrow { return !p.handle || .ferror(cast(FILE*) p.handle); } @@ -444,7 +444,7 @@ If the file is not opened, succeeds vacuously. Otherwise, returns $(WEB cplusplus.com/reference/clibrary/cstdio/_clearerr.html, _clearerr) for the file handle. */ - void clearerr() + void clearerr() pure nothrow { p is null || p.handle is null || .clearerr(p.handle); @@ -919,7 +919,7 @@ File) never takes the initiative in closing the file. */ /** Returns the $(D FILE*) corresponding to this object. */ - FILE* getFP() + FILE* getFP() pure { enforce(p && p.handle, "Attempting to call getFP() on an unopened file"); From aff8f4d6a44e8b9e3fe2cc44ceaea3ee233d3083 Mon Sep 17 00:00:00 2001 From: alexrp Date: Sun, 10 Jun 2012 10:21:16 +0200 Subject: [PATCH 2/3] Document std.stdio.{stdin,stdout,stderr}. --- std/stdio.d | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/std/stdio.d b/std/stdio.d index b893dca8e7b..6c9b9d668e3 100644 --- a/std/stdio.d +++ b/std/stdio.d @@ -2304,9 +2304,9 @@ extern(C) void std_stdio_static_this() //--------- __gshared { - File stdin; - File stdout; - File stderr; + File stdin; /// The standard input stream. + File stdout; /// The standard output stream. + File stderr; /// The standard error stream. } unittest From e34e1083a2453f9a861e0cc5c0b3cf734c699fd9 Mon Sep 17 00:00:00 2001 From: alexrp Date: Sun, 10 Jun 2012 20:17:15 +0200 Subject: [PATCH 3/3] Rename isStreamingDevice to isFileHandle and deprecate the old name. --- std/stdio.d | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/std/stdio.d b/std/stdio.d index 6c9b9d668e3..8f50984a9f7 100644 --- a/std/stdio.d +++ b/std/stdio.d @@ -1512,12 +1512,26 @@ void writefx(FILE* fps, TypeInfo[] arguments, void* argptr, int newline=false) } } -template isStreamingDevice(T) +/** + * Indicates whether $(D T) is a file handle of some kind. + */ +template isFileHandle(T) { - enum isStreamingDevice = is(T : FILE*) || + enum isFileHandle = is(T : FILE*) || is(T : File); } +unittest +{ + static assert(isFileHandle!(FILE*)); + static assert(isFileHandle!(File)); +} + +/** + * $(RED Scheduled for deprecation. Please use $(D isFileHandle) instead.) + */ +alias isFileHandle isStreamingDevice; + /*********************************** For each argument $(D arg) in $(D args), format the argument (as per $(LINK2 std_conv.html, to!(string)(arg))) and write the resulting