Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit955a1f8

Browse files
committed
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 reasonableresults when cross-compiling: In that case we just take the compiler'sinformation and trust that the arithmetic works. Disabling int64 is toopessimistic.
1 parentc027624 commit955a1f8

File tree

4 files changed

+190
-178
lines changed

4 files changed

+190
-178
lines changed

‎config/c-compiler.m4

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Macros to detect C compiler features
2-
# $Header: /cvsroot/pgsql/config/c-compiler.m4,v 1.5 2002/03/29 17:32:53 petere Exp $
2+
# $Header: /cvsroot/pgsql/config/c-compiler.m4,v 1.6 2003/01/28 21:57:12 petere Exp $
33

44

55
# PGAC_C_SIGNED
@@ -54,9 +54,11 @@ main() {
5454
}],
5555
[Ac_cachevar=yes],
5656
[Ac_cachevar=no],
57-
[Ac_cachevar=no
58-
dnl We will do better here with Autoconf 2.50
59-
AC_MSG_WARN([64 bit arithmetic disabled when cross-compiling])])])
57+
[# If cross-compiling, check the size reported by the compiler and
58+
# trust that the arithmetic works.
59+
AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([],[sizeof($1) == 8])],
60+
Ac_cachevar=yes,
61+
Ac_cachevar=no)])])
6062
6163
Ac_define=$Ac_cachevar
6264
if test x"$Ac_cachevar" = xyes ; then

‎config/c-library.m4

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Macros that test various C library quirks
2-
# $Header: /cvsroot/pgsql/config/c-library.m4,v 1.14 2002/07/27 20:10:03 petere Exp $
2+
# $Header: /cvsroot/pgsql/config/c-library.m4,v 1.15 2003/01/28 21:57:12 petere Exp $
33

44

55
# PGAC_VAR_INT_TIMEZONE
@@ -86,3 +86,51 @@ if test x"$pgac_cv_func_posix_signals" = xyes ; then
8686
fi
8787
HAVE_POSIX_SIGNALS=$pgac_cv_func_posix_signals
8888
AC_SUBST(HAVE_POSIX_SIGNALS)])# PGAC_FUNC_POSIX_SIGNALS
89+
90+
91+
# PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT
92+
# ---------------------------------------
93+
# Determine which format snprintf uses for long long int. We handle
94+
# %lld, %qd, %I64d. The result is in shell variable
95+
# LONG_LONG_INT_FORMAT.
96+
AC_DEFUN([PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT],
97+
[AC_MSG_CHECKING([snprintf format for long long int])
98+
AC_CACHE_VAL(pgac_cv_snprintf_long_long_int_format,
99+
[for pgac_format in '%lld' '%qd' '%I64d'; do
100+
AC_TRY_RUN([#include <stdio.h>
101+
typedef long long int int64;
102+
#define INT64_FORMAT "$pgac_format"
103+
104+
int64 a = 20000001;
105+
int64 b = 40000005;
106+
107+
int does_int64_snprintf_work()
108+
{
109+
int64 c;
110+
char buf[100];
111+
112+
if (sizeof(int64) != 8)
113+
return 0;/* doesn't look like the right size */
114+
115+
c = a * b;
116+
snprintf(buf, 100, INT64_FORMAT, c);
117+
if (strcmp(buf, "800000140000005") != 0)
118+
return 0;/* either multiply or snprintf is busted */
119+
return 1;
120+
}
121+
main() {
122+
exit(! does_int64_snprintf_work());
123+
}],
124+
[pgac_cv_snprintf_long_long_int_format=$pgac_format; break],
125+
[],
126+
[pgac_cv_snprintf_long_long_int_format=cross; break])
127+
done])dnl AC_CACHE_VAL
128+
129+
LONG_LONG_INT_FORMAT=''
130+
131+
case $pgac_cv_snprintf_long_long_int_format in
132+
cross)AC_MSG_RESULT([cannot test (not on host machine)]);;
133+
?*)AC_MSG_RESULT([$pgac_cv_snprintf_long_long_int_format])
134+
LONG_LONG_INT_FORMAT=$pgac_cv_snprintf_long_long_int_format;;
135+
*)AC_MSG_RESULT(none);;
136+
esac])# PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT

‎configure

