Skip to content

Commit 023aa76

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 54ae787 commit 023aa76

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

configure

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12443,6 +12443,28 @@ _ACEOF
1244312443
fi
1244412444
done
1244512445

12446+
# strto[u]ll may exist but not be declared
12447+
ac_fn_c_check_decl "$LINENO" "strtoll" "ac_cv_have_decl_strtoll" "$ac_includes_default"
12448+
if test "x$ac_cv_have_decl_strtoll" = xyes; then :
12449+
ac_have_decl=1
12450+
else
12451+
ac_have_decl=0
12452+
fi
12453+
12454+
cat >>confdefs.h <<_ACEOF
12455+
#define HAVE_DECL_STRTOLL $ac_have_decl
12456+
_ACEOF
12457+
ac_fn_c_check_decl "$LINENO" "strtoull" "ac_cv_have_decl_strtoull" "$ac_includes_default"
12458+
if test "x$ac_cv_have_decl_strtoull" = xyes; then :
12459+
ac_have_decl=1
12460+
else
12461+
ac_have_decl=0
12462+
fi
12463+
12464+
cat >>confdefs.h <<_ACEOF
12465+
#define HAVE_DECL_STRTOULL $ac_have_decl
12466+
_ACEOF
12467+
1244612468

1244712469
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for builtin locking functions" >&5
1244812470
$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
@@ -1546,6 +1546,8 @@ fi
15461546

15471547
AC_CHECK_FUNCS([strtoll strtoq], [break])
15481548
AC_CHECK_FUNCS([strtoull strtouq], [break])
1549+
# strto[u]ll may exist but not be declared
1550+
AC_CHECK_DECLS([strtoll, strtoull])
15491551

15501552
AC_CACHE_CHECK([for builtin locking functions], pgac_cv_gcc_int_atomics,
15511553
[AC_TRY_LINK([],

src/include/c.h

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

963+
#if defined(HAVE_LONG_LONG_INT) && defined(HAVE_STRTOLL) && !HAVE_DECL_STRTOLL
964+
extern long long strtoll(const char *str, char **endptr, int base);
965+
#endif
966+
967+
#if defined(HAVE_LONG_LONG_INT) && defined(HAVE_STRTOULL) && !HAVE_DECL_STRTOULL
968+
extern unsigned long long strtoull(const char *str, char **endptr, int base);
969+
#endif
970+
963971
#if !defined(HAVE_MEMMOVE) && !defined(memmove)
964972
#define memmove(d, s, c) bcopy(s, d, c)
965973
#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)