[m-rev.] diff: fix a bug with io.write_int/[34] on MinGW64

Julien Fischer jfischer at opturion.com
Thu Apr 4 17:45:42 AEDT 2013


Fix a bug with io.write_int/[34] on MinGW64.

The implementations of io.write_int/[34] were casting their integer argument to
a long before printing it out.  This is incorrect on LLP64 platforms, since on
those platforms longs are 32-bit values (i.e. we were truncating 64-bit
integers to 32-bit integers when printing them out!).
Among other things, this was causing --smart-indexing to break on MinGW64,
since the bit vectors we generate for semidet atomic lookup switches were being
incorrectly printed in the generated C files.

library/io.m:
    Do not assume that sizeof(MR_Integer) <= sizeof(long) in the
    implementations of io.write_int.  For 64-bit Windows, this
    is not true.

Julien.

diff --git a/library/io.m b/library/io.m
index e1883b8..8a462f4 100644
--- a/library/io.m
+++ b/library/io.m
@@ -7772,7 +7772,7 @@ io.putback_byte(binary_input_stream(Stream),
Character, !IO) :-
         does_not_affect_liveness, no_sharing],
 "
     MercuryFilePtr out = mercury_current_text_output();
-    if (ML_fprintf(out, ""%ld"", (long) Val) < 0) {
+    if (ML_fprintf(out, ""%"" MR_INTEGER_LENGTH_MODIFIER ""d"", Val) < 0) {
         mercury_output_error(out);
     }
 ").
@@ -8119,7 +8119,7 @@ io.write_int(output_stream(Stream), Val, !IO) :-
     [may_call_mercury, promise_pure, tabled_for_io, thread_safe, terminates,
         does_not_affect_liveness, no_sharing],
 "
-    if (ML_fprintf(Stream, ""%ld"", (long) Val) < 0) {
+    if (ML_fprintf(Stream, ""%"" MR_INTEGER_LENGTH_MODIFIER ""d"", Val) < 0) {
         mercury_output_error(Stream);
     }
 ").



More information about the reviews mailing list