Skip to content

Commit 46b5e7c

Browse files
committed
Revert "Distinguish printf-like functions that support %m from those that don't."
This reverts commit 3a60c8f. Buildfarm results show that that caused a whole bunch of new warnings on platforms where gcc believes the local printf to be non-POSIX-compliant. This problem outweighs the hypothetical-anyway possibility of getting warnings for misuse of %m. We could use gnu_printf archetype when we've substituted src/port/snprintf.c, but that brings us right back to the problem of not getting warnings for %m. A possible answer is to attack it in the other direction by insisting that %m support be included in printf's feature set, but that will take more investigation. In the meantime, revert the previous change, and update the comment for PGAC_C_PRINTF_ARCHETYPE to more fully explain what's going on. Discussion: https://postgr.es/m/2975.1526862605@sss.pgh.pa.us
1 parent d11eae0 commit 46b5e7c

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
lines changed

config/c-compiler.m4

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ fi])# PGAC_C_SIGNED
1919

2020
# PGAC_C_PRINTF_ARCHETYPE
2121
# -----------------------
22-
# Set the format archetype used by gcc to check elog/ereport functions.
23-
# This should accept %m, whether or not the platform's printf does.
24-
# We use "gnu_printf" if possible, which does that, although in some cases
25-
# it might do more than we could wish.
22+
# Select the format archetype to be used by gcc to check printf-type functions.
23+
# We prefer "gnu_printf", which matches the features glibc supports, notably
24+
# %m, 'z' and 'll' width modifiers ('ll' only matters if int64 requires it),
25+
# and argument order control if we're doing --enable-nls. On platforms where
26+
# the native printf doesn't have 'z'/'ll' or arg control, we replace it with
27+
# src/port/snprintf.c which does, so that the only potential mismatch here is
28+
# whether or not %m is supported. We need that for elog/ereport, so we live
29+
# with the fact that erroneous use of %m in plain printf calls won't be
30+
# detected. (It appears that many versions of gcc/clang wouldn't report it
31+
# even if told to check according to plain printf archetype, anyway.)
2632
AC_DEFUN([PGAC_PRINTF_ARCHETYPE],
27-
[AC_CACHE_CHECK([for printf format archetype for %m], pgac_cv_printf_archetype,
33+
[AC_CACHE_CHECK([for printf format archetype], pgac_cv_printf_archetype,
2834
[ac_save_c_werror_flag=$ac_c_werror_flag
2935
ac_c_werror_flag=yes
3036
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
@@ -34,8 +40,8 @@ __attribute__((format(gnu_printf, 2, 3)));], [])],
3440
[pgac_cv_printf_archetype=gnu_printf],
3541
[pgac_cv_printf_archetype=printf])
3642
ac_c_werror_flag=$ac_save_c_werror_flag])
37-
AC_DEFINE_UNQUOTED([PG_PRINTF_ATTRIBUTE_M], [$pgac_cv_printf_archetype],
38-
[Define as a format archetype that accepts %m, if available, else printf.])
43+
AC_DEFINE_UNQUOTED([PG_PRINTF_ATTRIBUTE], [$pgac_cv_printf_archetype],
44+
[Define to gnu_printf if compiler supports it, else printf.])
3945
])# PGAC_PRINTF_ARCHETYPE
4046

4147

configure

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13362,8 +13362,8 @@ _ACEOF
1336213362
;;
1336313363
esac
1336413364

13365-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for printf format archetype for %m" >&5
13366-
$as_echo_n "checking for printf format archetype for %m... " >&6; }
13365+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for printf format archetype" >&5
13366+
$as_echo_n "checking for printf format archetype... " >&6; }
1336713367
if ${pgac_cv_printf_archetype+:} false; then :
1336813368
$as_echo_n "(cached) " >&6
1336913369
else
@@ -13394,7 +13394,7 @@ fi
1339413394
$as_echo "$pgac_cv_printf_archetype" >&6; }
1339513395

1339613396
cat >>confdefs.h <<_ACEOF
13397-
#define PG_PRINTF_ATTRIBUTE_M $pgac_cv_printf_archetype
13397+
#define PG_PRINTF_ATTRIBUTE $pgac_cv_printf_archetype
1339813398
_ACEOF
1339913399

1340013400

src/include/c.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,10 @@
126126
/* GCC and XLC support format attributes */
127127
#if defined(__GNUC__) || defined(__IBMC__)
128128
#define pg_attribute_format_arg(a) __attribute__((format_arg(a)))
129-
/* Use for functions wrapping stdio's printf, which often doesn't take %m: */
130-
#define pg_attribute_printf(f,a) __attribute__((format(printf, f, a)))
131-
/* Use for elog/ereport, which implement %m for themselves: */
132-
#define pg_attribute_printf_m(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE_M, f, a)))
129+
#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
133130
#else
134131
#define pg_attribute_format_arg(a)
135132
#define pg_attribute_printf(f,a)
136-
#define pg_attribute_printf_m(f,a)
137133
#endif
138134

