Skip to content

Commit c964c21

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 e55a551 commit c964c21

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
@@ -13915,6 +13915,28 @@ _ACEOF
1391513915
fi
1391613916
done
1391713917

13918+
# strto[u]ll may exist but not be declared
13919+
ac_fn_c_check_decl "$LINENO" "strtoll" "ac_cv_have_decl_strtoll" "$ac_includes_default"
13920+
if test "x$ac_cv_have_decl_strtoll" = xyes; then :
13921+
ac_have_decl=1
13922+
else
13923+
ac_have_decl=0
13924+
fi
13925+
13926+
cat >>confdefs.h <<_ACEOF
13927+
#define HAVE_DECL_STRTOLL $ac_have_decl
13928+
_ACEOF
13929+
ac_fn_c_check_decl "$LINENO" "strtoull" "ac_cv_have_decl_strtoull" "$ac_includes_default"
13930+
if test "x$ac_cv_have_decl_strtoull" = xyes; then :
13931+
ac_have_decl=1
13932+
else
13933+
ac_have_decl=0
13934+
fi
13935+
13936+
cat >>confdefs.h <<_ACEOF
13937+
#define HAVE_DECL_STRTOULL $ac_have_decl
13938+
_ACEOF
13939+
1391813940

1391913941
if test "$with_icu" = yes; then
1392013942
ac_save_CPPFLAGS=$CPPFLAGS

configure.in

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

16601660
AC_CHECK_FUNCS([strtoll strtoq], [break])
16611661
AC_CHECK_FUNCS([strtoull strtouq], [break])
1662+
# strto[u]ll may exist but not be declared
1663+
AC_CHECK_DECLS([strtoll, strtoull])
16621664

16631665
if test "$with_icu" = yes; then
16641666
ac_save_CPPFLAGS=$CPPFLAGS

src/include/c.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,14 @@ extern int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_p
10761076
extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
10771077
#endif
10781078

1079+
#if defined(HAVE_LONG_LONG_INT) && defined(HAVE_STRTOLL) && !HAVE_DECL_STRTOLL
1080+
extern long long strtoll(const char *str, char **endptr, int base);
1081+
#endif
1082+
1083+
#if defined(HAVE_LONG_LONG_INT) && defined(HAVE_STRTOULL) && !HAVE_DECL_STRTOULL
1084+
extern unsigned long long strtoull(const char *str, char **endptr, int base);
1085+
#endif
1086+
10791087
#if !defined(HAVE_MEMMOVE) && !defined(memmove)
10801088
#define memmove(d, s, c) bcopy(s, d, c)
10811089
#endif

src/include/pg_config.h.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@
150150
don't. */
151151
#undef HAVE_DECL_STRLCPY
152152

153+
/* Define to 1 if you have the declaration of `strtoll', and to 0 if you
154+
don't. */
155+
#undef HAVE_DECL_STRTOLL
156+
157+
/* Define to 1 if you have the declaration of `strtoull', and to 0 if you
158+
don't. */
159+
#undef HAVE_DECL_STRTOULL
160+
153161
/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
154162
don't. */
155163
#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
@@ -102,6 +102,14 @@
102102
don't. */
103103
#define HAVE_DECL_SNPRINTF 1
104104

105+
/* Define to 1 if you have the declaration of `strtoll', and to 0 if you
106+
don't. */
107+
#define HAVE_DECL_STRTOLL 1
108+
109+
/* Define to 1 if you have the declaration of `strtoull', and to 0 if you
110+
don't. */
111+
#define HAVE_DECL_STRTOULL 1
112+
105113
/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
106114
don't. */
107115
#define HAVE_DECL_VSNPRINTF 1

0 commit comments

Comments
 (0)