OSDN Git Service

Use a macro variable PG_PRINTF_ATTRIBUTE for the style used for checking printf type...
authorAndrew Dunstan <andrew@dunslane.net>
Thu, 28 Apr 2011 14:56:14 +0000 (10:56 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Thu, 28 Apr 2011 14:56:14 +0000 (10:56 -0400)
The style is set to "printf" for backwards compatibility everywhere except
on Windows, where it is set to "gnu_printf", which eliminates hundreds of
false error messages from modern versions of gcc arising from  %m and %ll{d,u}
formats.

16 files changed:
src/backend/utils/adt/format_type.c
src/bin/pg_ctl/pg_ctl.c
src/bin/pg_dump/pg_backup.h
src/bin/pg_dump/pg_backup_archiver.h
src/bin/psql/common.h
src/bin/psql/large_obj.c
src/include/c.h
src/include/lib/stringinfo.h
src/include/pg_config_manual.h
src/include/port.h
src/include/utils/elog.h
src/interfaces/ecpg/preproc/extern.h
src/interfaces/libpq/libpq-int.h
src/interfaces/libpq/pqexpbuffer.h
src/pl/plpython/plpython.c
src/test/regress/pg_regress.c

index b56bb74..7c51ee7 100644 (file)
@@ -33,7 +33,7 @@ static char *printTypmod(const char *typname, int32 typmod, Oid typmodout);
 static char *
 psnprintf(size_t len, const char *fmt,...)
 /* This lets gcc check the format string for consistency. */
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 
 
 /*
index 98de19f..98bbaef 100644 (file)
@@ -115,7 +115,7 @@ static void
 write_stderr(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 static void *pg_malloc(size_t size);
 static char *xstrdup(const char *s);
 static void do_advice(void);
index f51c958..b37cc19 100644 (file)
@@ -152,7 +152,7 @@ typedef struct _restoreOptions
 
 extern void
 exit_horribly(Archive *AH, const char *modulename, const char *fmt,...)
-__attribute__((format(printf, 3, 4)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
 
 
 /* Lets the archive know we have a DB connection to shutdown if it dies */
@@ -207,7 +207,7 @@ extern int  archputs(const char *s, Archive *AH);
 extern int
 archprintf(Archive *AH, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 
 #define appendStringLiteralAH(buf,str,AH) \
        appendStringLiteral(buf, str, (AH)->encoding, (AH)->std_strings)
index fd0b174..f9af874 100644 (file)
@@ -328,9 +328,9 @@ typedef struct _tocEntry
 /* Used everywhere */
 extern const char *progname;
 
-extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(printf, 3, 4)));
-extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(printf, 3, 4)));
-extern void write_msg(const char *modulename, const char *fmt,...) __attribute__((format(printf, 2, 3)));
+extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
+extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
+extern void write_msg(const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 
 extern void WriteTOC(ArchiveHandle *AH);
 extern void ReadTOC(ArchiveHandle *AH);
@@ -378,8 +378,8 @@ extern int  ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *
 extern void DropBlobIfExists(ArchiveHandle *AH, Oid oid);
 
 int                    ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH);
