Factor out the code that detects the long long int snprintf format into a

separate macro.  Also add support for %I64d which is the way on Windows.

The code that checks for the 64-bit int type now gives more reasonable
results when cross-compiling: In that case we just take the compiler's
information and trust that the arithmetic works.  Disabling int64 is too
pessimistic.
This commit is contained in:
Peter Eisentraut 2003-01-28 21:57:12 +00:00
parent c0276244b1
commit 955a1f81a7
4 changed files with 190 additions and 178 deletions

View file

@ -1,5 +1,5 @@
# Macros to detect C compiler features # Macros to detect C compiler features
# $Header: /cvsroot/pgsql/config/c-compiler.m4,v 1.5 2002/03/29 17:32:53 petere Exp $ # $Header: /cvsroot/pgsql/config/c-compiler.m4,v 1.6 2003/01/28 21:57:12 petere Exp $
# PGAC_C_SIGNED # PGAC_C_SIGNED
@ -54,9 +54,11 @@ main() {
}], }],
[Ac_cachevar=yes], [Ac_cachevar=yes],
[Ac_cachevar=no], [Ac_cachevar=no],
[Ac_cachevar=no [# If cross-compiling, check the size reported by the compiler and
dnl We will do better here with Autoconf 2.50 # trust that the arithmetic works.
AC_MSG_WARN([64 bit arithmetic disabled when cross-compiling])])]) AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([], [sizeof($1) == 8])],
Ac_cachevar=yes,
Ac_cachevar=no)])])
Ac_define=$Ac_cachevar Ac_define=$Ac_cachevar
if test x"$Ac_cachevar" = xyes ; then if test x"$Ac_cachevar" = xyes ; then

View file

@ -1,5 +1,5 @@
# Macros that test various C library quirks # Macros that test various C library quirks
# $Header: /cvsroot/pgsql/config/c-library.m4,v 1.14 2002/07/27 20:10:03 petere Exp $ # $Header: /cvsroot/pgsql/config/c-library.m4,v 1.15 2003/01/28 21:57:12 petere Exp $
# PGAC_VAR_INT_TIMEZONE # PGAC_VAR_INT_TIMEZONE
@ -86,3 +86,51 @@ if test x"$pgac_cv_func_posix_signals" = xyes ; then
fi fi
HAVE_POSIX_SIGNALS=$pgac_cv_func_posix_signals HAVE_POSIX_SIGNALS=$pgac_cv_func_posix_signals
AC_SUBST(HAVE_POSIX_SIGNALS)])# PGAC_FUNC_POSIX_SIGNALS AC_SUBST(HAVE_POSIX_SIGNALS)])# PGAC_FUNC_POSIX_SIGNALS
# PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT
# ---------------------------------------
# Determine which format snprintf uses for long long int. We handle
# %lld, %qd, %I64d. The result is in shell variable
# LONG_LONG_INT_FORMAT.
AC_DEFUN([PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT],
[AC_MSG_CHECKING([snprintf format for long long int])
AC_CACHE_VAL(pgac_cv_snprintf_long_long_int_format,
[for pgac_format in '%lld' '%qd' '%I64d'; do
AC_TRY_RUN([#include <stdio.h>
typedef long long int int64;
#define INT64_FORMAT "$pgac_format"
int64 a = 20000001;
int64 b = 40000005;
int does_int64_snprintf_work()
{
int64 c;
char buf[100];
if (sizeof(int64) != 8)
return 0; /* doesn't look like the right size */
c = a * b;
snprintf(buf, 100, INT64_FORMAT, c);
if (strcmp(buf, "800000140000005") != 0)
return 0; /* either multiply or snprintf is busted */
return 1;
}
main() {
exit(! does_int64_snprintf_work());
}],
[pgac_cv_snprintf_long_long_int_format=$pgac_format; break],
[],
[pgac_cv_snprintf_long_long_int_format=cross; break])
done])dnl AC_CACHE_VAL
LONG_LONG_INT_FORMAT=''
case $pgac_cv_snprintf_long_long_int_format in
cross) AC_MSG_RESULT([cannot test (not on host machine)]);;
?*) AC_MSG_RESULT([$pgac_cv_snprintf_long_long_int_format])
LONG_LONG_INT_FORMAT=$pgac_cv_snprintf_long_long_int_format;;
*) AC_MSG_RESULT(none);;
esac])# PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT

