Skip to content

Commit e9f475f

Browse files
committed
Arrange to supply declarations for strtoll/strtoull if needed.
Buildfarm member dromedary is still unhappy about the recently-added ecpg "long long" tests. The reason turns out to be that it includes "-ansi" in its CFLAGS, and in their infinite wisdom Apple have decided to hide the declarations of strtoll/strtoull in C89-compliant builds. (I find it pretty curious that they hide those function declarations when you can nonetheless declare a "long long" variable, but anyway that is their behavior, both on dromedary's obsolete macOS version and the newest and shiniest.) As a result, gcc assumes these functions return "int", leading naturally to wrong results. (Looking at dromedary's past build results, it's evident that this problem also breaks pg_strtouint64() on 32-bit platforms; but we evidently have no regression tests that exercise that function with values above 32 bits.) To fix, supply declarations for these functions when the platform provides the functions but not the declarations, using the same type of mechanism as we use for some other similar cases. Discussion: https://postgr.es/m/151935568942.1461.14623890240535309745@wrigleys.postgresql.org
1 parent d73857d commit e9f475f

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed

configure

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23423,6 +23423,143 @@ _ACEOF
2342323423
fi
2342423424
done
2342523425

23426+
# strto[u]ll may exist but not be declared
23427+
{ $as_echo "$as_me:$LINENO: checking whether strtoll is declared" >&5
23428+
$as_echo_n "checking whether strtoll is declared... " >&6; }
23429+
if test "${ac_cv_have_decl_strtoll+set}" = set; then
23430+
$as_echo_n "(cached) " >&6
23431+
else
23432+
cat >conftest.$ac_ext <<_ACEOF
23433+
/* confdefs.h. */
23434+
_ACEOF
23435+
cat confdefs.h >>conftest.$ac_ext
23436+
cat >>conftest.$ac_ext <<_ACEOF
23437+
/* end confdefs.h. */
23438+
$ac_includes_default
23439+
int
23440+
main ()
23441+
{
23442+
#ifndef strtoll
23443+
(void) strtoll;
23444+
#endif
23445+
23446+
;
23447+
return 0;
23448+
}
23449+
_ACEOF
23450+
rm -f conftest.$ac_objext
23451+
if { (ac_try="$ac_compile"
23452+
case "(($ac_try" in
23453+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
23454+
*) ac_try_echo=$ac_try;;
23455+
esac
23456+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
23457+
$as_echo "$ac_try_echo") >&5
23458+
(eval "$ac_compile") 2>conftest.er1
23459+
ac_status=$?
23460+
grep -v '^ *+' conftest.er1 >conftest.err
23461+
rm -f conftest.er1
23462+
cat conftest.err >&5
23463+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
23464+
(exit $ac_status); } && {
23465+
test -z "$ac_c_werror_flag" ||
23466+
test ! -s conftest.err
23467+
} && test -s conftest.$ac_objext; then
23468+
ac_cv_have_decl_strtoll=yes
23469+
else
23470+
$as_echo "$as_me: failed program was:" >&5
23471+
sed 's/^/| /' conftest.$ac_ext >&5
23472+
23473+
ac_cv_have_decl_strtoll=no
23474+
fi
23475+
23476+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
23477+
fi
23478+
{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_strtoll" >&5
23479+
$as_echo "$ac_cv_have_decl_strtoll" >&6; }
23480+
if test "x$ac_cv_have_decl_strtoll" = x""yes; then
23481+
23482+
cat >>confdefs.h <<_ACEOF
23483+
#define HAVE_DECL_STRTOLL 1
23484+
_ACEOF
23485+
23486+
23487+
else
23488+
cat >>confdefs.h <<_ACEOF
23489+
#define HAVE_DECL_STRTOLL 0
23490+
_ACEOF
23491+
23492+
23493+
fi
23494+
{ $as_echo "$as_me:$LINENO: checking whether strtoull is declared" >&5
23495+
$as_echo_n "checking whether strtoull is declared... " >&6; }
23496+
if test "${ac_cv_have_decl_strtoull+set}" = set; then
23497+
$as_echo_n "(cached) " >&6
23498+
else
23499+
cat >conftest.$ac_ext <<_ACEOF
23500+
/* confdefs.h. */
23501+
_ACEOF
23502+
cat confdefs.h >>conftest.$ac_ext
23503+
cat >>conftest.$ac_ext <<_ACEOF
23504+
/* end confdefs.h. */
23505+
$ac_includes_default
23506+
int
23507+
main ()
23508+
{
23509+
#ifndef strtoull
23510+
(void) strtoull;
23511+
#endif
23512+
23513+
;
23514+
return 0;
23515+
}
23516+
_ACEOF
23517+
rm -f conftest.$ac_objext
23518+
if { (ac_try="$ac_compile"
23519+
case "(($ac_try" in
23520+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
23521+
*) ac_try_echo=$ac_try;;
23522+
esac
23523+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
23524+
$as_echo "$ac_try_echo") >&5
23525+
(eval "$ac_compile") 2>conftest.er1
23526+
ac_status=$?
23527+
grep -v '^ *+' conftest.er1 >conftest.err
23528+
rm -f conftest.er1
23529+
cat conftest.err >&5
23530+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
23531+
(exit $ac_status); } && {
23532+
test -z "$ac_c_werror_flag" ||
23533+
test ! -s conftest.err
23534+
} && test -s conftest.$ac_objext; then
23535+
ac_cv_have_decl_strtoull=yes
23536+
else
23537+
$as_echo "$as_me: failed program was:" >&5
23538+
sed 's/^/| /' conftest.$ac_ext >&5
23539+
23540+
ac_cv_have_decl_strtoull=no
23541+
fi
23542+
23543+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
23544+
fi
23545+
{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_strtoull" >&5
23546+
$as_echo "$ac_cv_have_decl_strtoull" >&6; }
23547+
if test "x$ac_cv_have_decl_strtoull" = x""yes; then
23548+
23549+
cat >>confdefs.h <<_ACEOF
23550+
#define HAVE_DECL_STRTOULL 1
23551+
_ACEOF
23552+
23553+
23554+
else
23555+
cat >>confdefs.h <<_ACEOF
23556+
#define HAVE_DECL_STRTOULL 0
23557+
_ACEOF
23558+
23559+
23560+
fi
23561+
23562+
2342623563

