[m-dev.] for review: Fix bug in io__read_file_as_string/4
Tyson Dowd
trd at cs.mu.OZ.AU
Mon Sep 11 14:18:44 AEDT 2000
Hi,
This is for Peter Ross -- you break it, you review it ;-)
Your original (buggy) diff was:
@@ -1650,7 +1667,7 @@
char *buffer = (Char *) Buffer0;
int items_read;
- items_read = fread(buffer + Pos0, sizeof(Char), Size - Pos0, f->file);
+ MR_READ(*f, buffer + Pos0, Size - Pos0);
Buffer = (Word) buffer;
Pos = Pos0 + items_read;
===================================================================
Estimated hours taken: 2
The xml parser wasn't working, because all the files read using
io__read_file_as_string/4 were empty. It turns out this is a due to a
bug in the library.
library/io.m:
Fix a bug that petdr introduced when changing the file stream
structures.
Make sure we use the return value of fread (or whatever is used
to read the file) when reading into a buffer.
tests/general/Mmakefile:
tests/general/io_regression.exp:
tests/general/io_regression.inp:
tests/general/io_regression.m:
Add a test case for this problem to the test suite.
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.201
diff -u -r1.201 io.m
--- library/io.m 2000/08/11 16:50:15 1.201
+++ library/io.m 2000/09/11 02:48:21
@@ -1667,7 +1667,7 @@
char *buffer = (Char *) Buffer0;
int items_read;
- MR_READ(*f, buffer + Pos0, Size - Pos0);
+ items_read = MR_READ(*f, buffer + Pos0, Size - Pos0);
Buffer = (Word) buffer;
Pos = Pos0 + items_read;
Index: tests/general/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/general/Mmakefile,v
retrieving revision 1.30
diff -u -r1.30 Mmakefile
--- tests/general/Mmakefile 2000/08/10 10:36:38 1.30
+++ tests/general/Mmakefile 2000/09/11 03:12:57
@@ -37,6 +37,7 @@
higher_order \
intermod_type \
interpreter \
+ io_regression \
liveness \
liveness2 \
mode_inf \
Index: tests/general/io_regression.exp
===================================================================
RCS file: io_regression.exp
diff -N io_regression.exp
--- /dev/null Tue May 16 14:50:59 2000
+++ io_regression.exp Mon Sep 11 14:11:36 2000
@@ -0,0 +1,3 @@
+
+This is a test of the reading files using io__read_file_as_string.
+
Index: tests/general/io_regression.inp
===================================================================
RCS file: io_regression.inp
diff -N io_regression.inp
--- /dev/null Tue May 16 14:50:59 2000
+++ io_regression.inp Mon Sep 11 14:08:49 2000
@@ -0,0 +1,3 @@
+
+This is a test of the reading files using io__read_file_as_string.
+
Index: tests/general/io_regression.m
===================================================================
RCS file: io_regression.m
diff -N io_regression.m
--- /dev/null Tue May 16 14:50:59 2000
+++ io_regression.m Mon Sep 11 14:11:23 2000
@@ -0,0 +1,22 @@
+:- module io_regression.
+
+%
+% io__read_file_as_string stopped working one day, and it wasn't noticed
+% because it wasn't in any of the test cases. So now it is.
+%
+
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+main -->
+ io__read_file_as_string(Res, Str),
+ ( { Res = ok } ->
+ io__write_string(Str)
+ ;
+ io__write_string("Error reading file.\n")
+ ).
+
--
Tyson Dowd #
# Surreal humour isn't everyone's cup of fur.
trd at cs.mu.oz.au #
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list