Lines changed: 119 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -11817,9 +11817,47 @@ if test "${pgac_cv_type_long_int_64+set}" = set; then
1181711817
echo$ECHO_N"(cached)$ECHO_C">&6
1181811818
else
1181911819
iftest"$cross_compiling" = yes;then
11820-
pgac_cv_type_long_int_64=no
11821-
{echo"$as_me:$LINENO: WARNING: 64 bit arithmetic disabled when cross-compiling">&5
11822-
echo"$as_me: WARNING: 64 bit arithmetic disabled when cross-compiling">&2;}
11820+
# If cross-compiling, check the size reported by the compiler and
11821+
# trust that the arithmetic works.
11822+
cat>conftest.$ac_ext<<_ACEOF
11823+
#line$LINENO "configure"
11824+
#include "confdefs.h"
11825+
11826+
#ifdef F77_DUMMY_MAIN
11827+
# ifdef __cplusplus
11828+
extern "C"
11829+
# endif
11830+
int F77_DUMMY_MAIN() { return 1; }
11831+
#endif
11832+
int
11833+
main ()
11834+
{
11835+
static int test_array [1 - 2 * !(sizeof(long int) == 8)];
11836+
test_array [0] = 0
11837+
11838+
;
11839+
return 0;
11840+
}
11841+
_ACEOF
11842+
rm -f conftest.$ac_objext
11843+
if { (evalecho"$as_me:$LINENO:\"$ac_compile\"")>&5
11844+
(eval$ac_compile)2>&5
11845+
ac_status=$?
11846+
echo"$as_me:$LINENO:\$? =$ac_status">&5
11847+
(exit$ac_status); }&&
11848+
{ ac_try='test -s conftest.$ac_objext'
11849+
{ (evalecho"$as_me:$LINENO:\"$ac_try\"")>&5
11850+
(eval$ac_try)2>&5
11851+
ac_status=$?
11852+
echo"$as_me:$LINENO:\$? =$ac_status">&5
11853+
(exit$ac_status); }; };then
11854+
pgac_cv_type_long_int_64=yes
11855+
else
11856+
echo"$as_me: failed program was:">&5
11857+
cat conftest.$ac_ext>&5
11858+
pgac_cv_type_long_int_64=no
11859+
fi
11860+
rm -f conftest.$ac_objext conftest.$ac_ext
1182311861
else
1182411862
cat>conftest.$ac_ext<<_ACEOF
1182511863
#line$LINENO "configure"
@@ -11893,9 +11931,47 @@ if test "${pgac_cv_type_long_long_int_64+set}" = set; then
1189311931
echo$ECHO_N"(cached)$ECHO_C">&6
1189411932
else
1189511933
iftest"$cross_compiling" = yes;then
11896-
pgac_cv_type_long_long_int_64=no
11897-
{echo"$as_me:$LINENO: WARNING: 64 bit arithmetic disabled when cross-compiling">&5
11898-
echo"$as_me: WARNING: 64 bit arithmetic disabled when cross-compiling">&2;}
11934+
# If cross-compiling, check the size reported by the compiler and
11935+
# trust that the arithmetic works.
11936+
cat>conftest.$ac_ext<<_ACEOF
11937+
#line$LINENO "configure"
11938+
#include "confdefs.h"
11939+
11940+
#ifdef F77_DUMMY_MAIN
11941+
# ifdef __cplusplus
11942+
extern "C"
11943+
# endif
11944+
int F77_DUMMY_MAIN() { return 1; }
11945+
#endif
11946+
int
11947+
main ()
11948+
{
11949+
static int test_array [1 - 2 * !(sizeof(long long int) == 8)];
11950+
test_array [0] = 0
11951+
11952+
;
11953+
return 0;
11954+
}
11955+
_ACEOF
11956+
rm -f conftest.$ac_objext
11957+
if { (evalecho"$as_me:$LINENO:\"$ac_compile\"")>&5
11958+
(eval$ac_compile)2>&5
11959+
ac_status=$?
11960+
echo"$as_me:$LINENO:\$? =$ac_status">&5
11961+
(exit$ac_status); }&&
11962+
{ ac_try='test -s conftest.$ac_objext'
11963+
{ (evalecho"$as_me:$LINENO:\"$ac_try\"")>&5
11964+
(eval$ac_try)2>&5
11965+
ac_status=$?
11966+
echo"$as_me:$LINENO:\$? =$ac_status">&5
11967+
(exit$ac_status); }; };then
11968+
pgac_cv_type_long_long_int_64=yes
11969+
else
11970+
echo"$as_me: failed program was:">&5
11971+
cat conftest.$ac_ext>&5
11972+
pgac_cv_type_long_long_int_64=no
11973+
fi
11974+
rm -f conftest.$ac_objext conftest.$ac_ext
1189911975
else
1190011976
cat>conftest.$ac_ext<<_ACEOF
1190111977
#line$LINENO "configure"
@@ -12012,25 +12088,29 @@ rm -f conftest.$ac_objext conftest.$ac_ext
1201212088
fi
1201312089
1201412090
12091+
# If we found "long int" is 64 bits, assume snprintf handles it. If
12092+
# we found we need to use "long long int", better check. We cope with
12093+
# snprintfs that use either %lld, %qd, or %I64d as the format. If
12094+
# neither works, fall back to our own snprintf emulation (which we
12095+
# know uses %lld).
1201512096
12016-
iftestx"$HAVE_LONG_LONG_INT_64" =xyes;then
12097+
iftest"$HAVE_LONG_LONG_INT_64" =yes;then
1201712098
iftest$pgac_need_repl_snprintf = no;then
12018-
echo"$as_me:$LINENO: checking whether snprintf handles 'long long int' as %lld">&5
12019-
echo$ECHO_N"checking whether snprintf handles 'long long int' as %lld...$ECHO_C">&6
12020-
iftest"$cross_compiling" = yes;then
12021-
echo"$as_me:$LINENO: result: cannot test (not on host machine)">&5
12022-
echo"${ECHO_T}cannot test (not on host machine)">&6
12023-
# Force usage of our own snprintf, since we cannot test foreign snprintf
12024-
pgac_need_repl_snprintf=yes
12025-
INT64_FORMAT='"%lld"'
12026-
12099+
echo"$as_me:$LINENO: checking snprintf format for long long int">&5
12100+
echo$ECHO_N"checking snprintf format for long long int...$ECHO_C">&6
12101+
iftest"${pgac_cv_snprintf_long_long_int_format+set}" =set;then
12102+
echo$ECHO_N"(cached)$ECHO_C">&6
12103+
else
12104+
forpgac_formatin'%lld''%qd''%I64d';do
12105+
iftest"$cross_compiling" = yes;then
12106+
pgac_cv_snprintf_long_long_int_format=cross;break
1202712107
else
1202812108
cat>conftest.$ac_ext<<_ACEOF
1202912109
#line$LINENO "configure"
1203012110
#include "confdefs.h"
1203112111
#include <stdio.h>
1203212112
typedef long long int int64;
12033-
#define INT64_FORMAT "%lld"
12113+
#define INT64_FORMAT "$pgac_format"
1203412114
1203512115
int64 a = 20000001;
1203612116
int64 b = 40000005;
@@ -12064,91 +12144,38 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
1206412144
ac_status=$?
1206512145
echo"$as_me:$LINENO:\$? =$ac_status">&5
1206612146
(exit$ac_status); }; };then
12067-
echo"$as_me:$LINENO: result: yes">&5
12068-
echo"${ECHO_T}yes">&6
12069-
INT64_FORMAT='"%lld"'
12070-
12147+
pgac_cv_snprintf_long_long_int_format=$pgac_format;break
1207112148
else
1207212149
echo"$as_me: program exited with status$ac_status">&5
1207312150
echo"$as_me: failed program was:">&5
1207412151
cat conftest.$ac_ext>&5
12075-
(exit$ac_status )
12076-
echo"$as_me:$LINENO: result: no">&5
12077-
echo"${ECHO_T}no">&6
12078-
echo"$as_me:$LINENO: checking whether snprintf handles 'long long int' as %qd">&5
12079-
echo$ECHO_N"checking whether snprintf handles 'long long int' as %qd...$ECHO_C">&6
12080-
iftest"$cross_compiling" = yes;then
12081-
echo"$as_me:$LINENO: result: cannot test (not on host machine)">&5
12082-
echo"${ECHO_T}cannot test (not on host machine)">&6
12083-
# Force usage of our own snprintf, since we cannot test foreign snprintf
12084-
pgac_need_repl_snprintf=yes
12085-
INT64_FORMAT='"%lld"'
12086-
12087-
else
12088-
cat>conftest.$ac_ext<<_ACEOF
12089-
#line$LINENO "configure"
12090-
#include "confdefs.h"
12091-
#include <stdio.h>
12092-
typedef long long int int64;
12093-
#define INT64_FORMAT "%qd"
12094-
12095-
int64 a = 20000001;
12096-
int64 b = 40000005;
12097-
12098-
int does_int64_snprintf_work()
12099-
{
12100-
int64 c;
12101-
char buf[100];
12102-
12103-
if (sizeof(int64) != 8)
12104-
return 0; /* doesn't look like the right size */
12105-
12106-
c = a * b;
12107-
snprintf(buf, 100, INT64_FORMAT, c);
12108-
if (strcmp(buf, "800000140000005") != 0)
12109-
return 0; /* either multiply or snprintf is busted */
12110-
return 1;
12111-
}
12112-
main() {
12113-
exit(! does_int64_snprintf_work());
12114-
}
12115-
_ACEOF
12116-
rm -f conftest$ac_exeext
12117-
if { (evalecho"$as_me:$LINENO:\"$ac_link\"")>&5
12118-
(eval$ac_link)2>&5
12119-
ac_status=$?
12120-
echo"$as_me:$LINENO:\$? =$ac_status">&5
12121-
(exit$ac_status); }&& { ac_try='./conftest$ac_exeext'
12122-
{ (evalecho"$as_me:$LINENO:\"$ac_try\"")>&5
12123-
(eval$ac_try)2>&5
12124-
ac_status=$?
12125-
echo"$as_me:$LINENO:\$? =$ac_status">&5
12126-
(exit$ac_status); }; };then
12127-
echo"$as_me:$LINENO: result: yes">&5
12128-
echo"${ECHO_T}yes">&6
12129-
INT64_FORMAT='"%qd"'
12130-
12131-
else
12132-
echo"$as_me: program exited with status$ac_status">&5
12133-
echo"$as_me: failed program was:">&5
12134-
cat conftest.$ac_ext>&5
12135-
(exit$ac_status )
12136-
echo"$as_me:$LINENO: result: no">&5
12137-
echo"${ECHO_T}no">&6
12138-
# Force usage of our own snprintf, since system snprintf is broken
12139-
pgac_need_repl_snprintf=yes
12140-
INT64_FORMAT='"%lld"'
12141-
1214212152
fi
1214312153
rm -f core core.**.core conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
1214412154
fi
12155+
done
1214512156
fi
12146-
rm -f core core.**.core conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
12147-
fi
12157+
12158+
LONG_LONG_INT_FORMAT=''
12159+
12160+
case$pgac_cv_snprintf_long_long_int_formatin
12161+
cross)echo"$as_me:$LINENO: result: cannot test (not on host machine)">&5
12162+
echo"${ECHO_T}cannot test (not on host machine)">&6;;
12163+
?*)echo"$as_me:$LINENO: result:$pgac_cv_snprintf_long_long_int_format">&5
12164+
echo"${ECHO_T}$pgac_cv_snprintf_long_long_int_format">&6
12165+
LONG_LONG_INT_FORMAT=$pgac_cv_snprintf_long_long_int_format;;
12166+
*)echo"$as_me:$LINENO: result: none">&5
12167+
echo"${ECHO_T}none">&6;;
12168+
esac
12169+
iftest"$LONG_LONG_INT_FORMAT" ="";then
12170+
# Force usage of our own snprintf, since system snprintf is broken
12171+
pgac_need_repl_snprintf=yes
12172+
LONG_LONG_INT_FORMAT='%lld'
12173+
fi
1214812174
else
12149-
#here if we previously decided we needed to use our own snprintf
12150-
INT64_FORMAT='"%lld"'
12175+
#Here if we previously decided we needed to use our own snprintf
12176+
LONG_LONG_INT_FORMAT='%lld'
1215112177
fi
12178+
INT64_FORMAT="\"$LONG_LONG_INT_FORMAT\""
1215212179
else
1215312180
# Here if we are not using 'long long int' at all
1215412181
INT64_FORMAT='"%ld"'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp