summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavi <davi@13f79535-47bb-0310-9956-ffa450edef68>2007-07-10 14:39:03 +0000
committerdavi <davi@13f79535-47bb-0310-9956-ffa450edef68>2007-07-10 14:39:03 +0000
commit068d5136d2ab18fca435f3e8ca25b61cd78e7bc5 (patch)
treec8d60aee463cca5495c334fc48a5bfafca365437
parent70738e7f53f36f5828e49143d48f8db221f7c83f (diff)
downloadlibapr-068d5136d2ab18fca435f3e8ca25b61cd78e7bc5.tar.gz
Improve detection of the printf format identifiers for apr_ssize_t and apr_size_t
using the gcc (and icc) built-in __builtin_types_compatible_p (used to determine if two types are the same). This could also be achieved with another gcc extension (type redeclaration), but using the built-in seems more forward compatible. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@554963 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--build/apr_common.m414
-rw-r--r--configure.in112
2 files changed, 79 insertions, 47 deletions
diff --git a/build/apr_common.m4 b/build/apr_common.m4
index 1c17591ec..1b2b15947 100644
--- a/build/apr_common.m4
+++ b/build/apr_common.m4
@@ -959,3 +959,17 @@ fi
AC_SUBST(MKDEP)
])
+
+dnl
+dnl APR_CHECK_TYPES_COMPATIBLE(TYPE-1, TYPE-2, [ACTION-IF-TRUE])
+dnl
+dnl Try to determine whether two types are the same. Only works
+dnl for gcc and icc.
+dnl
+AC_DEFUN([APR_CHECK_TYPES_COMPATIBLE], [
+define([apr_cvname], apr_cv_typematch_[]translit([$1], [ ], [_])_[]translit([$2], [ ], [_]))
+AC_CACHE_CHECK([whether $1 and $2 are the same], apr_cvname, [
+AC_TRY_COMPILE(AC_INCLUDES_DEFAULT, [
+ int foo[0 - !__builtin_types_compatible_p($1, $2)];
+], [apr_cvname=yes $3], [apr_cvname=no])])
+])
diff --git a/configure.in b/configure.in
index 4ee1b6512..c1059bdf1 100644
--- a/configure.in
+++ b/configure.in
@@ -1330,26 +1330,83 @@ else
socklen_t_value="int"
fi
+# Basically, we have tried to figure out the correct format strings
+# for APR types which vary between platforms, but we don't always get
+# it right.
+case $host in
+ s390*linux*)
+ # uniquely, the 31-bit Linux/s390 uses "unsigned long int"
+ # for size_t rather than "unsigned int":
+ size_t_fmt="lu"
+ ssize_t_fmt="ld"
+ ;;
+ *-os2*)
+ size_t_fmt="lu"
+ ;;
+ *-solaris*)
+ pid_t_fmt="ld"
+ ;;
+ *aix4*|*aix5*)
+ ssize_t_fmt="ld"
+ size_t_fmt="ld"
+ ;;
+ *beos*)
+ ssize_t_fmt="ld"
+ size_t_fmt="ld"
+ ;;
+ *apple-darwin*)
+ osver=`uname -r`
+ case $osver in
+ [[0-7]].*)
+ ssize_t_fmt="d"
+ ;;
+ *)
+ ssize_t_fmt="ld"
+ ;;
+ esac
+ size_t_fmt="lu"
+ ;;
+esac
+
+APR_CHECK_TYPES_COMPATIBLE(ssize_t, int, [ssize_t_fmt="d"])
+APR_CHECK_TYPES_COMPATIBLE(ssize_t, long, [ssize_t_fmt="ld"])
+APR_CHECK_TYPES_COMPATIBLE(size_t, unsigned int, [size_t_fmt="u"])
+APR_CHECK_TYPES_COMPATIBLE(size_t, unsigned long, [size_t_fmt="lu"])
+
APR_CHECK_SIZEOF_EXTENDED([#include <sys/types.h>], ssize_t, 8)
-if test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_int"; then
- ssize_t_fmt='#define APR_SSIZE_T_FMT "d"'
+AC_MSG_CHECKING([which format to use for apr_ssize_t])
+if test -n "$ssize_t_fmt"; then
+ AC_MSG_RESULT(%$ssize_t_fmt)
+elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_int"; then
+ ssize_t_fmt="d"
+ AC_MSG_RESULT(%d)
elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_long"; then
- ssize_t_fmt='#define APR_SSIZE_T_FMT "ld"'
+ ssize_t_fmt="ld"
+ AC_MSG_RESULT(%ld)
else
- ssize_t_fmt='#error Can not determine the proper size for ssize_t'
+ AC_ERROR([could not determine the proper format for apr_ssize_t])
fi
+ssize_t_fmt="#define APR_SSIZE_T_FMT \"$ssize_t_fmt\""
+
APR_CHECK_SIZEOF_EXTENDED([#include <stddef.h>], size_t, 8)
-if test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_int"; then
- size_t_fmt='#define APR_SIZE_T_FMT "d"'
+AC_MSG_CHECKING([which format to use for apr_size_t])
+if test -n "$size_t_fmt"; then
+ AC_MSG_RESULT(%$size_t_fmt)
+elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_int"; then
+ size_t_fmt="d"
+ AC_MSG_RESULT(%d)
elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_long"; then
- size_t_fmt='#define APR_SIZE_T_FMT "ld"'
+ size_t_fmt="ld"
+ AC_MSG_RESULT(%ld)
else
- size_t_fmt='#error Can not determine the proper size for size_t'
+ AC_ERROR([could not determine the proper format for apr_size_t])
fi
+size_t_fmt="#define APR_SIZE_T_FMT \"$size_t_fmt\""
+
APR_CHECK_SIZEOF_EXTENDED([#include <sys/types.h>], off_t, 8)
if test "${ac_cv_sizeof_off_t}${apr_cv_use_lfs64}" = "4yes"; then
@@ -1420,45 +1477,6 @@ else
bigendian=0
fi
-# Basically, we have tried to figure out the correct format strings
-# for APR types which vary between platforms, but we don't always get
-# it right. If you find that we don't get it right for your platform,
-# you can override our decision below.
-case $host in
- s390*linux*)
- # uniquely, the 31-bit Linux/s390 uses "unsigned long int"
- # for size_t rather than "unsigned int":
- size_t_fmt='#define APR_SIZE_T_FMT "lu"'
- ssize_t_fmt='#define APR_SSIZE_T_FMT "ld"'
- ;;
- *-os2*)
- size_t_fmt='#define APR_SIZE_T_FMT "lu"'
- ;;
- *-solaris*)
- pid_t_fmt='#define APR_PID_T_FMT "ld"'
- ;;
- *aix4*|*aix5*)
- ssize_t_fmt='#define APR_SSIZE_T_FMT "ld"'
- size_t_fmt='#define APR_SIZE_T_FMT "ld"'
- ;;
- *beos*)
- ssize_t_fmt='#define APR_SSIZE_T_FMT "ld"'
- size_t_fmt='#define APR_SIZE_T_FMT "ld"'
- ;;
- *apple-darwin*)
- osver=`uname -r`
- case $osver in
- [[0-7]].*)
- ssize_t_fmt='#define APR_SSIZE_T_FMT "d"'
- ;;
- *)
- ssize_t_fmt='#define APR_SSIZE_T_FMT "ld"'
- ;;
- esac
- size_t_fmt='#define APR_SIZE_T_FMT "lu"'
- ;;
-esac
-
APR_CHECK_SIZEOF_EXTENDED([#include <sys/types.h>
#include <sys/uio.h>],struct iovec,0)
if test "$ac_cv_sizeof_struct_iovec" = "0"; then