[m-rev.] for review: throw exception for io__close_output(stdout)

Simon Taylor stayl at cs.mu.OZ.AU
Tue Jun 18 22:39:32 AEST 2002


Estimated hours taken: 0.25
Branches: main

NEWS:
library/io.m:
	Throw an exception rather than silently ignoring
	attempts to close stdin, stdout or stderr.

Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.259
diff -u -u -r1.259 NEWS
--- NEWS	30 May 2002 12:54:51 -0000	1.259
+++ NEWS	18 Jun 2002 12:26:04 -0000
@@ -108,6 +108,11 @@
 
 Changes to the Mercury standard library:
 
+* io__close_input, io__close_output, io__close_binary_input and
+  io__close_binary_output now throw an exception rather than
+  silently ignoring attempts to close the stdin, stdout or stderr
+  streams.
+
 * We have added the type class `pprint__doc/1' and a new concatenation
   operator, `++/2', which should make it easier to construct doc values.
 * Performance bugs in `pprint__to_doc' have now been fixed.  Even
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.259
diff -u -u -r1.259 io.m
--- library/io.m	14 Jun 2002 10:18:47 -0000	1.259
+++ library/io.m	18 Jun 2002 12:37:09 -0000
@@ -3803,10 +3803,15 @@
 void
 mercury_close(MercuryFile* mf)
 {
-	if (mf != &mercury_stdin &&
-	    mf != &mercury_stdout &&
-	    mf != &mercury_stderr)
+	if (mf == &mercury_stdin ||
+	    mf == &mercury_stdout ||
+	    mf == &mercury_stderr ||
+	    mf == &mercury_stdin_binary ||
+	    mf == &mercury_stdout_binary)
 	{
+		mercury_io_error(mf,
+			""attempt to close stdin, stdout or stderr"");	
+	} else {
 		if (MR_CLOSE(*mf) < 0) {
 			mercury_io_error(mf, ""error closing file: %s"",
 				strerror(errno));
@@ -3879,10 +3884,15 @@
 static void
 mercury_close(MR_MercuryFile mf)
 {
-        if (mf != mercury_stdin &&
-            mf != mercury_stdout &&
-            mf != mercury_stderr)
+        if (mf == mercury_stdin ||
+            mf == mercury_stdout ||
+            mf == mercury_stderr ||
+            mf == mercury_stdin_binary ||
+            mf == mercury_stdout_binary)
         {
+                // XXX We should throw an exception here.
+                ;	
+        } else {
                 mf->stream->Close();
                 mf->stream = NULL;
         }
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list