Don't rely on `HAVE_' macros in public header "tags.h".
authorLudovic Courtès <ludo@gnu.org>
Tue, 24 Nov 2009 22:12:03 +0000 (23:12 +0100)
committerLudovic Courtès <ludo@gnu.org>
Tue, 24 Nov 2009 22:12:03 +0000 (23:12 +0100)
* configure.ac: Check for `intptr_t' and `uintptr_t'.  Substitute
  `SCM_I_GSC_T_INTPTR' and `SCM_I_GSC_T_UINPTR'.

* libguile/__scm.h (SCM_T_UINTPTR_MAX, SCM_T_INTPTR_MIN,
  SCM_T_INTPTR_MAX): New macros.

* libguile/_scm.h (SIZEOF_SCM_T_BITS): New macro.

* libguile/gen-scmconfig.c (main): Produce typedefs for `scm_t_intptr'
  and `scm_t_uintptr'.

* libguile/gen-scmconfig.h.in (SCM_I_GSC_T_INTPTR, SCM_I_GSC_T_UINPTR):
  New macros.

* libguile/tags.h: Don't check for `HAVE_INTTYPES_H' and
  `HAVE_STDINT_H'; don't include <inttypes.h> nor <stdint.h>.
  (scm_t_signed_bits, scm_t_bits): Define unconditionally as aliases for
  `scm_t_intptr' and `scm_t_uintptr', respectively.
  (SCM_T_SIGNED_BITS_MAX, SCM_T_SIGNED_BITS_MIN, SCM_T_BITS_MAX):
  Likewise.
  (SIZEOF_SCM_T_BITS): Remove.

configure.ac
libguile/__scm.h
libguile/_scm.h
libguile/gen-scmconfig.c
libguile/gen-scmconfig.h.in
libguile/tags.h

