[m-dev.] diff: fix problem with <inttypes.h> on Solaris

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Jun 1 04:21:39 AEST 1999


On 24-May-1999, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Fix a problem on Solaris: Solaris has <inttypes.h> and #includes that
> file from <sys/types.h>, which conflicted with our definitions of intptr_t
> etc. in runtime/mercury_types.h.  The solution is to check for <inttypes.h>
> not just <stdint.h> and to use <inttypes.h> if it is available rather than
> defining the types ourselves.

Unfortunately that fix caused as many problems as it solved.
Previously we were assuming that if <stdint.h> existed, then
it would contain the types we need.  That assumption is
probably true for <stdint.h>, since that is new with C9X,
but it is definitely not true for <inttypes.h>, because there
are lots of old versions of <inttypes.h> floating around, e.g.
on IRIX.

----------

Estimated hours taken: 2

Fix a problem on IRIX caused by my previous attempt to
fix a problem with <inttypes.h> on Solaris.  The problem
was that IRIX has <inttypes.h>, but its <inttypes.h>
does not define the types that we need.  The fix is to
get configure to explicitly check for the types that we
need, rather than just checking for the header file.

runtime/mercury_conf.h.in:
	Add new macros HAVE_SYS_TYPES, HAVE_INTPTR_T,
	and HAVE_INT_LEASTN_T.

configure.in:
	Add code to check for <sys/types.h>,
	{u,}intptr_t, and {u,}int_least{8,16,32}_t,
	and define HAVE_SYS_TYPES, HAVE_INTPTR_T,
	and HAVE_INT_LEASTN_T accordingly.

runtime/mercury_types.h:
	Define {u,}intptr_t and {u,}int_least{8,16,32}_t
	iff they aren't defined by the system header files,
	instead of assuming that they don't need to be
	defined if we have <stdint.h> or <inttypes.h>.

Workspace: /home/mercury0/fjh/mercury-other
Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.171
diff -u -r1.171 configure.in
--- configure.in	1999/05/27 10:20:13	1.171
+++ configure.in	1999/05/31 18:12:48
@@ -673,10 +673,97 @@
 	AC_DEFINE(HAVE_INTTYPES)
 fi
 