2342723564
{ $as_echo "$as_me:$LINENO: checking for builtin locking functions" >&5
2342823565
$as_echo_n "checking for builtin locking functions... " >&6; }

configure.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,8 @@ fi
15091509

15101510
AC_CHECK_FUNCS([strtoll strtoq], [break])
15111511
AC_CHECK_FUNCS([strtoull strtouq], [break])
1512+
# strto[u]ll may exist but not be declared
1513+
AC_CHECK_DECLS([strtoll, strtoull])
15121514

15131515
AC_CACHE_CHECK([for builtin locking functions], pgac_cv_gcc_int_atomics,
15141516
[AC_TRY_LINK([],

src/include/c.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,14 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
951951
extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
952952
#endif
953953

954+
#if defined(HAVE_LONG_LONG_INT) && defined(HAVE_STRTOLL) && !HAVE_DECL_STRTOLL
955+
extern long long strtoll(const char *str, char **endptr, int base);
956+
#endif
957+
958+
#if defined(HAVE_LONG_LONG_INT) && defined(HAVE_STRTOULL) && !HAVE_DECL_STRTOULL
959+
extern unsigned long long strtoull(const char *str, char **endptr, int base);
960+
#endif
961+
954962
#if !defined(HAVE_MEMMOVE) && !defined(memmove)
955963
#define memmove(d, s, c) bcopy(s, d, c)
956964
#endif

src/include/pg_config.h.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@
135135
don't. */
136136
#undef HAVE_DECL_STRLCPY
137137

138+
/* Define to 1 if you have the declaration of `strtoll', and to 0 if you
139+
don't. */
140+
#undef HAVE_DECL_STRTOLL
141+
142+
/* Define to 1 if you have the declaration of `strtoull', and to 0 if you
143+
don't. */
144+
#undef HAVE_DECL_STRTOULL
145+
138146
/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
139147
don't. */
140148
#undef HAVE_DECL_SYS_SIGLIST

src/include/pg_config.h.win32

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@
9696
don't. */
9797
#define HAVE_DECL_SNPRINTF 1
9898

99+
/* Define to 1 if you have the declaration of `strtoll', and to 0 if you
100+
don't. */
101+
#define HAVE_DECL_STRTOLL 1
102+
103+
/* Define to 1 if you have the declaration of `strtoull', and to 0 if you
104+
don't. */
105+
#define HAVE_DECL_STRTOULL 1
106+
99107
/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
100108
don't. */
101109
#define HAVE_DECL_VSNPRINTF 1

0 commit comments

Comments
 (0)