reddit discussion on replacing Python in 0install

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jun 13 11:26:51 PDT 2013


On Thu, Jun 13, 2013 at 11:11:06AM -0700, Walter Bright wrote:
> On 6/13/2013 6:24 AM, Steven Schveighoffer wrote:
[...]
> >This isn't the problem that was presented.  The problem that was
> >presented is that given an invalid file descriptor, writeln happily
> >works (as long as you don't cause a flush) and does not throw.  This
> >is unintuitive to someone who is expecting writeln to choke on an
> >invalid descriptor.
> 
> That behavior is normal to anyone used to working with C stdio.
> 
> What is wrong and needs fixing is the program exiting with "success"
> indication when the output has actually failed.

Wouldn't an easy fix be for DMD to insert this into main()?

	scope(exit) if (fflush(stdout) != 0)
		throw new Exception(...);

	// ... rinse, repeat for whatever other fd's we care about

Of course, instead of hardcoding stdio into DMD, the scope(exit) can
call some kind of library cleanup hook, maybe something like:

	scope(exit) _druntimeCleanup();

and the throw can happen inside _druntimeCleanup, which should cause the
exit status to be non-zero.

Not sure how to make this exception user-catchable, though.


T

-- 
Ph.D. = Permanent head Damage


More information about the Digitalmars-d mailing list