[m-dev.] diff: Miscellaneous library fixes
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Sep 7 16:36:55 AEST 1998
On 07-Sep-1998, Andrew Bromage <bromage at cs.mu.OZ.AU> wrote:
>
> library/io.m:
> library/io.nu.nl:
> Implement io__read_line_as_string/{3,4}.
>
> Also sneaked in here are some trivial whitespace fixes in some
> of the pragma c_code which did not comply to our coding standards
> (to do with type casting).
These should be committed as three separate changes.
This is one...
> library/math.m:
> library/float.m:
> Addition of four new system constants (float__radix,
> float__mantissa_digits, float__min_exponent and
> float__max_exponent) plus predicate equivalents. Also
> added in some extra documentation for the other constants.
>
> Rename floating point constants using the C coding standard
> way (ML_*).
>
> Put code for mathematical domain checking inside
> `#ifndef ML_OMIT_MATH_DOMAIN_CHECKS', so that the user
> can disable domain checking. (Note: This is actually safe,
> since the combination of floating point hardware and -lm
> should do all these checks for you.)
...
> samples/cat.m:
> samples/sort.m:
> Use io__read_line_as_string.
>
> tests/general/Mmakefile:
> tests/general/read_line_as_string.exp:
> tests/general/read_line_as_string.m:
> Test case for io__read_line_as_string.
This is another...
> library/queue.m:
> Fix a bug in queue__delete where the constraint that the `off'
> list is empty if and only if the queue is empty was not being
> preserved in all cases.
And this is the last one.
> +
> + % Radix of the floating-point representation.
> +:- pragma c_code(float__radix(Radix::out), will_not_call_mercury,
> + "Radix = ML_FLOAT_RADIX;").
I think all of these should be declared `thread_safe' too.
> io__read_line(Stream, Result) -->
> - io__read_char(Stream, CharResult),
> + io__read_char_code(Stream, Code),
> (
> - { CharResult = error(Error) },
> - { Result = error(Error) }
> - ;
> - { CharResult = eof },
> + { Code = -1 }
> + ->
> { Result = eof }
> ;
> - { CharResult = ok(Char) },
> + { char__to_int(Char, Code) }
> + ->
> ( { Char = '\n' } ->
> { Result = ok([Char]) }
> ;
> - io__read_line(Stream, Result0),
> - (
> - { Result0 = ok(Chars) },
> - { Result = ok([Char | Chars]) }
> - ;
> - { Result0 = error(_) },
> - { Result = Result0 }
> - ;
> - { Result0 = eof },
> - { Result = ok([Char]) }
> - )
> + io__read_line_2(Stream, Result0),
> + { Result = ok([Char | Result0]) }
> )
> + ;
> + % XXX improve error message
> + { Result = error("read error") }
> ).
You should improve the error message here.
This change unfolds io__read_char into io__read_line,
but io__read_char has changed since you made this change.
> +io__read_line_as_string(Stream, Result, IO0, IO) :-
> + io__read_line_as_string_2(Stream, Res, String, IO0, IO),
> + ( Res < 0 ->
> + ( Res = -1 ->
> + Result = eof
> + ;
> + % XXX improve error message
> + Result = error("read error")
Here too you should improve the error message.
> +:- pred io__read_line_as_string_2(io__input_stream, int, string,
> + io__state, io__state).
> +:- mode io__read_line_as_string_2(in, out, out, di, uo) is det.
> +
> +:- pragma c_code(io__read_line_as_string_2(File::in, Res :: out,
> + RetString::out, IO0::di, IO::uo),
> + will_not_call_mercury,
Should this be thread_safe too?
> + if (i == read_buf_size) {
> + /* Grow the read buffer */
> + read_buf_size = READ_LINE_GROW(read_buf_size);
> + if (read_buffer == initial_read_buffer) {
> + read_buffer = checked_malloc(read_buf_size
> + * sizeof(Char));
> + memcpy(read_buffer, initial_read_buffer,
> + READ_LINE_START);
> + }
> + else {
Should be `} else {' (on one line).
> -:- pragma c_code(io__putback_char(File::in, Character::in, IO0::di, IO::uo),
> +:- pragma(c_code, io__putback_char(File::in, Character::in, IO0::di, IO::uo),
> will_not_call_mercury, "{
You changed the parentheses in the wrong way.
Please be careful when merging in changes.
> -:- pragma c_code(io__putback_byte(File::in, Character::in, IO0::di, IO::uo),
> +:- pragma(c_code, io__putback_byte(File::in, Character::in, IO0::di, IO::uo),
> will_not_call_mercury, "{
Ditto.
--
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.
More information about the developers
mailing list