[m-rev.] io.m latest full diff

James Goddard goddardjames at yahoo.com
Thu Jan 22 12:49:35 AEDT 2004


 --- Fergus Henderson <fjh at cs.mu.OZ.AU> wrote: 
> > +		/*
> > +		** read_char():
> > +		**	Reads one character in from a text input file using the
> > +		**	default charset decoding.  Returns -1 at end of file.
> > +		*/
> > +		public int read_char() {
> > +			int c;
> > +			if (input == null) {
> > +				throw new java.lang.RuntimeException(
> > +					""read_char_code may only be called"" +
> > +					"" on text input streams"");
> 
> This code here, and quite a bit of code elsewhere, is going to break if
> text mode operations are attempted on a binary file.  The implementations
> of io__read_binary and io__write_binary do exactly that.
> 
> Fixing this problem would require a major redesign, so I suggest that
> for now, you just document the problem with XXX comments, both at the
> definition of the MercuryFile structure and also at the definition
> of io__read_binary/io__write_binary.

I think that io__write_binary will actually succeed.. The put() and write()
functions work for both text and binary streams, using the default text
encoding for text streams and stripping away all but the lower 8 bits for each
character for binary streams.  Whether this is the behaviour we want in this
case is another matter.

I could merge read_char() and read_byte() into a single read() function, so
that you could actually call read_char_code on binary streams, (and
read_byte_val on text streams) and it would behave in a symmetrical manner. 
Would this be appropriate and/or solve the problem?

In the worst case, this will at least allow io__read_binary to succeed without
throwing exceptions, albeit with undefined behaviour in the case where
characters with more than one significant byte are used.

http://personals.yahoo.com.au - Yahoo! Personals
New people, new possibilities. FREE for a limited time.
--------------------------------------------------------------------------
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