-if test "$HAVE_STDINT_H" = 1 || test "$HAVE_INTTYPES_H" = 1; then
+AC_CHECK_HEADER(sys/types.h, HAVE_SYS_TYPES_H=1)
+if test "$HAVE_SYS_TYPES_H" = 1; then
+	AC_DEFINE(HAVE_SYS_TYPES)
+fi
+#-----------------------------------------------------------------------------#
+AC_MSG_CHECKING(for intptr_t)
+AC_CACHE_VAL(mercury_cv_have_intptr_t,
+	AC_TRY_COMPILE([
+		#ifdef HAVE_STDINT
+		  #include <stdint.h>
+		#endif
+		#ifdef HAVE_INTTYPES
+		  #include <inttypes.h>
+		#endif
+		#ifdef HAVE_SYS_TYPES
+		  #include <sys/types.h>
+		#endif
+	], [
+		changequote(<<,>>) 
+
+		/* test the existence of the types */
+		intptr_t foo;
+		uintptr_t bar;
+
+		/* check that they have the right size */
+		#define ASSERTION \
+			(sizeof(intptr_t) == sizeof(void *) && \
+			 sizeof(uintptr_t) == sizeof(void *))
+
+		/* this forces a compile error if ASSERTION is false */
+		int array[ASSERTION ? 1 : -1];
+
+		changequote([,]) 
+	],
+	[mercury_cv_have_intptr_t=yes],
+	[mercury_cv_have_intptr_t=no])
+)
+AC_MSG_RESULT($mercury_cv_have_intptr_t)
+if test "$mercury_cv_have_intptr_t" = yes; then
+	AC_DEFINE(MR_HAVE_INTPTR_T)
+fi
+#-----------------------------------------------------------------------------#
+AC_MSG_CHECKING(for int_leastN_t)
+AC_CACHE_VAL(mercury_cv_have_int_leastN_t,
+	AC_TRY_COMPILE([
+		#ifdef HAVE_STDINT
+		  #include <stdint.h>
+		#endif
+		#ifdef HAVE_INTTYPES
+		  #include <inttypes.h>
+		#endif
+		#ifdef HAVE_SYS_TYPES
+		  #include <sys/types.h>
+		#endif
+		#include <limits.h> /* for CHAR_BIT */
+	], [
+		changequote(<<,>>) 
+
+		/* test the existence of the types */
+		int_least8_t foo8;
+		uint_least8_t bar8;
+		int_least16_t foo16;
+		uint_least16_t bar16;
+		int_least32_t foo32;
+		uint_least32_t bar32;
+
+		/* check that they have the right size */
+		#define ASSERTION \
+			(sizeof(int_least8_t) * CHAR_BIT >= 8 && \
+			 sizeof(uint_least8_t) * CHAR_BIT >= 8 && \
+			 sizeof(int_least16_t) * CHAR_BIT >= 16 && \
+			 sizeof(uint_least16_t) * CHAR_BIT >= 16 && \
+			 sizeof(int_least32_t) * CHAR_BIT >= 32 && \
+			 sizeof(uint_least32_t) * CHAR_BIT >= 32)
+
+		/* this forces a compile error if ASSERTION is false */
+		int array[ASSERTION ? 1 : -1];
+
+		changequote([,]) 
+	],
+	[mercury_cv_have_int_leastN_t=yes],
+	[mercury_cv_have_int_leastN_t=no])
+)
+AC_MSG_RESULT($mercury_cv_have_int_leastN_t)
+if test "$mercury_cv_have_intleastN_t" = yes; then
+	AC_DEFINE(MR_HAVE_INT_LEASTN_T)
+fi
+#-----------------------------------------------------------------------------#
+if test "$mercury_cv_have_intptr_t" = yes; then
 	true
 else
