From 114bc68ac97d47b2e5635de98b111b47de85ed92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Tue, 24 Nov 2009 23:12:03 +0100 Subject: [PATCH] Don't rely on `HAVE_' macros in public header "tags.h". * 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 nor . (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 | 44 +++++++++++++++++++++++++++++++++++++ libguile/__scm.h | 4 ++++ libguile/_scm.h | 3 +++ libguile/gen-scmconfig.c | 2 ++ libguile/gen-scmconfig.h.in | 2 ++ libguile/tags.h | 38 +++++--------------------------- 6 files changed, 60 insertions(+), 33 deletions(-) diff --git a/configure.ac b/configure.ac index 0731d2ab6..4fccf68d5 100644 --- a/configure.ac +++ b/configure.ac @@ -355,6 +355,8 @@ if test "$ac_cv_header_stdint_h" = yes; then AC_CHECK_TYPE([uint64_t],[scm_stdint_has_uint64=1],,[#include ]) AC_CHECK_TYPE([intmax_t],[scm_stdint_has_intmax=1],,[#include ]) AC_CHECK_TYPE([uintmax_t],[scm_stdint_has_uintmax=1],,[#include ]) + AC_CHECK_TYPE([intptr_t],[scm_stdint_has_intptr=1],,[#include ]) + AC_CHECK_TYPE([uintptr_t],[scm_stdint_has_uintptr=1],,[#include ]) 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 ]) AC_CHECK_TYPE([intmax_t],[scm_inttypes_has_intmax=1],,[#include ]) AC_CHECK_TYPE([uintmax_t],[scm_inttypes_has_uintmax=1],,[#include ]) + AC_CHECK_TYPE([intptr_t],[scm_inttypes_has_intptr=1],,[#include ]) + AC_CHECK_TYPE([uintptr_t],[scm_inttypes_has_uintptr=1],,[#include ]) 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]) diff --git a/libguile/__scm.h b/libguile/__scm.h index 7450dc523..b4e1bd93a 100644 --- a/libguile/__scm.h +++ b/libguile/__scm.h @@ -397,6 +397,10 @@ #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) diff --git a/libguile/_scm.h b/libguile/_scm.h index 6cb7ce8a4..810b65692 100644 --- a/libguile/_scm.h +++ b/libguile/_scm.h @@ -39,6 +39,9 @@ # include #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: diff --git a/libguile/gen-scmconfig.c b/libguile/gen-scmconfig.c index f9fff6e3e..cf5f6c7f1 100644 --- a/libguile/gen-scmconfig.c +++ b/libguile/gen-scmconfig.c @@ -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); diff --git a/libguile/gen-scmconfig.h.in b/libguile/gen-scmconfig.h.in index 770e08196..5d569f6ec 100644 --- a/libguile/gen-scmconfig.h.in +++ b/libguile/gen-scmconfig.h.in @@ -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@ diff --git a/libguile/tags.h b/libguile/tags.h index c8cd621d7..79f709306 100644 --- a/libguile/tags.h +++ b/libguile/tags.h @@ -31,17 +31,6 @@ /* 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 /* for INTPTR_MAX and friends */ -#else -# ifdef HAVE_STDINT_H -# include /* for INTPTR_MAX and friends */ -# endif -#endif - /* In the beginning was the Word: @@ -72,31 +61,14 @@ /* 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 +typedef scm_t_intptr scm_t_signed_bits; +typedef scm_t_uintptr scm_t_bits; -#else +#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 -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 - -#endif /* But as external interface, we define SCM, which may, according to the * desired level of type checking, be defined in several ways: