Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a622812

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 e2b83ff commit a622812

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

configure

+22
Original file line numberDiff line numberDiff line change
@@ -15734,6 +15734,28 @@ _ACEOF
1573415734
fi
1573515735
done
1573615736

15737+
# strto[u]ll may exist but not be declared
15738+
ac_fn_c_check_decl "$LINENO" "strtoll" "ac_cv_have_decl_strtoll" "$ac_includes_default"
15739+
if test "x$ac_cv_have_decl_strtoll" = xyes; then :
15740+
ac_have_decl=1
15741+
else
15742+
ac_have_decl=0
15743+
fi
15744+
15745+
cat >>confdefs.h <<_ACEOF
15746+
#define HAVE_DECL_STRTOLL $ac_have_decl
15747+
_ACEOF
15748+
ac_fn_c_check_decl "$LINENO" "strtoull" "ac_cv_have_decl_strtoull" "$ac_includes_default"
15749+
if test "x$ac_cv_have_decl_strtoull" = xyes; then :
15750+
ac_have_decl=1
15751+
else
15752+
ac_have_decl=0
15753+
fi
15754+
15755+
cat >>confdefs.h <<_ACEOF
15756+
#define HAVE_DECL_STRTOULL $ac_have_decl
15757+
_ACEOF
15758+
1573715759

1573815760
if test "$with_icu" = yes; then
1573915761
ac_save_CPPFLAGS=$CPPFLAGS

configure.in

+2
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,8 @@ fi
17511751

17521752
AC_CHECK_FUNCS([strtoll strtoq], [break])
17531753
AC_CHECK_FUNCS([strtoull strtouq], [break])
1754+
# strto[u]ll may exist but not be declared
1755+
AC_CHECK_DECLS([strtoll, strtoull])
17541756

17551757
if test "$with_icu" = yes; then
17561758
ac_save_CPPFLAGS=$CPPFLAGS

src/include/c.h

+8
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,14 @@ extern int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_p
10961096
extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
10971097
#endif
10981098

1099+
#if defined(HAVE_LONG_LONG_INT) && defined(HAVE_STRTOLL) && !HAVE_DECL_STRTOLL
1100+
extern long long strtoll(const char *str, char **endptr, int base);
1101+
#endif
1102+
1103+
#if defined(HAVE_LONG_LONG_INT) && defined(HAVE_STRTOULL) && !HAVE_DECL_STRTOULL
1104+
extern unsigned long long strtoull(const char *str, char **endptr, int base);
1105+
#endif
1106+
10991107
#if !defined(HAVE_MEMMOVE) && !defined(memmove)
11001108
#define memmove(d, s, c) bcopy(s, d, c)
11011109
#endif

src/include/pg_config.h.in

+8
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@
170170
don't. */
171171
#undef HAVE_DECL_STRNLEN
172172

173+
/* Define to 1 if you have the declaration of `strtoll', and to 0 if you
174+
don't. */
175+
#undef HAVE_DECL_STRTOLL
176+
177+
/* Define to 1 if you have the declaration of `strtoull', and to 0 if you
178+
don't. */
179+
#undef HAVE_DECL_STRTOULL
180+
173181
/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
174182
don't. */
175183
#undef HAVE_DECL_SYS_SIGLIST

src/include/pg_config.h.win32

+8
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@
122122
don't. */
123123
#define HAVE_DECL_STRNLEN 1
124124

125+
/* Define to 1 if you have the declaration of `strtoll', and to 0 if you
126+
don't. */
127+
#define HAVE_DECL_STRTOLL 1
128+
129+
/* Define to 1 if you have the declaration of `strtoull', and to 0 if you
130+
don't. */
131+
#define HAVE_DECL_STRTOULL 1
132+
125133
/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
126134
don't. */
127135
#define HAVE_DECL_VSNPRINTF 1

0 commit comments

Comments
 (0)