139135
/* GCC, Sunpro and XLC support aligned, packed and noreturn */

src/include/pg_config.h.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@
809809
/* PostgreSQL major version as a string */
810810
#undef PG_MAJORVERSION
811811

812-
/* Define as a format archetype that accepts %m, if available, else printf. */
813-
#undef PG_PRINTF_ATTRIBUTE_M
812+
/* Define to gnu_printf if compiler supports it, else printf. */
813+
#undef PG_PRINTF_ATTRIBUTE
814814

815815
/* PostgreSQL version as a string */
816816
#undef PG_VERSION

src/include/utils/elog.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,25 +152,25 @@ extern int errcode(int sqlerrcode);
152152
extern int errcode_for_file_access(void);
153153
extern int errcode_for_socket_access(void);
154154

155-
extern int errmsg(const char *fmt,...) pg_attribute_printf_m(1, 2);
156-
extern int errmsg_internal(const char *fmt,...) pg_attribute_printf_m(1, 2);
155+
extern int errmsg(const char *fmt,...) pg_attribute_printf(1, 2);
156+
extern int errmsg_internal(const char *fmt,...) pg_attribute_printf(1, 2);
157157

158158
extern int errmsg_plural(const char *fmt_singular, const char *fmt_plural,
159-
unsigned long n,...) pg_attribute_printf_m(1, 4) pg_attribute_printf_m(2, 4);
159+
unsigned long n,...) pg_attribute_printf(1, 4) pg_attribute_printf(2, 4);
160160

161-
extern int errdetail(const char *fmt,...) pg_attribute_printf_m(1, 2);
162-
extern int errdetail_internal(const char *fmt,...) pg_attribute_printf_m(1, 2);
161+
extern int errdetail(const char *fmt,...) pg_attribute_printf(1, 2);
162+
extern int errdetail_internal(const char *fmt,...) pg_attribute_printf(1, 2);
163163

164-
extern int errdetail_log(const char *fmt,...) pg_attribute_printf_m(1, 2);
164+
extern int errdetail_log(const char *fmt,...) pg_attribute_printf(1, 2);
165165

166166
extern int errdetail_log_plural(const char *fmt_singular,
167167
const char *fmt_plural,
168-
unsigned long n,...) pg_attribute_printf_m(1, 4) pg_attribute_printf_m(2, 4);
168+
unsigned long n,...) pg_attribute_printf(1, 4) pg_attribute_printf(2, 4);
169169

170170
extern int errdetail_plural(const char *fmt_singular, const char *fmt_plural,
171-
unsigned long n,...) pg_attribute_printf_m(1, 4) pg_attribute_printf_m(2, 4);
171+
unsigned long n,...) pg_attribute_printf(1, 4) pg_attribute_printf(2, 4);
172172

173-
extern int errhint(const char *fmt,...) pg_attribute_printf_m(1, 2);
173+
extern int errhint(const char *fmt,...) pg_attribute_printf(1, 2);
174174

175175
/*
176176
* errcontext() is typically called in error context callback functions, not
@@ -184,7 +184,7 @@ extern int errhint(const char *fmt,...) pg_attribute_printf_m(1, 2);
184184

185185
extern int set_errcontext_domain(const char *domain);
186186

187-
extern int errcontext_msg(const char *fmt,...) pg_attribute_printf_m(1, 2);
187+
extern int errcontext_msg(const char *fmt,...) pg_attribute_printf(1, 2);
188188

189189
extern int errhidestmt(bool hide_stmt);
190190
extern int errhidecontext(bool hide_ctx);
@@ -243,13 +243,13 @@ extern int getinternalerrposition(void);
243243
#endif /* HAVE__VA_ARGS */
244244

245245
extern void elog_start(const char *filename, int lineno, const char *funcname);
246-
extern void elog_finish(int elevel, const char *fmt,...) pg_attribute_printf_m(2, 3);
246+
extern void elog_finish(int elevel, const char *fmt,...) pg_attribute_printf(2, 3);
247247

248248

249249
/* Support for constructing error strings separately from ereport() calls */
250250

251251
extern void pre_format_elog_string(int errnumber, const char *domain);
252-
extern char *format_elog_string(const char *fmt,...) pg_attribute_printf_m(1, 2);
252+
extern char *format_elog_string(const char *fmt,...) pg_attribute_printf(1, 2);
253253

254254

255255
/* Support for attaching context information to error reports */
@@ -428,9 +428,9 @@ extern void set_syslog_parameters(const char *ident, int facility);
428428
#endif
429429

430430
/*
431-
* Write errors to stderr (or by comparable means when stderr is not
432-
* available). Used before ereport/elog can be used safely (memory context,
433-
* GUC load etc). Note that this does *not* accept "%m".
431+
* Write errors to stderr (or by equal means when stderr is
432+
* not available). Used before ereport/elog can be used
433+
* safely (memory context, GUC load etc)
434434
*/
435435
extern void write_stderr(const char *fmt,...) pg_attribute_printf(1, 2);
436436

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy