diff options
author | Yann Ylavic <ylavic@apache.org> | 2019-03-22 13:30:31 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2019-03-22 13:30:31 +0000 |
commit | 07a8f11a72b200e2a961cdafc5fbcb29b66be4ac (patch) | |
tree | b59c73bd02cf067e8f68be51fed0778c3f614669 | |
parent | a00e02fab2a93d1a0a69c32316a0a5e77a0c2aa6 (diff) | |
download | apr-07a8f11a72b200e2a961cdafc5fbcb29b66be4ac.tar.gz |
Merge r1856042, r1856043, r1856046, r1856050 from trunk:
Use stdint/inttypes 64bit types/formats when both available.
Which should be the case on modern platforms, no change for others.
Don't mangle Darwin's native [U]INT64_C macros.
Define __STDC_FORMAT_MACROS for C++'s inttypes.
stdint.h and inttypes.h may include each other so define __STDC macros first.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1856052 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | build/apr_common.m4 | 6 | ||||
-rw-r--r-- | configure.in | 41 | ||||
-rw-r--r-- | include/apr.h.in | 40 |
3 files changed, 62 insertions, 25 deletions
diff --git a/build/apr_common.m4 b/build/apr_common.m4 index 9d4e686e7..208017116 100644 --- a/build/apr_common.m4 +++ b/build/apr_common.m4 @@ -985,7 +985,11 @@ AC_DEFUN([APR_CHECK_TYPES_FMT_COMPATIBLE], [ define([apr_cvname], apr_cv_typematch_[]translit([$1], [ ], [_])_[]translit([$2], [ ], [_])_[][$3]) AC_CACHE_CHECK([whether $1 and $2 use fmt %$3], apr_cvname, [ APR_TRY_COMPILE_NO_WARNING([#include <sys/types.h> -#include <stdio.h>], [ +#include <stdio.h> +#ifdef HAVE_STDINT_H +#include <stdint.h> +#endif +], [ $1 chk1, *ptr1; $2 chk2, *ptr2 = &chk1; ptr1 = &chk2; diff --git a/configure.in b/configure.in index 71df66d2c..ff3a63cf6 100644 --- a/configure.in +++ b/configure.in @@ -1493,6 +1493,7 @@ APR_FLAG_HEADERS( errno.h \ fcntl.h \ grp.h \ + inttypes.h \ io.h \ limits.h \ mach-o/dyld.h \ @@ -1572,6 +1573,7 @@ AC_SUBST(crypth) AC_SUBST(errnoh) AC_SUBST(direnth) AC_SUBST(fcntlh) +AC_SUBST(inttypesh) AC_SUBST(ioh) AC_SUBST(limitsh) AC_SUBST(netdbh) @@ -1667,9 +1669,9 @@ fi dnl Checks for integer size AC_CHECK_SIZEOF(char, 1) +AC_CHECK_SIZEOF(short, 2) AC_CHECK_SIZEOF(int, 4) AC_CHECK_SIZEOF(long, 4) -AC_CHECK_SIZEOF(short, 2) AC_CHECK_SIZEOF(long long, 8) if test "$ac_cv_sizeof_short" = "2"; then @@ -1678,16 +1680,37 @@ fi if test "$ac_cv_sizeof_int" = "4"; then int_value=int fi + # Now we need to find what apr_int64_t (sizeof == 8) will be. -# The first match is our preference. -if test "$ac_cv_sizeof_int" = "8"; then +# The first match is our preference (use inttypes if available). +APR_IFALLYES(header:stdint.h header:inttypes.h, hasinttypes="1", hasinttypes="0") +if test "$hasinttypes" = "1"; then + int64_literal='#define APR_INT64_C(val) INT64_C(val)' + uint64_literal='#define APR_UINT64_C(val) UINT64_C(val)' + int64_t_fmt='#define APR_INT64_T_FMT PRId64' + uint64_t_fmt='#define APR_UINT64_T_FMT PRIu64' + uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT PRIx64' + int64_value="int64_t" + uint64_value="uint64_t" + APR_CHECK_TYPES_FMT_COMPATIBLE(int64_t, int, d, [ + int64_strfn="strtoi" + ], [ + APR_CHECK_TYPES_FMT_COMPATIBLE(int64_t, long, ld, [ + int64_strfn="strtol" + ], [ + APR_CHECK_TYPES_FMT_COMPATIBLE(int64_t, long long, lld, [ + int64_strfn="strtoll" + ], [ + AC_ERROR([could not determine the string function for int64_t]) + ])])]) +elif test "$ac_cv_sizeof_int" = "8"; then int64_literal='#define APR_INT64_C(val) (val)' uint64_literal='#define APR_UINT64_C(val) (val##U)' int64_t_fmt='#define APR_INT64_T_FMT "d"' uint64_t_fmt='#define APR_UINT64_T_FMT "u"' uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "x"' int64_value="int" - long_value=int + uint64_value="unsigned int" int64_strfn="strtoi" elif test "$ac_cv_sizeof_long" = "8"; then int64_literal='#define APR_INT64_C(val) (val##L)' @@ -1696,7 +1719,7 @@ elif test "$ac_cv_sizeof_long" = "8"; then uint64_t_fmt='#define APR_UINT64_T_FMT "lu"' uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "lx"' int64_value="long" - long_value=long + uint64_value="unsigned long" int64_strfn="strtol" elif test "$ac_cv_sizeof_long_long" = "8"; then int64_literal='#define APR_INT64_C(val) (val##LL)' @@ -1709,7 +1732,7 @@ elif test "$ac_cv_sizeof_long_long" = "8"; then uint64_t_fmt='#define APR_UINT64_T_FMT "llu"' uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "llx"' int64_value="long long" - long_value="long long" + uint64_value="unsigned long long" int64_strfn="strtoll" elif test "$ac_cv_sizeof_longlong" = "8"; then int64_literal='#define APR_INT64_C(val) (val##LL)' @@ -1718,7 +1741,7 @@ elif test "$ac_cv_sizeof_longlong" = "8"; then uint64_t_fmt='#define APR_UINT64_T_FMT "qu"' uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "qx"' int64_value="__int64" - long_value="__int64" + uint64_value="unsigned __int64" int64_strfn="strtoll" else # int64_literal may be overriden if your compiler thinks you have @@ -1836,7 +1859,7 @@ case $host in uint64_t_fmt='#define APR_UINT64_T_FMT "I64u"' uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "I64x"' int64_value="__int64" - long_value="__int64" + uint64_value="unsigned __int64" int64_strfn="_strtoi64" ;; esac @@ -2010,8 +2033,8 @@ fi AC_SUBST(voidp_size) AC_SUBST(short_value) AC_SUBST(int_value) -AC_SUBST(long_value) AC_SUBST(int64_value) +AC_SUBST(uint64_value) AC_SUBST(off_t_value) AC_SUBST(size_t_value) AC_SUBST(ssize_t_value) diff --git a/include/apr.h.in b/include/apr.h.in index 0a4ba8456..ee99deff1 100644 --- a/include/apr.h.in +++ b/include/apr.h.in @@ -93,6 +93,7 @@ #define APR_HAVE_STDLIB_H @stdlibh@ #define APR_HAVE_STRING_H @stringh@ #define APR_HAVE_STRINGS_H @stringsh@ +#define APR_HAVE_INTTYPES_H @inttypesh@ #define APR_HAVE_SYS_IOCTL_H @sys_ioctlh@ #define APR_HAVE_SYS_SENDFILE_H @sys_sendfileh@ #define APR_HAVE_SYS_SIGNAL_H @sys_signalh@ @@ -168,16 +169,25 @@ #include <sys/socket.h> #endif -#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS) +#if APR_HAVE_STDINT_H +#ifdef __cplusplus /* C99 7.18.4 requires that stdint.h only exposes INT64_C * and UINT64_C for C++ implementations if this is defined: */ +#ifndef __STDC_CONSTANT_MACROS #define __STDC_CONSTANT_MACROS #endif - -#if APR_HAVE_STDINT_H +/* C++ needs this too for PRI*NN formats: */ +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif +#endif /* __cplusplus */ #include <stdint.h> #endif +#if APR_HAVE_INTTYPES_H +#include <inttypes.h> +#endif + #if APR_HAVE_SYS_WAIT_H #include <sys/wait.h> #endif @@ -342,24 +352,28 @@ typedef unsigned @int_value@ apr_uint32_t; */ #ifdef DARWIN_10 #undef APR_SIZEOF_VOIDP -#undef INT64_C -#undef UINT64_C +#undef APR_INT64_C +#undef APR_UINT64_C #ifdef __LP64__ typedef long apr_int64_t; typedef unsigned long apr_uint64_t; #define APR_SIZEOF_VOIDP 8 - #define INT64_C(v) (v ## L) - #define UINT64_C(v) (v ## UL) + #define APR_INT64_C(v) (v ## L) + #define APR_UINT64_C(v) (v ## UL) #else typedef long long apr_int64_t; typedef unsigned long long apr_uint64_t; #define APR_SIZEOF_VOIDP 4 - #define INT64_C(v) (v ## LL) - #define UINT64_C(v) (v ## ULL) + #define APR_INT64_C(v) (v ## LL) + #define APR_UINT64_C(v) (v ## ULL) #endif #else - typedef @long_value@ apr_int64_t; - typedef unsigned @long_value@ apr_uint64_t; + typedef @int64_value@ apr_int64_t; + typedef @uint64_value@ apr_uint64_t; + + /* Mechanisms to properly type numeric literals */ + @int64_literal@ + @uint64_literal@ #endif typedef @size_t_value@ apr_size_t; @@ -377,10 +391,6 @@ typedef apr_uint32_t apr_uintptr_t; /* Are we big endian? */ #define APR_IS_BIGENDIAN @bigendian@ -/* Mechanisms to properly type numeric literals */ -@int64_literal@ -@uint64_literal@ - #ifdef INT16_MIN #define APR_INT16_MIN INT16_MIN #else |