[Issue 10344] Exiting _Dmain should flush all FILE*s and return nonzero on failure

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 17 08:12:57 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10344



--- Comment #9 from Andrei Alexandrescu <andrei at erdani.com> 2013-06-17 08:12:56 PDT ---
(In reply to comment #8)
> Let's say there is a program that executes some database commands, then outputs
> how many rows affected.  It returns 0 on success to modify the database, 1 on
> failure.  The output of how many rows affected is likely less than 100 chars. 
> So it likely would not flush before program termination.
> 
> Now, consider that the author of this program has no idea about the
> "flush-at-end-of-main" feature (an extremely likely scenario).  All his testing
> does not involve creating full disks, or invalid descriptors for stdout.  The
> man page and help screen likely says that it returns 0 on successful write to
> the DB, non-zero on failure.  It does not mention that if it fails to output "X
> rows affected," an error is returned.
> 
> Someone using this program messes up and passes an invalid descriptor (for
> whatever reason).  What happens is that any program using this application will
> see a failure, yet the database commands had succeeded.  What is the utility in
> that?  It's a completely unexpected occurrence, from both sides, and it even
> violates the documentation.  For all intents and purposes, you have introduced
> a bug into every program that doesn't expect this behavior.

But this is an argument against our current approach to stdout (we check and
throw on all errors). The error in the program you mentioned may very well
intervene in writeln under one or more of the following conditions:

* sufficient characters output
* line buffered or unbuffered stdout

In such cases, succeeding to produce stdout is just as unimportant to the
program, but the program will fail with nonzero error code. Are you saying we
should change that?

At the highest level, it is well understood there examples can be given that
show the stdout output was of small consequence to the program. The point is we
cannot decide on behalf of the program that it's okay to have truncated output.

In D all flushes of stdout are checked and exceptions are thrown if they fail.
The last flush is not special in any way and must behave the same.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list