-#-----------------------------------------------------------------------------#
 	AC_MSG_CHECKING(for an integer type with the same size as a pointer)
 	AC_CACHE_VAL(mercury_cv_word_type,
 		AC_TRY_RUN([
@@ -734,7 +821,11 @@
 	AC_DEFINE_UNQUOTED(MR_WORD_TYPE, $mercury_cv_word_type)
 	MR_WORD_TYPE=$mercury_cv_word_type
 	AC_SUBST(MR_WORD_TYPE)
+fi # ! have_int_ptr_t
 #-----------------------------------------------------------------------------#
+if test "$mercury_cv_have_int_leastN_t" = yes; then
+	true
+else
 	AC_MSG_CHECKING(for an integer type of at least 32 bits)
 	AC_CACHE_VAL(mercury_cv_int_least32_type,
 		AC_TRY_RUN([
@@ -806,7 +897,7 @@
 	AC_DEFINE_UNQUOTED(MR_INT_LEAST16_TYPE, $mercury_cv_int_least16_type)
 	MR_INT_LEAST16_TYPE=$mercury_cv_int_least16_type
 	AC_SUBST(MR_INT_LEAST16_TYPE)
-fi # ! (HAVE_STDINT_H || HAVE_INTTYPES_H)
+fi # ! have_int_leastN_t
 #-----------------------------------------------------------------------------#
 AC_MSG_CHECKING(the number of low tag bits available)
 AC_CACHE_VAL(mercury_cv_low_tag_bits,
Index: runtime/mercury_conf.h.in
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_conf.h.in,v
retrieving revision 1.20
diff -u -r1.20 mercury_conf.h.in
--- mercury_conf.h.in	1999/05/24 08:40:52	1.20
+++ mercury_conf.h.in	1999/05/31 18:03:44
@@ -40,7 +40,8 @@
 ** MR_WORD_TYPE: the base type for the definition of Word.
 ** This must be a C integral type (e.g. int, long, or long long)
 ** without any explicit signedness.
-** It ought to be the same size as the machine's general-purpose registers.
+** It ought to be the same size as the machine's general-purpose registers
+** (i.e. the same size as pointers).
 */
 #undef	MR_WORD_TYPE
 
@@ -93,6 +94,7 @@
 **	HAVE_DLFCN_H		we have <dlfcn.h>
 **	HAVE_STDINT		we have <stdint.h>
 **	HAVE_INTTYPES		we have <inttypes.h>
+**	HAVE_SYS_TYPES		we have <sys/types.h>
 */
 #undef	HAVE_SYS_SIGINFO
 #undef	HAVE_UCONTEXT
@@ -104,6 +106,17 @@
 #undef	HAVE_DLFCN_H
 #undef	HAVE_STDINT    
 #undef	HAVE_INTTYPES
+#undef	HAVE_SYS_TYPES
+
+/*
+** The following macros are defined iff the corresponding type
+** is available (in <stdint.h>, <inttypes.h>, or <sys/types.h>):
+**
+**	MR_HAVE_INTPTR_T	we have intptr_t and uintptr_t
+**	MR_HAVE_INT_LEASTN_T	we have {u,}int_least{8,16,32}_t
+*/
+#undef MR_HAVE_INTPTR_T
+#undef MR_HAVE_INT_LEASTN_T
 
 /*
 ** The following macros are defined iff the corresponding function or
Index: runtime/mercury_types.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_types.h,v
retrieving revision 1.16
diff -u -r1.16 mercury_types.h
--- mercury_types.h	1999/05/24 08:40:53	1.16
+++ mercury_types.h	1999/05/31 18:02:58
@@ -21,18 +21,29 @@
 
 #include "mercury_conf.h"
 
-/* 
-** Note that we require sizeof(Word) == sizeof(Integer) == sizeof(Code*);
-** this is ensured by the autoconfiguration script.
+/*
+** This section defines the relevant types from C9X's
+** <stdint.h> header, either by including that header,
+** or if necessary by emulating it ourselves, with some
+** help from the autoconfiguration script.
 */
 
-#if defined(HAVE_STDINT)
+#ifdef HAVE_STDINT
   #include <stdint.h>
-#elif defined(HAVE_INTTYPES)
+#endif
+#ifdef HAVE_INTTYPES
   #include <inttypes.h>
-#else
+#endif
+#ifdef HAVE_SYS_TYPES
+  #include <sys/types.h>
+#endif
+
+#ifndef MR_HAVE_INTPTR_T
   typedef unsigned MR_WORD_TYPE		uintptr_t;
   typedef MR_WORD_TYPE			intptr_t;
+#endif
+
+#ifndef MR_HAVE_INT_LEASTN_T
   typedef unsigned MR_INT_LEAST32_TYPE	uint_least32_t;
   typedef MR_INT_LEAST32_TYPE		int_least32_t;
   typedef unsigned MR_INT_LEAST16_TYPE	uint_least16_t;
@@ -41,6 +52,11 @@
   typedef signed char			int_least8_t;
 #endif
 
+/* 
+** This section defines the basic types that we use.
+** Note that we require sizeof(Word) == sizeof(Integer) == sizeof(Code*).
+*/
+
 typedef	uintptr_t		Word;
 typedef	intptr_t		Integer;
 typedef	uintptr_t		Unsigned;
@@ -67,9 +83,11 @@
 	#error	For Mercury bytecode, we require 64-bit IEEE-754 floating point
 #endif
 
-/* The following four typedefs logically belong in mercury_string.h.     */
-/* They are defined here to avoid problems with circular #includes.      */
-/* If you modify them, you will need to modify mercury_string.h as well. */
+/*
+** The following four typedefs logically belong in mercury_string.h.
+** They are defined here to avoid problems with circular #includes.
+** If you modify them, you will need to modify mercury_string.h as well.
+*/
 
 typedef char Char;
 typedef unsigned char UnsignedChar;

-- 
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