213
configure vendored
View file

@ -11817,9 +11817,47 @@ if test "${pgac_cv_type_long_int_64+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6 echo $ECHO_N "(cached) $ECHO_C" >&6
else else
if test "$cross_compiling" = yes; then if test "$cross_compiling" = yes; then
pgac_cv_type_long_int_64=no # If cross-compiling, check the size reported by the compiler and
{ echo "$as_me:$LINENO: WARNING: 64 bit arithmetic disabled when cross-compiling" >&5 # trust that the arithmetic works.
echo "$as_me: WARNING: 64 bit arithmetic disabled when cross-compiling" >&2;} cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
#include "confdefs.h"
#ifdef F77_DUMMY_MAIN
# ifdef __cplusplus
extern "C"
# endif
int F77_DUMMY_MAIN() { return 1; }
#endif
int
main ()
{
static int test_array [1 - 2 * !(sizeof(long int) == 8)];
test_array [0] = 0
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -s conftest.$ac_objext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
pgac_cv_type_long_int_64=yes
else
echo "$as_me: failed program was:" >&5
cat conftest.$ac_ext >&5
pgac_cv_type_long_int_64=no
fi
rm -f conftest.$ac_objext conftest.$ac_ext
else else
cat >conftest.$ac_ext <<_ACEOF cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure" #line $LINENO "configure"
@ -11893,9 +11931,47 @@ if test "${pgac_cv_type_long_long_int_64+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6 echo $ECHO_N "(cached) $ECHO_C" >&6
else else
if test "$cross_compiling" = yes; then if test "$cross_compiling" = yes; then
pgac_cv_type_long_long_int_64=no # If cross-compiling, check the size reported by the compiler and
{ echo "$as_me:$LINENO: WARNING: 64 bit arithmetic disabled when cross-compiling" >&5 # trust that the arithmetic works.
echo "$as_me: WARNING: 64 bit arithmetic disabled when cross-compiling" >&2;} cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
#include "confdefs.h"
#ifdef F77_DUMMY_MAIN
# ifdef __cplusplus
extern "C"
# endif
int F77_DUMMY_MAIN() { return 1; }
#endif
int
main ()
{
static int test_array [1 - 2 * !(sizeof(long long int) == 8)];
test_array [0] = 0
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -s conftest.$ac_objext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
pgac_cv_type_long_long_int_64=yes
else
echo "$as_me: failed program was:" >&5
cat conftest.$ac_ext >&5
pgac_cv_type_long_long_int_64=no
fi
rm -f conftest.$ac_objext conftest.$ac_ext
else else
cat >conftest.$ac_ext <<_ACEOF cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure" #line $LINENO "configure"
@ -12012,25 +12088,29 @@ rm -f conftest.$ac_objext conftest.$ac_ext
fi fi
# If we found "long int" is 64 bits, assume snprintf handles it. If
# we found we need to use "long long int", better check. We cope with
# snprintfs that use either %lld, %qd, or %I64d as the format. If
# neither works, fall back to our own snprintf emulation (which we
# know uses %lld).
if test x"$HAVE_LONG_LONG_INT_64" = xyes ; then if test "$HAVE_LONG_LONG_INT_64" = yes ; then
if test $pgac_need_repl_snprintf = no; then if test $pgac_need_repl_snprintf = no; then
echo "$as_me:$LINENO: checking whether snprintf handles 'long long int' as %lld" >&5 echo "$as_me:$LINENO: checking snprintf format for long long int" >&5
echo $ECHO_N "checking whether snprintf handles 'long long int' as %lld... $ECHO_C" >&6 echo $ECHO_N "checking snprintf format for long long int... $ECHO_C" >&6
if test "$cross_compiling" = yes; then if test "${pgac_cv_snprintf_long_long_int_format+set}" = set; then
echo "$as_me:$LINENO: result: cannot test (not on host machine)" >&5 echo $ECHO_N "(cached) $ECHO_C" >&6
echo "${ECHO_T}cannot test (not on host machine)" >&6 else
# Force usage of our own snprintf, since we cannot test foreign snprintf for pgac_format in '%lld' '%qd' '%I64d'; do
pgac_need_repl_snprintf=yes if test "$cross_compiling" = yes; then
INT64_FORMAT='"%lld"' pgac_cv_snprintf_long_long_int_format=cross; break
else else
cat >conftest.$ac_ext <<_ACEOF cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure" #line $LINENO "configure"
#include "confdefs.h" #include "confdefs.h"
#include <stdio.h> #include <stdio.h>
typedef long long int int64; typedef long long int int64;
#define INT64_FORMAT "%lld" #define INT64_FORMAT "$pgac_format"
int64 a = 20000001; int64 a = 20000001;
int64 b = 40000005; int64 b = 40000005;
@ -12064,91 +12144,38 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
ac_status=$? ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then (exit $ac_status); }; }; then
echo "$as_me:$LINENO: result: yes" >&5 pgac_cv_snprintf_long_long_int_format=$pgac_format; break
echo "${ECHO_T}yes" >&6
INT64_FORMAT='"%lld"'
else else
echo "$as_me: program exited with status $ac_status" >&5 echo "$as_me: program exited with status $ac_status" >&5
echo "$as_me: failed program was:" >&5 echo "$as_me: failed program was:" >&5
cat conftest.$ac_ext >&5 cat conftest.$ac_ext >&5
( exit $ac_status ) fi
echo "$as_me:$LINENO: result: no" >&5 rm -f core core.* *.core conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
echo "${ECHO_T}no" >&6 fi
echo "$as_me:$LINENO: checking whether snprintf handles 'long long int' as %qd" >&5 done
echo $ECHO_N "checking whether snprintf handles 'long long int' as %qd... $ECHO_C" >&6 fi
if test "$cross_compiling" = yes; then
echo "$as_me:$LINENO: result: cannot test (not on host machine)" >&5
echo "${ECHO_T}cannot test (not on host machine)" >&6
# Force usage of our own snprintf, since we cannot test foreign snprintf
pgac_need_repl_snprintf=yes
INT64_FORMAT='"%lld"'
else LONG_LONG_INT_FORMAT=''
cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
#include "confdefs.h"
#include <stdio.h>
typedef long long int int64;
#define INT64_FORMAT "%qd"
int64 a = 20000001; case $pgac_cv_snprintf_long_long_int_format in
int64 b = 40000005; cross) echo "$as_me:$LINENO: result: cannot test (not on host machine)" >&5
echo "${ECHO_T}cannot test (not on host machine)" >&6;;
int does_int64_snprintf_work() ?*) echo "$as_me:$LINENO: result: $pgac_cv_snprintf_long_long_int_format" >&5
{ echo "${ECHO_T}$pgac_cv_snprintf_long_long_int_format" >&6
int64 c; LONG_LONG_INT_FORMAT=$pgac_cv_snprintf_long_long_int_format;;
char buf[100]; *) echo "$as_me:$LINENO: result: none" >&5
echo "${ECHO_T}none" >&6;;
if (sizeof(int64) != 8) esac
return 0; /* doesn't look like the right size */ if test "$LONG_LONG_INT_FORMAT" = ""; then
c = a * b;
snprintf(buf, 100, INT64_FORMAT, c);
if (strcmp(buf, "800000140000005") != 0)
return 0; /* either multiply or snprintf is busted */
return 1;
}
main() {
exit(! does_int64_snprintf_work());
}
_ACEOF
rm -f conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
echo "$as_me:$LINENO: result: yes" >&5
echo "${ECHO_T}yes" >&6
INT64_FORMAT='"%qd"'
else
echo "$as_me: program exited with status $ac_status" >&5
echo "$as_me: failed program was:" >&5
cat conftest.$ac_ext >&5
( exit $ac_status )
echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
# Force usage of our own snprintf, since system snprintf is broken # Force usage of our own snprintf, since system snprintf is broken
pgac_need_repl_snprintf=yes pgac_need_repl_snprintf=yes
INT64_FORMAT='"%lld"' LONG_LONG_INT_FORMAT='%lld'
fi
rm -f core core.* *.core conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
fi
fi
rm -f core core.* *.core conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
fi
else
# here if we previously decided we needed to use our own snprintf
INT64_FORMAT='"%lld"'
fi fi
else
# Here if we previously decided we needed to use our own snprintf
LONG_LONG_INT_FORMAT='%lld'
fi
INT64_FORMAT="\"$LONG_LONG_INT_FORMAT\""
else else
# Here if we are not using 'long long int' at all # Here if we are not using 'long long int' at all
INT64_FORMAT='"%ld"' INT64_FORMAT='"%ld"'