-int                    ahprintf(ArchiveHandle *AH, const char *fmt,...) __attribute__((format(printf, 2, 3)));
+int                    ahprintf(ArchiveHandle *AH, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 
-void           ahlog(ArchiveHandle *AH, int level, const char *fmt,...) __attribute__((format(printf, 3, 4)));
+void           ahlog(ArchiveHandle *AH, int level, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
 
 #endif
index 7b559f3..a26b868 100644 (file)
@@ -36,7 +36,7 @@ extern bool setQFout(const char *fname);
 extern void
 psql_error(const char *fmt,...)
 /* This lets gcc check the format string for consistency. */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
 extern void NoticeProcessor(void *arg, const char *message);
 
index 594fa0e..d8e703a 100644 (file)
@@ -14,7 +14,7 @@
 
 static void
 print_lo_result(const char *fmt,...)
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
 static void
 print_lo_result(const char *fmt,...)
index af1be94..0391860 100644 (file)
@@ -773,7 +773,7 @@ typedef NameData *Name;
 extern int
 snprintf(char *str, size_t count, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(printf, 3, 4)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
 #endif
 
 #if !HAVE_DECL_VSNPRINTF
index a84988c..3657a68 100644 (file)
@@ -95,7 +95,7 @@ extern void resetStringInfo(StringInfo str);
 extern void
 appendStringInfo(StringInfo str, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 
 /*------------------------
  * appendStringInfoVA
index 7cf1a64..5f4cf93 100644 (file)
  */
 #define MAX_RANDOM_VALUE  (0x7FFFFFFF)
 
+/*
+ * Set the format style used by gcc to check printf type functions. We really
+ * want the "gnu_printf" style set, which includes what glibc uses, such
+ * as %m for error strings and %lld for 64 bit long longs. But not all gcc
+ * compilers are known to support it, so we just use "printf" which all
+ * gcc versions alive are known to support, except on Windows where
+ * using "gnu_printf" style makes a dramatic difference. Maybe someday
+ * we'll have a configure test for this, if we ever discover use of more
+ * variants to be necessary.
+ */
+#ifdef WIN32
+#define PG_PRINTF_ATTRIBUTE gnu_printf
+#else
+#define PG_PRINTF_ATTRIBUTE printf
+#endif
 
 /*
  *------------------------------------------------------------------------
index 1116a92..6ea681f 100644 (file)
@@ -197,20 +197,20 @@ extern int        pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
 extern int
 pg_snprintf(char *str, size_t count, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(printf, 3, 4)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
 extern int
 pg_sprintf(char *str, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 extern int     pg_vfprintf(FILE *stream, const char *fmt, va_list args);
 extern int
 pg_fprintf(FILE *stream, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 extern int
 pg_printf(const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
 /*
  *     The GCC-specific code below prevents the __attribute__(... 'printf')
index fb5ef16..4a3bd02 100644 (file)
@@ -124,53 +124,53 @@ extern int
 errmsg(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
 extern int
 errmsg_internal(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
 extern int
 errmsg_plural(const char *fmt_singular, const char *fmt_plural,
                          unsigned long n,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 4)))
-__attribute__((format(printf, 2, 4)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 4)))
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 4)));
 
 extern int
 errdetail(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
 extern int
 errdetail_log(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
 extern int
 errdetail_plural(const char *fmt_singular, const char *fmt_plural,
                                 unsigned long n,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 4)))
-__attribute__((format(printf, 2, 4)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 4)))
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 4)));
 
 extern int
 errhint(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
 extern int
 errcontext(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
 extern int     errhidestmt(bool hide_stmt);
 
@@ -197,7 +197,7 @@ extern void
 elog_finish(int elevel, const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 
 
 /* Support for constructing error strings separately from ereport() calls */
@@ -207,7 +207,7 @@ extern char *
 format_elog_string(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
 
 /* Support for attaching context information to error reports */
@@ -366,6 +366,6 @@ extern void
 write_stderr(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
 #endif   /* ELOG_H */
index 05b273c..ccf5548 100644 (file)
@@ -76,7 +76,7 @@ extern char *mm_strdup(const char *);
 extern void
 mmerror(int, enum errortype, const char *,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(printf, 3, 4)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
 extern void output_get_descr_header(char *);
 extern void output_get_descr(char *, char *);
 extern void output_set_descr_header(char *);
index fbd94eb..d56ef5d 100644 (file)
@@ -505,7 +505,7 @@ extern PGresult *pqPrepareAsyncResult(PGconn *conn);
 extern void
 pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
 /* This lets gcc check the format string for consistency. */
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 extern int     pqAddTuple(PGresult *res, PGresAttValue *tup);
 extern void pqSaveMessageField(PGresult *res, char code,
                                   const char *value);
index be7cc61..d60fedc 100644 (file)
@@ -141,7 +141,7 @@ extern int  enlargePQExpBuffer(PQExpBuffer str, size_t needed);
 extern void
 printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 
 /*------------------------
  * appendPQExpBuffer
@@ -153,7 +153,7 @@ __attribute__((format(printf, 2, 3)));
 extern void
 appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
 /* This extension allows gcc to check the format string */
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 
 /*------------------------
  * appendPQExpBufferStr
index 8108cfc..fe44a1a 100644 (file)
@@ -324,14 +324,14 @@ static void PLy_init_plpy(void);
 /* call PyErr_SetString with a vprint interface and translation support */
 static void
 PLy_exception_set(PyObject *, const char *,...)
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 
 /* same, with pluralized message */
 static void
 PLy_exception_set_plural(PyObject *, const char *, const char *,
                                                 unsigned long n,...)
-__attribute__((format(printf, 2, 5)))
-__attribute__((format(printf, 3, 5)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 5)))
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 5)));
 
 /* like PLy_exception_set, but conserve more fields from ErrorData */
 static void PLy_spi_exception_set(PyObject *excclass, ErrorData *edata);
@@ -342,7 +342,7 @@ static char *PLy_procedure_name(PLyProcedure *);
 /* some utility functions */
 static void
 PLy_elog(int, const char *,...)
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 static void PLy_get_spi_error_data(PyObject *exc, char **detail, char **hint, char **query, int *position);
 static void PLy_traceback(char **, char **, int *);
 
index 23ef0a9..1411ca4 100644 (file)
@@ -126,17 +126,17 @@ static void
 header(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 static void
 status(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 1, 2)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 static void
 psql_command(const char *database, const char *query,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
-__attribute__((format(printf, 2, 3)));
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 
 #ifdef WIN32
 typedef BOOL (WINAPI * __CreateRestrictedToken) (HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE);