Rely on __func__ being supported
authorAndres Freund <[email protected]>
Sun, 7 Aug 2022 16:36:01 +0000 (09:36 -0700)
committerAndres Freund <[email protected]>
Sun, 7 Aug 2022 16:36:01 +0000 (09:36 -0700)
Previously we fell back to __FUNCTION__ and then NULL. As __func__ is in C99
that shouldn't be necessary anymore.

Solution.pm defined HAVE_FUNCNAME__FUNCTION instead of
HAVE_FUNCNAME__FUNC (originating in 4164e6636e2), as at some point in the past
MSVC only supported __FUNCTION__. Our minimum version supports __func__.

Reviewed-By: Thomas Munro <[email protected]>
Discussion: https://postgr.es/m/20220807012914[email protected]

config/c-compiler.m4
configure
configure.ac
src/backend/storage/lmgr/s_lock.c
src/include/c.h
src/include/pg_config.h.in
src/include/storage/s_lock.h
src/include/utils/elog.h
src/tools/msvc/Solution.pm

index d3562d6feee52f7e95db559c661baea182bb0b2a..69efc5bb10a4e74870846e15a3d1ce42e211802c 100644 (file)
@@ -165,32 +165,6 @@ if (q != holder)
 fi])# PGAC_TYPE_128BIT_INT
 
 
-# PGAC_C_FUNCNAME_SUPPORT
-# -----------------------
-# Check if the C compiler understands __func__ (C99) or __FUNCTION__ (gcc).
-# Define HAVE_FUNCNAME__FUNC or HAVE_FUNCNAME__FUNCTION accordingly.
-AC_DEFUN([PGAC_C_FUNCNAME_SUPPORT],
-[AC_CACHE_CHECK(for __func__, pgac_cv_funcname_func_support,
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>],
-[printf("%s\n", __func__);])],
-[pgac_cv_funcname_func_support=yes],
-[pgac_cv_funcname_func_support=no])])
-if test x"$pgac_cv_funcname_func_support" = xyes ; then
-AC_DEFINE(HAVE_FUNCNAME__FUNC, 1,
-          [Define to 1 if your compiler understands __func__.])
-else
-AC_CACHE_CHECK(for __FUNCTION__, pgac_cv_funcname_function_support,
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>],
-[printf("%s\n", __FUNCTION__);])],
-[pgac_cv_funcname_function_support=yes],
-[pgac_cv_funcname_function_support=no])])
-if test x"$pgac_cv_funcname_function_support" = xyes ; then
-AC_DEFINE(HAVE_FUNCNAME__FUNCTION, 1,
-          [Define to 1 if your compiler understands __FUNCTION__.])
-fi
-fi])# PGAC_C_FUNCNAME_SUPPORT
-
-
 
 # PGAC_C_STATIC_ASSERT
 # --------------------
index 5ee7c2c1a21fb647f9073b96d68605076016b8e8..cdd7a94160ac1cb0f64f01271a3117a974ac851c 100755 (executable)
--- a/configure
+++ b/configure
@@ -14937,67 +14937,6 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __func__" >&5
-$as_echo_n "checking for __func__... " >&6; }
-if ${pgac_cv_funcname_func_support+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <stdio.h>
-int
-main ()
-{
-printf("%s\n", __func__);
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  pgac_cv_funcname_func_support=yes
-else
-  pgac_cv_funcname_func_support=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_funcname_func_support" >&5
-$as_echo "$pgac_cv_funcname_func_support" >&6; }
-if test x"$pgac_cv_funcname_func_support" = xyes ; then
-
-$as_echo "#define HAVE_FUNCNAME__FUNC 1" >>confdefs.h
-
-else
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __FUNCTION__" >&5
-$as_echo_n "checking for __FUNCTION__... " >&6; }
-if ${pgac_cv_funcname_function_support+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <stdio.h>
-int
-main ()
-{
-printf("%s\n", __FUNCTION__);
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  pgac_cv_funcname_function_support=yes
-else
-  pgac_cv_funcname_function_support=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_funcname_function_support" >&5
-$as_echo "$pgac_cv_funcname_function_support" >&6; }
-if test x"$pgac_cv_funcname_function_support" = xyes ; then
-
-$as_echo "#define HAVE_FUNCNAME__FUNCTION 1" >>confdefs.h
-
-fi
-fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _Static_assert" >&5
 $as_echo_n "checking for _Static_assert... " >&6; }
 if ${pgac_cv__static_assert+:} false; then :
index be52e17ea75476782a4e15f86ebbb343cef1ebfa..c3accc91a1987e82645380d63617ba7e5d9e0ea6 100644 (file)
@@ -1635,7 +1635,6 @@ m4_defun([AC_PROG_CC_STDC], []) dnl We don't want that.
 AC_C_BIGENDIAN
 AC_C_INLINE
 PGAC_PRINTF_ARCHETYPE
-PGAC_C_FUNCNAME_SUPPORT
 PGAC_C_STATIC_ASSERT
 PGAC_C_TYPEOF
 PGAC_C_TYPES_COMPATIBLE
