Skip to content

Commit b779168

Browse files
committed
Detect PG_PRINTF_ATTRIBUTE automatically.
This eliminates gobs of "unrecognized format function type" warnings under MinGW compilers predating GCC 4.4.
1 parent b62f94c commit b779168

File tree

5 files changed

+61
-16
lines changed

5 files changed

+61
-16
lines changed

config/c-compiler.m4

+21
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@ fi
5151
])# PGAC_C_INLINE
5252

5353

54+
# PGAC_C_PRINTF_ARCHETYPE
55+
# -----------------------
56+
# Set the format archetype used by gcc to check printf type functions. We
57+
# prefer "gnu_printf", which includes what glibc uses, such as %m for error
58+
# strings and %lld for 64 bit long longs. GCC 4.4 introduced it. It makes a
59+
# dramatic difference on Windows.
60+
AC_DEFUN([PGAC_PRINTF_ARCHETYPE],
61+
[AC_CACHE_CHECK([for printf format archetype], pgac_cv_printf_archetype,
62+
[ac_save_c_werror_flag=$ac_c_werror_flag
63+
ac_c_werror_flag=yes
64+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
65+
[extern int
66+
pgac_write(int ignore, const char *fmt,...)
67+
__attribute__((format(gnu_printf, 2, 3)));], [])],
68+
[pgac_cv_printf_archetype=gnu_printf],
69+
[pgac_cv_printf_archetype=printf])
70+
ac_c_werror_flag=$ac_save_c_werror_flag])
71+
AC_DEFINE_UNQUOTED([PG_PRINTF_ATTRIBUTE], [$pgac_cv_printf_archetype],
72+
[Define to gnu_printf if compiler supports it, else printf.])
73+
])# PGAC_PRINTF_ARCHETYPE
74+
5475

5576
# PGAC_TYPE_64BIT_INT(TYPE)
5677
# -------------------------

configure

+36
Original file line numberDiff line numberDiff line change
@@ -10094,6 +10094,42 @@ _ACEOF
1009410094

1009510095
fi
1009610096

10097+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for printf format archetype" >&5
10098+
$as_echo_n "checking for printf format archetype... " >&6; }
10099+
if ${pgac_cv_printf_archetype+:} false; then :
10100+
$as_echo_n "(cached) " >&6
10101+
else
10102+
ac_save_c_werror_flag=$ac_c_werror_flag
10103+
ac_c_werror_flag=yes
10104+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
10105+
/* end confdefs.h. */
10106+
extern int
10107+
pgac_write(int ignore, const char *fmt,...)
10108+
__attribute__((format(gnu_printf, 2, 3)));
10109+
int
10110+
main ()
10111+
{
10112+
10113+
;
10114+
return 0;
10115+
}
10116+
_ACEOF
10117+
if ac_fn_c_try_compile "$LINENO"; then :
10118+
pgac_cv_printf_archetype=gnu_printf
10119+
else
10120+
pgac_cv_printf_archetype=printf
10121+
fi
10122+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
10123+
ac_c_werror_flag=$ac_save_c_werror_flag
10124+
fi
10125+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_printf_archetype" >&5
10126+
$as_echo "$pgac_cv_printf_archetype" >&6; }
10127+
10128+
cat >>confdefs.h <<_ACEOF
10129+
#define PG_PRINTF_ATTRIBUTE $pgac_cv_printf_archetype
10130+
_ACEOF
10131+
10132+
1009710133

1009810134
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for flexible array members" >&5
1009910135
$as_echo_n "checking for flexible array members... " >&6; }

configure.in

+1
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,7 @@ fi
11701170
m4_defun([AC_PROG_CC_STDC], []) dnl We don't want that.
11711171
AC_C_BIGENDIAN
11721172
PGAC_C_INLINE
1173+
PGAC_PRINTF_ARCHETYPE
11731174
AC_C_FLEXIBLE_ARRAY_MEMBER
11741175
PGAC_C_SIGNED
11751176
PGAC_C_FUNCNAME_SUPPORT

src/include/pg_config.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,9 @@
718718
/* PostgreSQL major version as a string */
719719
#undef PG_MAJORVERSION
720720

721+
/* Define to gnu_printf if compiler supports it, else printf. */
722+
#undef PG_PRINTF_ATTRIBUTE
723+
721724
/* Define to 1 if "static inline" works without unwanted warnings from
722725
compilations where static inline functions are defined but not called. */
723726
#undef PG_USE_INLINE

src/include/pg_config_manual.h

-16
Original file line numberDiff line numberDiff line change
@@ -187,22 +187,6 @@
187187
*/
188188
#define MAX_RANDOM_VALUE (0x7FFFFFFF)
189189

190-
/*
191-
* Set the format style used by gcc to check printf type functions. We really
192-
* want the "gnu_printf" style set, which includes what glibc uses, such
193-
* as %m for error strings and %lld for 64 bit long longs. But not all gcc
194-
* compilers are known to support it, so we just use "printf" which all
195-
* gcc versions alive are known to support, except on Windows where
196-
* using "gnu_printf" style makes a dramatic difference. Maybe someday
197-
* we'll have a configure test for this, if we ever discover use of more
198-
* variants to be necessary.
199-
*/
200-
#ifdef WIN32
201-
#define PG_PRINTF_ATTRIBUTE gnu_printf
202-
#else
203-
#define PG_PRINTF_ATTRIBUTE printf
204-
#endif
205-
206190
/*
207191
* On PPC machines, decide whether to use the mutex hint bit in LWARX
208192
* instructions. Setting the hint bit will slightly improve spinlock

0 commit comments

Comments
 (0)