[m-rev.] for review: Remove MR_INT_LEAST64_LENGTH_MODIFIER.

Peter Wang novalazy at gmail.com
Tue Dec 19 14:26:44 AEDT 2023


We had configure choose the format string length modifier for
MR_int_least64_t based on whether the type is an alias for "int",
"long", "long long" or "__int64". That does not work for some versions
of MinGW-w64, which warn about the "ll" length modifier even though
MR_int_least64_t is an alias for "long long". The reason is that
we would be calling the MSVC runtime *printf functions,
which require the "I64" length modifier instead of "ll".

The only place MR_INT_LEAST64_LENGTH_MODIFIER is used in the Mercury
system is in the hidden function float64_bits_string (which is also
no longer used by the Mercury compiler after the removal of the hl
grades). We can replace that use with PRIdLEAST64 from inttypes.h.

Users are unlikely to be using MR_INT_LEAST64_LENGTH_MODIFIER,
so it should be safe to remove it.

configure.ac:
runtime/mercury_conf.h.in:
    Don't define MR_INT_LEAST64_LENGTH_MODIFIER.

library/float.m:
    Replace use of MR_INT_LEAST64_LENGTH_MODIFIER with PRIdLEAST64
    in float64_bits_string.

    Mark all float32_bits_string and float64_bits_string foreign procs
    as 'may_not_export_body'. There is no need to opt-export procedures
    that will rarely be used, if ever.

runtime/mercury_types.h:
    Mention that a comment is out of date.

diff --git a/configure.ac b/configure.ac
index 7f0c3b98a..bd1260b2a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1752,19 +1752,6 @@ if test "$mercury_cv_int_least64_type" != unknown; then
     AC_DEFINE_UNQUOTED(MR_INT_LEAST64_TYPE, $mercury_cv_int_least64_type)
     MR_INT_LEAST64_TYPE=$mercury_cv_int_least64_type
     AC_SUBST(MR_INT_LEAST64_TYPE)
-
-    if test "$mercury_cv_int_least64_type" = int; then
-        AC_DEFINE_UNQUOTED(MR_INT_LEAST64_LENGTH_MODIFIER, "")
-    elif test "$mercury_cv_int_least64_type" = long; then
-        AC_DEFINE_UNQUOTED(MR_INT_LEAST64_LENGTH_MODIFIER, "l")
-    elif test "$mercury_cv_int_least64_type" = "long long"; then
-        AC_DEFINE_UNQUOTED(MR_INT_LEAST64_LENGTH_MODIFIER, "ll")
-    elif test "$mercury_cv_int_least64_type" = "__int64"; then
-        AC_DEFINE_UNQUOTED(MR_INT_LEAST64_LENGTH_MODIFIER, "I64")
-    else
-        AC_MSG_ERROR(Cannot determine the length modifier for the MR_int_least64_t type.)
-    fi
-    AC_SUBST(MR_INT_LEAST64_LENGTH_MODIFIER)
 fi
 
 #-----------------------------------------------------------------------------#
diff --git a/library/float.m b/library/float.m
index 72dabff96..bd0bd383b 100644
--- a/library/float.m
+++ b/library/float.m
@@ -348,12 +348,9 @@
 :- import_module exception.
 :- import_module int.
 
-%
-% Header files of mathematical significance.
-%
-
 :- pragma foreign_decl("C", "
     #include <float.h>
+    #include <inttypes.h>
     #include <math.h>
 
 #ifdef MR_HAVE_IEEEFP_H
@@ -1166,7 +1163,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
 
 :- pragma foreign_proc("C",
     float32_bits_string(Flt::in) = (Str::uo),
-    [will_not_call_mercury, promise_pure, thread_safe],
+    [will_not_call_mercury, promise_pure, thread_safe, may_not_export_body],
 "
     union {
         float f;
@@ -1181,7 +1178,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
 
 :- pragma foreign_proc("Java",
     float32_bits_string(Flt::in) = (Str::uo),
-    [will_not_call_mercury, promise_pure, thread_safe],
+    [will_not_call_mercury, promise_pure, thread_safe, may_not_export_body],
 "
     float f = (float) Flt;
     int i = Float.floatToIntBits(f);
@@ -1190,7 +1187,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
 
 :- pragma foreign_proc("C#",
     float32_bits_string(Flt::in) = (Str::uo),
-    [will_not_call_mercury, promise_pure, thread_safe],
+    [will_not_call_mercury, promise_pure, thread_safe, may_not_export_body],
 "
     float f = (float) Flt;
     int i = System.BitConverter.ToInt32(System.BitConverter.GetBytes(f), 0);
@@ -1199,7 +1196,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
 
 :- pragma foreign_proc("C",
     float64_bits_string(Flt::in) = (Str::uo),
-    [will_not_call_mercury, promise_pure, thread_safe],
+    [will_not_call_mercury, promise_pure, thread_safe, may_not_export_body],
 "
     #if defined(MR_INT_LEAST64_TYPE)
 
@@ -1210,7 +1207,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
         char buf[64];
 
         u.f = (double) Flt;
-        sprintf(buf, ""%"" MR_INT_LEAST64_LENGTH_MODIFIER ""d"", u.i);
+        sprintf(buf, ""%"" PRIdLEAST64, u.i);
         MR_make_aligned_string_copy(Str, buf);
     #else
         MR_fatal_error(
@@ -1220,7 +1217,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
 
 :- pragma foreign_proc("Java",
     float64_bits_string(Flt::in) = (Str::uo),
-    [will_not_call_mercury, promise_pure, thread_safe],
+    [will_not_call_mercury, promise_pure, thread_safe, may_not_export_body],
 "
     double d = (double) Flt;
     long i = Double.doubleToLongBits(d);
@@ -1229,7 +1226,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
 
 :- pragma foreign_proc("C#",
     float64_bits_string(Flt::in) = (Str::uo),
-    [will_not_call_mercury, promise_pure, thread_safe],
+    [will_not_call_mercury, promise_pure, thread_safe, may_not_export_body],
 "
     double d = (double) Flt;
     long i = System.BitConverter.DoubleToInt64Bits(d);
diff --git a/runtime/mercury_conf.h.in b/runtime/mercury_conf.h.in
index b847ffce1..168f9bcc5 100644
--- a/runtime/mercury_conf.h.in
+++ b/runtime/mercury_conf.h.in
@@ -67,11 +67,6 @@
 
 #undef  MR_INT_LEAST64_TYPE
 
-// MR_INT_LEAST64_LENGTH_MODIFIER: the print() length modifier for
-// a MR_int_least64_t.
-
-#undef  MR_INT_LEAST64_LENGTH_MODIFIER
-
 // MR_INT_LEAST32_TYPE:
 // This must be a C integral type (e.g. short, int, long)
 // without any explicit signedness.
diff --git a/runtime/mercury_types.h b/runtime/mercury_types.h
index 11085e550..53e35f56c 100644
--- a/runtime/mercury_types.h
+++ b/runtime/mercury_types.h
@@ -44,6 +44,7 @@
 #endif
 
 // This section defines types similar to C9X's <stdint.h> header.
+// XXX The following is out of date.
 // We do not use <stdint.h>, or the <inttypes.h> or <sys/types.h> files
 // that substitute for it on some systems because (a) some such files
 // do not define the types we need, and (b) some such files include
-- 
2.42.0



More information about the reviews mailing list