index 2a658ff594c3f42c4a6801af1ad91e903a864611..4e473ec27ec75708dccb8cb2b4ea908392f637b1 100644 (file)
@@ -304,7 +304,7 @@ main()
    printf("             if S_LOCK() and TAS() are working.\n");
    fflush(stdout);
 
-   s_lock(&test_lock.lock, __FILE__, __LINE__, PG_FUNCNAME_MACRO);
+   s_lock(&test_lock.lock, __FILE__, __LINE__, __func__);
 
    printf("S_LOCK_TEST: failed, lock not locked\n");
    return 1;
index 8c4baeb0ec379133b6871c85b01f09f6d5d8267c..de9ec04d494ca3065b8cbc1f6161c5cb0539a4aa 100644 (file)
@@ -360,17 +360,6 @@ typedef void (*pg_funcptr_t) (void);
  */
 #define FLEXIBLE_ARRAY_MEMBER  /* empty */
 
-/* Which __func__ symbol do we have, if any? */
-#ifdef HAVE_FUNCNAME__FUNC
-#define PG_FUNCNAME_MACRO  __func__
-#else
-#ifdef HAVE_FUNCNAME__FUNCTION
-#define PG_FUNCNAME_MACRO  __FUNCTION__
-#else
-#define PG_FUNCNAME_MACRO  NULL
-#endif
-#endif
-
 
 /* ----------------------------------------------------------------
  *             Section 2:  bool, true, false
index c243a906c9b541d8782b1a166ebd385826f06965..1007b84fca1b6c89a79e03160dd066c14a10a358 100644 (file)
 /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
 #undef HAVE_FSEEKO
 
-/* Define to 1 if your compiler understands __func__. */
-#undef HAVE_FUNCNAME__FUNC
-
-/* Define to 1 if your compiler understands __FUNCTION__. */
-#undef HAVE_FUNCNAME__FUNCTION
-
 /* Define to 1 if you have __atomic_compare_exchange_n(int *, int *, int). */
 #undef HAVE_GCC__ATOMIC_INT32_CAS
 
index 1c9f6f089546044eb88b6357c9a26bcf5c5915f6..0877cf65b0b25459ee592d6be7f7eef5dffe1d60 100644 (file)
@@ -768,7 +768,7 @@ extern int  tas_sema(volatile slock_t *lock);
 
 #if !defined(S_LOCK)
 #define S_LOCK(lock) \
-   (TAS(lock) ? s_lock((lock), __FILE__, __LINE__, PG_FUNCNAME_MACRO) : 0)
+   (TAS(lock) ? s_lock((lock), __FILE__, __LINE__, __func__) : 0)
 #endif  /* S_LOCK */
 
 #if !defined(S_LOCK_FREE)
@@ -855,7 +855,7 @@ init_spin_delay(SpinDelayStatus *status,
    status->func = func;
 }
 
-#define init_local_spin_delay(status) init_spin_delay(status, __FILE__, __LINE__, PG_FUNCNAME_MACRO)
+#define init_local_spin_delay(status) init_spin_delay(status, __FILE__, __LINE__, __func__)
 extern void perform_spin_delay(SpinDelayStatus *status);
 extern void finish_spin_delay(SpinDelayStatus *status);
 
index 68ead8e8736587cb2d248f9ef5a72f81f4bf7356..5639817690194581c3d03b414ea644e1dadaf9f8 100644 (file)
        if (__builtin_constant_p(elevel) && (elevel) >= ERROR ? \
            errstart_cold(elevel, domain) : \
            errstart(elevel, domain)) \
-           __VA_ARGS__, errfinish(__FILE__, __LINE__, PG_FUNCNAME_MACRO); \
+           __VA_ARGS__, errfinish(__FILE__, __LINE__, __func__); \
        if (__builtin_constant_p(elevel) && (elevel) >= ERROR) \
            pg_unreachable(); \
    } while(0)
        const int elevel_ = (elevel); \
        pg_prevent_errno_in_scope(); \
        if (errstart(elevel_, domain)) \
-           __VA_ARGS__, errfinish(__FILE__, __LINE__, PG_FUNCNAME_MACRO); \
+           __VA_ARGS__, errfinish(__FILE__, __LINE__, __func__); \
        if (elevel_ >= ERROR) \
            pg_unreachable(); \
    } while(0)
index caacb965bbd0fb906e96b64caacaac3faa3556b0..ed03524e46c399a93819150db36505ae1138770d 100644 (file)
@@ -250,8 +250,6 @@ sub GenerateFiles
        HAVE_EXECINFO_H                             => undef,
        HAVE_EXPLICIT_BZERO                         => undef,
        HAVE_FSEEKO                                 => 1,
-       HAVE_FUNCNAME__FUNC                         => undef,
-       HAVE_FUNCNAME__FUNCTION                     => 1,
        HAVE_GCC__ATOMIC_INT32_CAS                  => undef,
        HAVE_GCC__ATOMIC_INT64_CAS                  => undef,
        HAVE_GCC__SYNC_CHAR_TAS                     => undef,