View file

@ -1,5 +1,5 @@
dnl Process this file with autoconf to produce a configure script. dnl Process this file with autoconf to produce a configure script.
dnl $Header: /cvsroot/pgsql/configure.in,v 1.233 2003/01/25 05:19:45 tgl Exp $ dnl $Header: /cvsroot/pgsql/configure.in,v 1.234 2003/01/28 21:57:11 petere Exp $
dnl dnl
dnl Developers, please strive to achieve this order: dnl Developers, please strive to achieve this order:
dnl dnl
@ -970,90 +970,25 @@ long long int foo = INT64CONST(0x1234567890123456);
fi fi
dnl If we found "long int" is 64 bits, assume snprintf handles it. # If we found "long int" is 64 bits, assume snprintf handles it. If
dnl If we found we need to use "long long int", better check. # we found we need to use "long long int", better check. We cope with
dnl We cope with snprintfs that use either %lld or %qd as the format. # snprintfs that use either %lld, %qd, or %I64d as the format. If
dnl If neither works, fall back to our own snprintf emulation (which we # neither works, fall back to our own snprintf emulation (which we
dnl know uses %lld). # know uses %lld).
if test x"$HAVE_LONG_LONG_INT_64" = xyes ; then if test "$HAVE_LONG_LONG_INT_64" = yes ; then
if test $pgac_need_repl_snprintf = no; then if test $pgac_need_repl_snprintf = no; then
AC_MSG_CHECKING(whether snprintf handles 'long long int' as %lld) PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT
AC_TRY_RUN([#include <stdio.h> if test "$LONG_LONG_INT_FORMAT" = ""; then
typedef long long int int64;
#define INT64_FORMAT "%lld"
int64 a = 20000001;
int64 b = 40000005;
int does_int64_snprintf_work()
{
int64 c;
char buf[100];
if (sizeof(int64) != 8)
return 0; /* doesn't look like the right size */
c = a * b;
snprintf(buf, 100, INT64_FORMAT, c);
if (strcmp(buf, "800000140000005") != 0)
return 0; /* either multiply or snprintf is busted */
return 1;
}
main() {
exit(! does_int64_snprintf_work());
}],
[ AC_MSG_RESULT(yes)
INT64_FORMAT='"%lld"'
],
[ AC_MSG_RESULT(no)
AC_MSG_CHECKING(whether snprintf handles 'long long int' as %qd)
AC_TRY_RUN([#include <stdio.h>
typedef long long int int64;
#define INT64_FORMAT "%qd"
int64 a = 20000001;
int64 b = 40000005;
int does_int64_snprintf_work()
{
int64 c;
char buf[100];
if (sizeof(int64) != 8)
return 0; /* doesn't look like the right size */
c = a * b;
snprintf(buf, 100, INT64_FORMAT, c);
if (strcmp(buf, "800000140000005") != 0)
return 0; /* either multiply or snprintf is busted */
return 1;
}
main() {
exit(! does_int64_snprintf_work());
}],
[ AC_MSG_RESULT(yes)
INT64_FORMAT='"%qd"'
],
[ AC_MSG_RESULT(no)
# Force usage of our own snprintf, since system snprintf is broken # Force usage of our own snprintf, since system snprintf is broken
pgac_need_repl_snprintf=yes pgac_need_repl_snprintf=yes
INT64_FORMAT='"%lld"' LONG_LONG_INT_FORMAT='%lld'
],
[ AC_MSG_RESULT([cannot test (not on host machine)])
# Force usage of our own snprintf, since we cannot test foreign snprintf
pgac_need_repl_snprintf=yes
INT64_FORMAT='"%lld"'
]) ],
[ AC_MSG_RESULT([cannot test (not on host machine)])
# Force usage of our own snprintf, since we cannot test foreign snprintf
pgac_need_repl_snprintf=yes
INT64_FORMAT='"%lld"'
])
else
# here if we previously decided we needed to use our own snprintf
INT64_FORMAT='"%lld"'
fi fi
else
# Here if we previously decided we needed to use our own snprintf
LONG_LONG_INT_FORMAT='%lld'
fi
INT64_FORMAT="\"$LONG_LONG_INT_FORMAT\""
else else
# Here if we are not using 'long long int' at all # Here if we are not using 'long long int' at all
INT64_FORMAT='"%ld"' INT64_FORMAT='"%ld"'