8000 Arrange to supply declarations for strtoll/strtoull if needed. · limezra/postgres@95fef6e · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.

Commit 95fef6e

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 bc8656c commit 95fef6e

File tree

5 files changed

+48
-0
lines changed
  • src/include
  • 5 files changed

    +48
    -0
    lines changed

    configure

    Lines changed: 22 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -12580,6 +12580,28 @@ _ACEOF
    1258012580
    fi
    1258112581
    done
    1258212582

    12583+
    # strto[u]ll may exist but not be declared
    12584+
    ac_fn_c_check_decl "$LINENO" "strtoll" "ac_cv_have_decl_strtoll" "$ac_includes_default"
    12585+
    if test "x$ac_cv_have_decl_strtoll" = xyes; then :
    12586+
    ac_have_decl=1
    12587+
    else
    12588+
    ac_have_decl=0
    12589+
    fi
    12590+
    12591+
    cat >>confdefs.h <<_ACEOF
    12592+
    #define HAVE_DECL_STRTOLL $ac_have_decl
    12593+
    _ACEOF
    12594+
    ac_fn_c_check_decl "$LINENO" "strtoull" "ac_cv_have_decl_strtoull" "$ac_includes_default"
    12595+
    if test "x$ac_cv_have_decl_strtoull" = xyes; then :
    12596+
    ac_have_decl=1
    12597+
    else
    12598+
    ac_have_decl=0
    12599+
    fi
    12600+
    12601+
    cat >>confdefs.h <<_ACEOF
    12602+
    #define HAVE_DECL_STRTOULL $ac_have_decl
    12603+
    _ACEOF
    12604+
    1258312605

    1258412606
    # Lastly, restore full LIBS list and check for readline/libedit symbols
    1258512607
    LIBS="$LIBS_including_readline"

    configure.in

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

    15721572
    AC_CHECK_FUNCS([strtoll strtoq], [break])
    15731573
    AC_CHECK_FUNCS([strtoull strtouq], [break])
    1574+
    # strto[u]ll may exist but not be declared
    1575+
    AC_CHECK_DECLS([strtoll, strtoull])
    15741576

    15751577
    # Lastly, restore full LIBS list and check for readline/libedit symbols
    15761578
    LIBS="$LIBS_including_readline"

    src/include/c.h

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

    1070+
    #if defined(HAVE_LONG_LONG_INT) && defined(HAVE_STRTOLL) && !HAVE_DECL_STRTOLL
    1071+
    extern long long strtoll(const char *str, char **endptr, int base);
    1072+
    #endif
    1073+
    1074+
    #if defined(HAVE_LONG_LONG_INT) && defined(HAVE_STRTOULL) && !HAVE_DECL_STRTOULL
    1075+
    extern unsigned long long strtoull(const char *str, char **endptr, int base);
    1076+
    #endif
    1077+
    10701078
    #if !defined(HAVE_MEMMOVE) && !defined(memmove)
    10711079
    #define memmove(d, s, c) bcopy(s, d, c)
    10721080
    #endif

    src/include/pg_config.h.in

    Lines changed: 8 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -144,6 +144,14 @@
    144144
    don't. */
    145145
    #undef HAVE_DECL_STRLCPY
    146146

    147+
    /* Define to 1 if you have the declaration of `strtoll', and to 0 if you
    148+
    don't. */
    149+
    #undef HAVE_DECL_STRTOLL
    150+
    151+
    /* Define to 1 if you have the declaration of `strtoull', and to 0 if you
    152+
    don't. */
    153+
    #undef HAVE_DECL_STRTOULL
    154+
    147155
    /* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
    148156
    don't. */
    149157
    #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)
    0