[m-rev.] diff: fix io__write_binary bug
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Jan 22 15:40:16 AEDT 2004
I already posted the diff for this in another thread,
but I forgot to include a regression test.
----------
Estimated hours taken: 0.5
Branches: main
library/io.m:
Fix a bug in io__read_binary: it was leaving unread the trailing
newline that io__write_binary writes.
tests/hard_coded/write_binary.m:
Uncomment the part of the test case which tests for this bug.
Workspace: /home/ceres/fjh/mercury
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.315
diff -u -d -r1.315 io.m
--- library/io.m 2 Dec 2003 10:02:05 -0000 1.315
+++ library/io.m 22 Jan 2004 02:55:14 -0000
@@ -3914,14 +3914,26 @@
% (not really binary!)
io__binary_input_stream(Stream),
io__read(Stream, ReadResult),
- { io__convert_read_result(ReadResult, Result) }.
-
-:- pred io__convert_read_result(io__read_result(T), io__result(T)).
-:- mode io__convert_read_result(in, out) is det.
-
-io__convert_read_result(ok(T), ok(T)).
-io__convert_read_result(eof, eof).
-io__convert_read_result(error(Error, _Line), error(io_error(Error))).
+ (
+ { ReadResult = ok(T) },
+ % We've read the newline and the trailing full stop.
+ % Now skip the newline after the full stop.
+ io__read_char(Stream, NewLineRes),
+ ( { NewLineRes = error(Error) } ->
+ { Result = error(Error) }
+ ; { NewLineRes = ok('\n') } ->
+ { Result = ok(T) }
+ ;
+ { Result = error(io_error(
+ "io.read_binary: missing newline")) }
+ )
+ ;
+ { ReadResult = eof },
+ { Result = eof }
+ ;
+ { ReadResult = error(ErrorMsg, _Line) },
+ { Result = error(io_error(ErrorMsg)) }
+ ).
%-----------------------------------------------------------------------------%
Index: tests/hard_coded/write_binary.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/write_binary.m,v
retrieving revision 1.1
diff -u -d -r1.1 write_binary.m
--- tests/hard_coded/write_binary.m 22 Jan 2004 04:35:13 -0000 1.1
+++ tests/hard_coded/write_binary.m 22 Jan 2004 04:37:32 -0000
@@ -3,9 +3,6 @@
% XXX currently we do not pass the test of "univ"!
-% XXX currently we do not pass the "B43" test,
-% because of a bug in io__read_binary
-
:- module write_binary.
:- interface.
:- import_module io.
@@ -190,9 +187,7 @@
io__close_binary_input(InputStream),
(
{ B42 = ok(42) },
- % XXX currently we do not pass the B43 test,
- % because of a bug in io__read_binary
- %%% { B43 = ok(43) },
+ { B43 = ok(43) },
{ Result = ok(TermRead0) },
{ TermRead0 = Term }
->
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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