mirror of
https://github.com/postgres/postgres.git
synced 2025-08-09 17:03:00 +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,10 +156,6 @@
|
||||
#define dummyret char
|
||||
#endif
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define __attribute__(_arg_)
|
||||
#endif
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* Section 2: bool, true, false, TRUE, FALSE, NULL
|
||||
* ----------------------------------------------------------------
|
||||
@@ -560,6 +556,47 @@ typedef NameData *Name;
|
||||
/* we don't currently need wider versions of the other ALIGN macros */
|
||||
#define MAXALIGN64(LEN) TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
|
||||
|
||||
/* ----------------
|
||||
* Attribute macros
|
||||
*
|
||||
* GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
|
||||
* GCC: https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
|
||||
* Sunpro: https://docs.oracle.com/cd/E18659_01/html/821-1384/gjzke.html
|
||||
* XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/function_attributes.html
|
||||
* XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/type_attrib.html
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
/* only GCC supports the unused attribute */
|
||||
#ifdef __GNUC__
|
||||
#define pg_attribute_unused __attribute__((unused))
|
||||
#else
|
||||
#define pg_attribute_unused
|
||||
#endif
|
||||
|
||||
/* GCC and XLC support format attributes */
|
||||
#if defined(__GNUC__) || defined(__IBMC__)
|
||||
#define pg_attribute_format_arg(a) __attribute__((format_arg(a)))
|
||||
#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
|
||||
#else
|
||||
#define pg_attribute_format_arg(a)
|
||||
#define pg_attribute_printf(f,a)
|
||||
#endif
|
||||
|
||||
/* GCC, Sunpro and XLC support aligned, packed and noreturn */
|
||||
#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__)
|
||||
#define pg_attribute_aligned(a) __attribute__((aligned(a)))
|
||||
#define pg_attribute_noreturn __attribute__((noreturn))
|
||||
#define pg_attribute_packed __attribute__((packed))
|
||||
#else
|
||||
/*
|
||||
* NB: aligned and packed are not defined as empty as they affect code
|
||||
* functionality; they must be implemented by the compiler if they are to be
|
||||
* used.
|
||||
*/
|
||||
#define pg_attribute_noreturn
|
||||
#endif
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* Section 6: assertions
|
||||
* ----------------------------------------------------------------
|
||||
@@ -906,7 +943,7 @@ typedef NameData *Name;
|
||||
#ifdef USE_ASSERT_CHECKING
|
||||
#define PG_USED_FOR_ASSERTS_ONLY
|
||||
#else
|
||||
#define PG_USED_FOR_ASSERTS_ONLY __attribute__((unused))
|
||||
#define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused
|
||||
#endif
|
||||
|
||||
|
||||
@@ -973,7 +1010,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(PG_PRINTF_ATTRIBUTE, 3, 4)));
|
||||
pg_attribute_printf(3, 4);
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_VSNPRINTF
|
||||
|
Reference in New Issue
Block a user