Skip to content

Commit aed9fa0

Browse files
committed
Select appropriate PG_PRINTF_ATTRIBUTE for recent NetBSD.
NetBSD-current generates a large number of warnings about "%m" not being appropriate to use with *printf functions. While that's true for their native printf, it's surely not true for snprintf.c, so I think they have misunderstood gcc's definition of the "gnu_printf" archetype. Nonetheless, choosing "__syslog__" instead silences the warnings; so teach configure about that. Since this is only a cosmetic warning issue (and anyway it depends on previous hacking to be self-consistent), no back-patch. Discussion: https://postgr.es/m/[email protected]
1 parent c481016 commit aed9fa0

File tree

3 files changed

+61
-17
lines changed

3 files changed

+61
-17
lines changed

config/c-compiler.m4

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,36 @@ fi])# PGAC_C_SIGNED
2121
# -----------------------
2222
# Select the format archetype to be used by gcc to check printf-type functions.
2323
# We prefer "gnu_printf", as that most closely matches the features supported
24-
# by src/port/snprintf.c (particularly the %m conversion spec).
24+
# by src/port/snprintf.c (particularly the %m conversion spec). However,
25+
# on some NetBSD versions, that doesn't work while "__syslog__" does.
26+
# If all else fails, use "printf".
2527
AC_DEFUN([PGAC_PRINTF_ARCHETYPE],
2628
[AC_CACHE_CHECK([for printf format archetype], pgac_cv_printf_archetype,
29+
[pgac_cv_printf_archetype=gnu_printf
30+
PGAC_TEST_PRINTF_ARCHETYPE
31+
if [[ "$ac_archetype_ok" = no ]]; then
32+
pgac_cv_printf_archetype=__syslog__
33+
PGAC_TEST_PRINTF_ARCHETYPE
34+
if [[ "$ac_archetype_ok" = no ]]; then
35+
pgac_cv_printf_archetype=printf
36+
fi
37+
fi])
38+
AC_DEFINE_UNQUOTED([PG_PRINTF_ATTRIBUTE], [$pgac_cv_printf_archetype],
39+
[Define to best printf format archetype, usually gnu_printf if available.])
40+
])# PGAC_PRINTF_ARCHETYPE
41+
42+
# Subroutine: test $pgac_cv_printf_archetype, set $ac_archetype_ok to yes or no
43+
AC_DEFUN([PGAC_TEST_PRINTF_ARCHETYPE],
2744
[ac_save_c_werror_flag=$ac_c_werror_flag
2845
ac_c_werror_flag=yes
2946
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
30-
[extern int
31-
pgac_write(int ignore, const char *fmt,...)
32-
__attribute__((format(gnu_printf, 2, 3)));], [])],
33-
[pgac_cv_printf_archetype=gnu_printf],
34-
[pgac_cv_printf_archetype=printf])
35-
ac_c_werror_flag=$ac_save_c_werror_flag])
36-
AC_DEFINE_UNQUOTED([PG_PRINTF_ATTRIBUTE], [$pgac_cv_printf_archetype],
37-
[Define to gnu_printf if compiler supports it, else printf.])
38-
])# PGAC_PRINTF_ARCHETYPE
47+
[extern void pgac_write(int ignore, const char *fmt,...)
48+
__attribute__((format($pgac_cv_printf_archetype, 2, 3)));],
49+
[pgac_write(0, "error %s: %m", "foo");])],
50+
[ac_archetype_ok=yes],
51+
[ac_archetype_ok=no])
52+
ac_c_werror_flag=$ac_save_c_werror_flag
53+
])# PGAC_TEST_PRINTF_ARCHETYPE
3954

4055

4156
# PGAC_TYPE_64BIT_INT(TYPE)

configure

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13583,28 +13583,57 @@ $as_echo_n "checking for printf format archetype... " >&6; }
1358313583
if ${pgac_cv_printf_archetype+:} false; then :
1358413584
$as_echo_n "(cached) " >&6
1358513585
else
13586-
ac_save_c_werror_flag=$ac_c_werror_flag
13586+
pgac_cv_printf_archetype=gnu_printf
13587+
ac_save_c_werror_flag=$ac_c_werror_flag
1358713588
ac_c_werror_flag=yes
1358813589
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1358913590
/* end confdefs.h. */
13590-
extern int
13591-
pgac_write(int ignore, const char *fmt,...)
13592-
__attribute__((format(gnu_printf, 2, 3)));
13591+
extern void pgac_write(int ignore, const char *fmt,...)
13592+
__attribute__((format($pgac_cv_printf_archetype, 2, 3)));
1359313593
int
1359413594
main ()
1359513595
{
13596+
pgac_write(0, "error %s: %m", "foo");
13597+
;
13598+
return 0;
13599+
}
13600+
_ACEOF
13601+
if ac_fn_c_try_compile "$LINENO"; then :
13602+
ac_archetype_ok=yes
13603+
else
13604+
ac_archetype_ok=no
13605+
fi
13606+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
13607+
ac_c_werror_flag=$ac_save_c_werror_flag
1359613608

13609+
if [ "$ac_archetype_ok" = no ]; then
13610+
pgac_cv_printf_archetype=__syslog__
13611+
ac_save_c_werror_flag=$ac_c_werror_flag
13612+
ac_c_werror_flag=yes
13613+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13614+
/* end confdefs.h. */
13615+
extern void pgac_write(int ignore, const char *fmt,...)
13616+
__attribute__((format($pgac_cv_printf_archetype, 2, 3)));
13617+
int
13618+
main ()
13619+
{
13620+
pgac_write(0, "error %s: %m", "foo");
1359713621
;
1359813622
return 0;
1359913623
}
1360013624
_ACEOF
1360113625
if ac_fn_c_try_compile "$LINENO"; then :
13602-
pgac_cv_printf_archetype=gnu_printf
13626+
ac_archetype_ok=yes
1360313627
else
13604-
pgac_cv_printf_archetype=printf
13628+
ac_archetype_ok=no
1360513629
fi
1360613630
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
1360713631
ac_c_werror_flag=$ac_save_c_werror_flag
13632+
13633+
if [ "$ac_archetype_ok" = no ]; then
13634+
pgac_cv_printf_archetype=printf
13635+
fi
13636+
fi
1360813637
fi
1360913638
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_printf_archetype" >&5
1361013639
$as_echo "$pgac_cv_printf_archetype" >&6; }

src/include/pg_config.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@
804804
/* PostgreSQL major version as a string */
805805
#undef PG_MAJORVERSION
806806

807-
/* Define to gnu_printf if compiler supports it, else printf. */
807+
/* Define to best printf format archetype, usually gnu_printf if available. */
808808
#undef PG_PRINTF_ATTRIBUTE
809809

810810
/* PostgreSQL version as a string */

0 commit comments

Comments
 (0)