mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +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:
@@ -156,25 +156,25 @@ 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(PG_PRINTF_ATTRIBUTE, 3, 4)));
|
||||
pg_attribute_printf(3, 4);
|
||||
extern int
|
||||
pg_sprintf(char *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);
|
||||
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(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
||||
pg_attribute_printf(2, 3);
|
||||
extern int
|
||||
pg_printf(const char *fmt,...)
|
||||
/* This extension allows gcc to check the format string */
|
||||
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
|
||||
pg_attribute_printf(1, 2);
|
||||
|
||||
/*
|
||||
* The GCC-specific code below prevents the __attribute__(... 'printf')
|
||||
* above from being replaced, and this is required because gcc doesn't
|
||||
* know anything about pg_printf.
|
||||
* The GCC-specific code below prevents the pg_attribute_printf above from
|
||||
* being replaced, and this is required because gcc doesn't know anything
|
||||
* about pg_printf.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
|
||||
|
Reference in New Issue
Block a user