Skip to content

Commit

Permalink
Use stdint types and inttypes formats when both available.
Browse files Browse the repository at this point in the history
Which should be the case on modern platforms, no change for others.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1856042 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ylavic committed Mar 22, 2019
1 parent e788597 commit 815881e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
6 changes: 5 additions & 1 deletion build/apr_common.m4
Expand Up @@ -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;
Expand Down
45 changes: 34 additions & 11 deletions configure.in
Expand Up @@ -1401,7 +1401,8 @@ APR_FLAG_HEADERS(
errno.h \
fcntl.h \
grp.h \
ifaddrs.h \
ifaddrs.h \
inttypes.h \
io.h \
limits.h \
mach-o/dyld.h \
Expand Down Expand Up @@ -1495,8 +1496,9 @@ AC_SUBST(crypth)
AC_SUBST(errnoh)
AC_SUBST(direnth)
AC_SUBST(fcntlh)
AC_SUBST(ioh)
AC_SUBST(ifaddrsh)
AC_SUBST(inttypesh)
AC_SUBST(ioh)
AC_SUBST(limitsh)
AC_SUBST(mswsockh)
AC_SUBST(netdbh)
Expand Down Expand Up @@ -1594,9 +1596,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
Expand All @@ -1605,16 +1607,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)'
Expand All @@ -1623,7 +1646,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)'
Expand All @@ -1636,7 +1659,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)'
Expand All @@ -1645,7 +1668,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
Expand Down Expand Up @@ -1763,7 +1786,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
Expand Down Expand Up @@ -1943,8 +1966,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)
Expand Down
9 changes: 7 additions & 2 deletions include/apr.h.in
Expand Up @@ -96,6 +96,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@
Expand Down Expand Up @@ -196,6 +197,10 @@
#include <stdint.h>
#endif

#if APR_HAVE_INTTYPES_H
#include <inttypes.h>
#endif

#if APR_HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
Expand Down Expand Up @@ -376,8 +381,8 @@ typedef unsigned @int_value@ apr_uint32_t;
#define 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;
#endif

typedef @size_t_value@ apr_size_t;
Expand Down

0 comments on commit 815881e

Please sign in to comment.