index 0731d2a..4fccf68 100644 (file)
@@ -355,6 +355,8 @@ if test "$ac_cv_header_stdint_h" = yes; then
    AC_CHECK_TYPE([uint64_t],[scm_stdint_has_uint64=1],,[#include <stdint.h>])
    AC_CHECK_TYPE([intmax_t],[scm_stdint_has_intmax=1],,[#include <stdint.h>])
    AC_CHECK_TYPE([uintmax_t],[scm_stdint_has_uintmax=1],,[#include <stdint.h>])
+   AC_CHECK_TYPE([intptr_t],[scm_stdint_has_intptr=1],,[#include <stdint.h>])
+   AC_CHECK_TYPE([uintptr_t],[scm_stdint_has_uintptr=1],,[#include <stdint.h>])
 fi
 
 # so we don't get confused by the cache (wish there was a better way
@@ -383,6 +385,8 @@ if test "$ac_cv_header_inttypes_h" = yes; then
   AC_CHECK_TYPE([uint64_t],[scm_inttypes_has_uint64=1],,[#include <inttypes.h>])
   AC_CHECK_TYPE([intmax_t],[scm_inttypes_has_intmax=1],,[#include <inttypes.h>])
   AC_CHECK_TYPE([uintmax_t],[scm_inttypes_has_uintmax=1],,[#include <inttypes.h>])
+  AC_CHECK_TYPE([intptr_t],[scm_inttypes_has_intptr=1],,[#include <inttypes.h>])
+  AC_CHECK_TYPE([uintptr_t],[scm_inttypes_has_uintptr=1],,[#include <inttypes.h>])
 fi
 
 # Try hard to find definitions for some required scm_t_*int* types.
@@ -575,6 +579,46 @@ else
 fi
 AC_SUBST([SCM_I_GSC_T_UINTMAX])
 
+### Required type scm_t_intptr
+###
+SCM_I_GSC_T_INTPTR=0
+if test "$scm_stdint_has_intptr"; then
+  SCM_I_GSC_T_INTPTR='"intptr_t"'
+  SCM_I_GSC_NEEDS_STDINT_H=1
+elif test "$scm_inttypes_has_intptr"; then
+  SCM_I_GSC_T_INTPTR='"intptr_t"'
+  SCM_I_GSC_NEEDS_INTTYPES_H=1
+elif test "$ac_cv_sizeof_int" = "$ac_cv_sizeof_void_p"; then
+  SCM_I_GSC_T_INTPTR='"int"'
+elif test "$ac_cv_sizeof_long" = "$ac_cv_sizeof_void_p"; then
+  SCM_I_GSC_T_INTPTR='"long"'
+elif test "$ac_cv_sizeof_long_long" = "$ac_cv_sizeof_void_p"; then
+  SCM_I_GSC_T_INTPTR='"long long"'
+else
+  AC_MSG_ERROR([Can't find appropriate type for `scm_t_intptr'.])
+fi
+AC_SUBST([SCM_I_GSC_T_INTPTR])
+
+### Required type scm_t_uintptr
+###
+SCM_I_GSC_T_UINTPTR=0
+if test "$scm_stdint_has_uintptr"; then
+  SCM_I_GSC_T_UINTPTR='"uintptr_t"'
+  SCM_I_GSC_NEEDS_STDINT_H=1
+elif test "$scm_inttypes_has_uintptr"; then
+  SCM_I_GSC_T_UINTPTR='"uintptr_t"'
+  SCM_I_GSC_NEEDS_INTTYPES_H=1
+elif test "$ac_cv_sizeof_int" = "$ac_cv_sizeof_void_p"; then
+  SCM_I_GSC_T_UINTPTR='"unsigned int"'
+elif test "$ac_cv_sizeof_long" = "$ac_cv_sizeof_void_p"; then
+  SCM_I_GSC_T_UINTPTR='"unsigned long"'
+elif test "$ac_cv_sizeof_long_long" = "$ac_cv_sizeof_void_p"; then
+  SCM_I_GSC_T_UINTPTR='"unsigned long long"'
+else
+  AC_MSG_ERROR([Can't find appropriate type for `scm_t_uintptr'.])
+fi
+AC_SUBST([SCM_I_GSC_T_UINTPTR])
+
 
 AC_SUBST([SCM_I_GSC_NEEDS_STDINT_H])
 AC_SUBST([SCM_I_GSC_NEEDS_INTTYPES_H])
index 7450dc5..b4e1bd9 100644 (file)
 #define SCM_T_INTMAX_MIN  SCM_I_TYPE_MIN(scm_t_intmax,SCM_T_UINTMAX_MAX)
 #define SCM_T_INTMAX_MAX  SCM_I_TYPE_MAX(scm_t_intmax,SCM_T_UINTMAX_MAX)
 
+#define SCM_T_UINTPTR_MAX SCM_I_UTYPE_MAX(scm_t_uintptr)
+#define SCM_T_INTPTR_MIN  SCM_I_TYPE_MIN(scm_t_intptr,SCM_T_UINTPTR_MAX)
+#define SCM_T_INTPTR_MAX  SCM_I_TYPE_MAX(scm_t_intptr,SCM_T_UINTPTR_MAX)
+
 #define SCM_I_SIZE_MAX    SCM_I_UTYPE_MAX(size_t)
 #define SCM_I_SSIZE_MIN   SCM_I_TYPE_MIN(ssize_t,SCM_I_SIZE_MAX)
 #define SCM_I_SSIZE_MAX   SCM_I_TYPE_MAX(ssize_t,SCM_I_SIZE_MAX)
index 6cb7ce8..810b656 100644 (file)
@@ -39,6 +39,9 @@
 #  include <config.h>
 #endif
 
+/* The size of `scm_t_bits'.  */
+#define SIZEOF_SCM_T_BITS SIZEOF_VOID_P
+
 /* Undefine HAVE_STRUCT_TIMESPEC, because the libguile C code doesn't
    need it anymore, and because on MinGW:
 
index f9fff6e..cf5f6c7 100644 (file)
@@ -290,6 +290,8 @@ main (int argc, char *argv[])
   pf ("typedef %s scm_t_uint32;\n", SCM_I_GSC_T_UINT32);
   pf ("typedef %s scm_t_intmax;\n", SCM_I_GSC_T_INTMAX);
   pf ("typedef %s scm_t_uintmax;\n", SCM_I_GSC_T_UINTMAX);
+  pf ("typedef %s scm_t_intptr;\n", SCM_I_GSC_T_INTPTR);
+  pf ("typedef %s scm_t_uintptr;\n", SCM_I_GSC_T_UINTPTR);
 
   if (0 == strcmp ("intmax_t", SCM_I_GSC_T_INTMAX))
     pf ("#define SCM_SIZEOF_INTMAX %d\n", SIZEOF_INTMAX_T);
index 770e081..5d569f6 100644 (file)
@@ -25,6 +25,8 @@
 #define SCM_I_GSC_T_UINT64 @SCM_I_GSC_T_UINT64@
 #define SCM_I_GSC_T_INTMAX @SCM_I_GSC_T_INTMAX@
 #define SCM_I_GSC_T_UINTMAX @SCM_I_GSC_T_UINTMAX@
+#define SCM_I_GSC_T_INTPTR @SCM_I_GSC_T_INTPTR@
+#define SCM_I_GSC_T_UINTPTR @SCM_I_GSC_T_UINTPTR@
 #define SCM_I_GSC_T_PTRDIFF @SCM_I_GSC_T_PTRDIFF@
 #define SCM_I_GSC_USE_PTHREAD_THREADS @SCM_I_GSC_USE_PTHREAD_THREADS@
 #define SCM_I_GSC_USE_NULL_THREADS @SCM_I_GSC_USE_NULL_THREADS@
index c8cd621..79f7093 100644 (file)
 /* picks up scmconfig.h too */
 #include "libguile/__scm.h"
 
-/* FIXME: We shouldn't rely on `HAVE_*' macros here since it's a public
-   header.  */
-
-#ifdef HAVE_INTTYPES_H
-# include <inttypes.h>  /* for INTPTR_MAX and friends */
-#else
-# ifdef HAVE_STDINT_H
-#  include <stdint.h>   /* for INTPTR_MAX and friends */
-# endif
-#endif
-
 \f
 
 /* In the beginning was the Word:
 /* For dealing with the bit level representation of scheme objects we define
  * scm_t_bits:
  */
-/* On Solaris 7 and 8, /usr/include/sys/int_limits.h defines
-   INTPTR_MAX and UINTPTR_MAX to empty, INTPTR_MIN is not defined.
-   To avoid uintptr_t and intptr_t in this case we require
-   UINTPTR_MAX-0 != 0 etc.  */
-#if SCM_SIZEOF_INTPTR_T != 0 && defined(INTPTR_MAX) && defined(INTPTR_MIN) \
-  && INTPTR_MAX-0 != 0 && INTPTR_MIN-0 != 0 \
-  && SCM_SIZEOF_UINTPTR_T != 0 && defined(UINTPTR_MAX) && UINTPTR_MAX-0 != 0
-
-typedef intptr_t scm_t_signed_bits;
-#define SCM_T_SIGNED_BITS_MAX INTPTR_MAX
-#define SCM_T_SIGNED_BITS_MIN INTPTR_MIN
-typedef uintptr_t scm_t_bits;
-#define SIZEOF_SCM_T_BITS SCM_SIZEOF_UINTPTR_T
-#define SCM_T_BITS_MAX UINTPTR_MAX
 
-#else
+typedef scm_t_intptr  scm_t_signed_bits;
+typedef scm_t_uintptr scm_t_bits;
 
-typedef signed long scm_t_signed_bits;
-#define SCM_T_SIGNED_BITS_MAX LONG_MAX
-#define SCM_T_SIGNED_BITS_MIN LONG_MIN
-typedef unsigned long scm_t_bits;
-#define SIZEOF_SCM_T_BITS SCM_SIZEOF_UNSIGNED_LONG
-#define SCM_T_BITS_MAX ULONG_MAX
+#define SCM_T_SIGNED_BITS_MAX SCM_T_INTPTR_MAX
+#define SCM_T_SIGNED_BITS_MIN SCM_T_INTPTR_MIN
+#define SCM_T_BITS_MAX        SCM_T_UINTPTR_MAX
 
-#endif
 
 /* But as external interface, we define SCM, which may, according to the
  * desired level of type checking, be defined in several ways: