[m-dev.] bug with MR_READ() and MR_WRITE()
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Sep 15 19:05:41 AEDT 2000
There seems to be some inconsistency about the semantics of the
return value from MR_READ() and MR_WRITE().
If MR_NEW_MERCURYFILE_STRUCT is not defined, then those
macros call fread() and fwrite(), which return 0 on error.
For fread(), to distinguish between end-of-file and errors,
you need to call feof()/ferror().
But if MR_NEW_MERCURYFILE_STRUCT is defined, then those
macros call the `read' and `write' fields of the MercuryFile struct,
which for ordinary streams will be set to MR_read() and MR_write(),
which return -1 on error. That makes sense, since for user-defined
streams, there is no FILE*, so you can't call feof()/ferror() to
distinguish the end-of-file and error cases. But it's inconsistent
with the behaviour when MR_NEW_MERCURYFILE_STRUCT is not defined.
And the meaning of the return value is not documented anywhere.
As far as I can tell, MR_WRITE() is not used anywhere.
But MR_READ() is used -- it is called from io__read_into_buffer,
which is used in io__read_file_as_string in library/io.m.
The code there assumes that it will return zero on error.
So I think that is a bug: that code will do the wrong thing
when MR_NEW_MERCURYFILE_STRUCT is defined.
Pete, could you please investigate this one?
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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