mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Add macros wrapping all usage of gcc's __attribute__.
Until now __attribute__() was defined to be empty for all compilers but gcc. That's problematic because it prevents using it in other compilers; which is necessary e.g. for atomics portability. It's also just generally dubious to do so in a header as widely included as c.h. Instead add pg_attribute_format_arg, pg_attribute_printf, pg_attribute_noreturn macros which are implemented in the compilers that understand them. Also add pg_attribute_noreturn and pg_attribute_packed, but don't provide fallbacks, since they can affect functionality. This means that external code that, possibly unwittingly, relied on __attribute__ defined to be empty on !gcc compilers may now run into warnings or errors on those compilers. But there shouldn't be many occurances of that and it's hard to work around... Discussion: 54B58BA3.8040302@ohmu.fi Author: Oskari Saarenmaa, with some minor changes by me.
This commit is contained in:
@ -185,7 +185,7 @@ void ecpg_raise(int line, int code, const char *sqlstate, const char *str);
|
||||
void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat);
|
||||
char *ecpg_prepared(const char *, struct connection *);
|
||||
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection * conn);
|
||||
void ecpg_log(const char *format,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
|
||||
void ecpg_log(const char *format,...) pg_attribute_printf(1, 2);
|
||||
bool ecpg_auto_prepare(int, const char *, const int, char **, const char *);
|
||||
void ecpg_init_sqlca(struct sqlca_t * sqlca);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#ifdef ENABLE_NLS
|
||||
extern char *
|
||||
ecpg_gettext(const char *msgid)
|
||||
__attribute__((format_arg(1)));
|
||||
pg_attribute_format_arg(1);
|
||||
#else
|
||||
#define ecpg_gettext(x) (x)
|
||||
#endif
|
||||
|
@ -64,7 +64,7 @@ static struct ECPGtype ecpg_query = {ECPGt_char_variable, NULL, NULL, NULL, {NUL
|
||||
/*
|
||||
* Handle parsing errors and warnings
|
||||
*/
|
||||
static void __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)))
|
||||
static void pg_attribute_printf(3, 0)
|
||||
vmmerror(int error_code, enum errortype type, const char *error, va_list ap)
|
||||
{
|
||||
/* localize the error message string */
|
||||
|
@ -77,8 +77,8 @@ extern int base_yylex(void);
|
||||
extern void base_yyerror(const char *);
|
||||
extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);
|
||||
extern char *mm_strdup(const char *);
|
||||
extern void mmerror(int errorcode, enum errortype type, const char *error,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
|
||||
extern void mmfatal(int errorcode, const char *error,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3), noreturn));
|
||||
extern void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3, 4);
|
||||
extern void mmfatal(int errorcode, const char *error,...) pg_attribute_printf(2, 3) pg_attribute_noreturn;
|
||||
extern void output_get_descr_header(char *);
|
||||
extern void output_get_descr(char *, char *);
|
||||
extern void output_set_descr_header(char *);
|
||||
|
@ -548,7 +548,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(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
||||
pg_attribute_printf(2, 3);
|
||||
extern void pqSaveMessageField(PGresult *res, char code,
|
||||
const char *value);
|
||||
extern void pqSaveParameterStatus(PGconn *conn, const char *name,
|
||||
@ -653,10 +653,10 @@ extern ssize_t pgtls_write(PGconn *conn, const void *ptr, size_t len);
|
||||
#ifdef ENABLE_NLS
|
||||
extern char *
|
||||
libpq_gettext(const char *msgid)
|
||||
__attribute__((format_arg(1)));
|
||||
pg_attribute_format_arg(1);
|
||||
extern char *
|
||||
libpq_ngettext(const char *msgid, const char *msgid_plural, unsigned long n)
|
||||
__attribute__((format_arg(1))) __attribute__((format_arg(2)));
|
||||
pg_attribute_format_arg(1) pg_attribute_format_arg(2);
|
||||
#else
|
||||
#define libpq_gettext(x) (x)
|
||||
#define libpq_ngettext(s, p, n) ((n) == 1 ? (s) : (p))
|
||||
|
@ -39,7 +39,7 @@ static const char oom_buffer[1] = "";
|
||||
|
||||
static bool
|
||||
appendPQExpBufferVA(PQExpBuffer str, const char *fmt, va_list args)
|
||||
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
|
||||
pg_attribute_printf(2, 0);
|
||||
|
||||
|
||||
/*
|
||||
|
@ -149,7 +149,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(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
||||
pg_attribute_printf(2, 3);
|
||||
|
||||
/*------------------------
|
||||
* appendPQExpBuffer
|
||||
@ -161,7 +161,7 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
||||
extern void
|
||||
appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
|
||||
/* This extension allows gcc to check the format string */
|
||||
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
||||
pg_attribute_printf(2, 3);
|
||||
|
||||
/*------------------------
|
||||
* appendPQExpBufferStr
|
||||
|
@ -36,7 +36,7 @@
|
||||
#ifdef ENABLE_NLS
|
||||
extern char *
|
||||
libpq_gettext(const char *msgid)
|
||||
__attribute__((format_arg(1)));
|
||||
pg_attribute_format_arg(1);
|
||||
#else
|
||||
#define libpq_gettext(x) (x)
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user