mirror of
https://github.com/postgres/postgres.git
synced 2025-06-01 14:21:49 +03:00
Rearrange c.h to create a "compiler characteristics" section.
Generalize section 1 to handle stuff that is principally about the compiler (not libraries), such as attributes, and collect stuff there that had been dropped into various other parts of c.h. Also, push all the gettext macros into section 8, so that section 0 is really just inclusions rather than inclusions and random other stuff. The primary goal here is to get pg_attribute_aligned() defined before section 3, so that we can use it with int128. But this seems like good cleanup anyway. This patch just moves macro definitions around, and shouldn't result in any changes in generated code. Back-patch of commit 91aec93e6. Discussion: https://postgr.es/m/20171110185747.31519.28038@wrigleys.postgresql.org
This commit is contained in:
parent
8d8f85d476
commit
a891050675
240
src/include/c.h
240
src/include/c.h
@ -26,7 +26,7 @@
|
|||||||
* section description
|
* section description
|
||||||
* ------- ------------------------------------------------
|
* ------- ------------------------------------------------
|
||||||
* 0) pg_config.h and standard system headers
|
* 0) pg_config.h and standard system headers
|
||||||
* 1) hacks to cope with non-ANSI C compilers
|
* 1) compiler characteristics
|
||||||
* 2) bool, true, false, TRUE, FALSE, NULL
|
* 2) bool, true, false, TRUE, FALSE, NULL
|
||||||
* 3) standard system types
|
* 3) standard system types
|
||||||
* 4) IsValid macros for system types
|
* 4) IsValid macros for system types
|
||||||
@ -90,61 +90,117 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#if defined(WIN32) || defined(__CYGWIN__)
|
#if defined(WIN32) || defined(__CYGWIN__)
|
||||||
#include <fcntl.h> /* ensure O_BINARY is available */
|
#include <fcntl.h> /* ensure O_BINARY is available */
|
||||||
#endif
|
#endif
|
||||||
|
#include <locale.h>
|
||||||
|
#ifdef ENABLE_NLS
|
||||||
|
#include <libintl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(WIN32) || defined(__CYGWIN__)
|
#if defined(WIN32) || defined(__CYGWIN__)
|
||||||
/* We have to redefine some system functions after they are included above. */
|
/* We have to redefine some system functions after they are included above. */
|
||||||
#include "pg_config_os.h"
|
#include "pg_config_os.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* Force disable inlining if PG_FORCE_DISABLE_INLINE is defined. This is used
|
/* ----------------------------------------------------------------
|
||||||
* to work around compiler bugs and might also be useful for investigatory
|
* Section 1: compiler characteristics
|
||||||
* purposes by defining the symbol in the platform's header..
|
|
||||||
*
|
*
|
||||||
* This is done early (in slightly the wrong section) as functionality later
|
* type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
|
||||||
* in this file might want to rely on inline functions.
|
* ----------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Disable "inline" if PG_FORCE_DISABLE_INLINE is defined.
|
||||||
|
* This is used to work around compiler bugs and might also be useful for
|
||||||
|
* investigatory purposes.
|
||||||
*/
|
*/
|
||||||
#ifdef PG_FORCE_DISABLE_INLINE
|
#ifdef PG_FORCE_DISABLE_INLINE
|
||||||
#undef inline
|
#undef inline
|
||||||
#define inline
|
#define inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Must be before gettext() games below */
|
/*
|
||||||
#include <locale.h>
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
#define _(x) gettext(x)
|
/* only GCC supports the unused attribute */
|
||||||
|
#ifdef __GNUC__
|
||||||
#ifdef ENABLE_NLS
|
#define pg_attribute_unused() __attribute__((unused))
|
||||||
#include <libintl.h>
|
|
||||||
#else
|
#else
|
||||||
#define gettext(x) (x)
|
#define pg_attribute_unused()
|
||||||
#define dgettext(d,x) (x)
|
|
||||||
#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
|
|
||||||
#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use this to mark string constants as needing translation at some later
|
* Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
|
||||||
* time, rather than immediately. This is useful for cases where you need
|
* used in assert-enabled builds, to avoid compiler warnings about unused
|
||||||
* access to the original string and translated string, and for cases where
|
* variables in assert-disabled builds.
|
||||||
* immediate translation is not possible, like when initializing global
|
|
||||||
* variables.
|
|
||||||
* http://www.gnu.org/software/autoconf/manual/gettext/Special-cases.html
|
|
||||||
*/
|
*/
|
||||||
#define gettext_noop(x) (x)
|
#ifdef USE_ASSERT_CHECKING
|
||||||
|
#define PG_USED_FOR_ASSERTS_ONLY
|
||||||
|
#else
|
||||||
|
#define PG_USED_FOR_ASSERTS_ONLY 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 */
|
||||||
* Section 1: hacks to cope with non-ANSI C compilers
|
#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))
|
||||||
|
#define HAVE_PG_ATTRIBUTE_NORETURN 1
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
* NB: aligned and packed are not given default definitions because they
|
||||||
|
* affect code functionality; they *must* be implemented by the compiler
|
||||||
|
* if they are to be used.
|
||||||
|
*/
|
||||||
|
#define pg_attribute_noreturn()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Mark a point as unreachable in a portable fashion. This should preferably
|
||||||
|
* be something that the compiler understands, to aid code generation.
|
||||||
|
* In assert-enabled builds, we prefer abort() for debugging reasons.
|
||||||
|
*/
|
||||||
|
#if defined(HAVE__BUILTIN_UNREACHABLE) && !defined(USE_ASSERT_CHECKING)
|
||||||
|
#define pg_unreachable() __builtin_unreachable()
|
||||||
|
#elif defined(_MSC_VER) && !defined(USE_ASSERT_CHECKING)
|
||||||
|
#define pg_unreachable() __assume(0)
|
||||||
|
#else
|
||||||
|
#define pg_unreachable() abort()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hints to the compiler about the likelihood of a branch. Both likely() and
|
||||||
|
* unlikely() return the boolean value of the contained expression.
|
||||||
*
|
*
|
||||||
* type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
|
* These should only be used sparingly, in very hot code paths. It's very easy
|
||||||
* ----------------------------------------------------------------
|
* to mis-estimate likelihoods.
|
||||||
*/
|
*/
|
||||||
|
#if __GNUC__ >= 3
|
||||||
|
#define likely(x) __builtin_expect((x) != 0, 1)
|
||||||
|
#define unlikely(x) __builtin_expect((x) != 0, 0)
|
||||||
|
#else
|
||||||
|
#define likely(x) ((x) != 0)
|
||||||
|
#define unlikely(x) ((x) != 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CppAsString
|
* CppAsString
|
||||||
@ -183,6 +239,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------
|
/* ----------------------------------------------------------------
|
||||||
* Section 2: bool, true, false, TRUE, FALSE, NULL
|
* Section 2: bool, true, false, TRUE, FALSE, NULL
|
||||||
* ----------------------------------------------------------------
|
* ----------------------------------------------------------------
|
||||||
@ -209,6 +266,7 @@ typedef char bool;
|
|||||||
#ifndef false
|
#ifndef false
|
||||||
#define false ((bool) 0)
|
#define false ((bool) 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* not C++ */
|
#endif /* not C++ */
|
||||||
|
|
||||||
typedef bool *BoolPtr;
|
typedef bool *BoolPtr;
|
||||||
@ -502,16 +560,6 @@ typedef NameData *Name;
|
|||||||
|
|
||||||
#define NameStr(name) ((name).data)
|
#define NameStr(name) ((name).data)
|
||||||
|
|
||||||
/*
|
|
||||||
* Support macros for escaping strings. escape_backslash should be TRUE
|
|
||||||
* if generating a non-standard-conforming string. Prefixing a string
|
|
||||||
* with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
|
|
||||||
* Beware of multiple evaluation of the "ch" argument!
|
|
||||||
*/
|
|
||||||
#define SQL_STR_DOUBLE(ch, escape_backslash) \
|
|
||||||
((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
|
|
||||||
|
|
||||||
#define ESCAPE_STRING_SYNTAX 'E'
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------
|
/* ----------------------------------------------------------------
|
||||||
* Section 4: IsValid macros for system types
|
* Section 4: IsValid macros for system types
|
||||||
@ -579,6 +627,9 @@ typedef NameData *Name;
|
|||||||
*
|
*
|
||||||
* NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2.
|
* NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2.
|
||||||
* That case seems extremely unlikely to be needed in practice, however.
|
* That case seems extremely unlikely to be needed in practice, however.
|
||||||
|
*
|
||||||
|
* NOTE: MAXIMUM_ALIGNOF, and hence MAXALIGN(), intentionally exclude any
|
||||||
|
* larger-than-8-byte types the compiler might have.
|
||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -615,47 +666,6 @@ typedef NameData *Name;
|
|||||||
/* we don't currently need wider versions of the other ALIGN macros */
|
/* we don't currently need wider versions of the other ALIGN macros */
|
||||||
#define MAXALIGN64(LEN) TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
|
#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))
|
|
||||||
#define HAVE_PG_ATTRIBUTE_NORETURN 1
|
|
||||||
#else
|
|
||||||
/*
|
|
||||||
* NB: aligned and packed are not given default definitions because 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
|
* Section 6: assertions
|
||||||
@ -692,6 +702,7 @@ typedef NameData *Name;
|
|||||||
#define AssertArg(condition) assert(condition)
|
#define AssertArg(condition) assert(condition)
|
||||||
#define AssertState(condition) assert(condition)
|
#define AssertState(condition) assert(condition)
|
||||||
#define AssertPointerAlignment(ptr, bndr) ((void)true)
|
#define AssertPointerAlignment(ptr, bndr) ((void)true)
|
||||||
|
|
||||||
#else /* USE_ASSERT_CHECKING && !FRONTEND */
|
#else /* USE_ASSERT_CHECKING && !FRONTEND */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -937,36 +948,6 @@ typedef NameData *Name;
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Mark a point as unreachable in a portable fashion. This should preferably
|
|
||||||
* be something that the compiler understands, to aid code generation.
|
|
||||||
* In assert-enabled builds, we prefer abort() for debugging reasons.
|
|
||||||
*/
|
|
||||||
#if defined(HAVE__BUILTIN_UNREACHABLE) && !defined(USE_ASSERT_CHECKING)
|
|
||||||
#define pg_unreachable() __builtin_unreachable()
|
|
||||||
#elif defined(_MSC_VER) && !defined(USE_ASSERT_CHECKING)
|
|
||||||
#define pg_unreachable() __assume(0)
|
|
||||||
#else
|
|
||||||
#define pg_unreachable() abort()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hints to the compiler about the likelihood of a branch. Both likely() and
|
|
||||||
* unlikely() return the boolean value of the contained expression.
|
|
||||||
*
|
|
||||||
* These should only be used sparingly, in very hot code paths. It's very easy
|
|
||||||
* to mis-estimate likelihoods.
|
|
||||||
*/
|
|
||||||
#if __GNUC__ >= 3
|
|
||||||
#define likely(x) __builtin_expect((x) != 0, 1)
|
|
||||||
#define unlikely(x) __builtin_expect((x) != 0, 0)
|
|
||||||
#else
|
|
||||||
#define likely(x) ((x) != 0)
|
|
||||||
#define unlikely(x) ((x) != 0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------
|
/* ----------------------------------------------------------------
|
||||||
* Section 8: random stuff
|
* Section 8: random stuff
|
||||||
* ----------------------------------------------------------------
|
* ----------------------------------------------------------------
|
||||||
@ -976,26 +957,47 @@ typedef NameData *Name;
|
|||||||
#define HIGHBIT (0x80)
|
#define HIGHBIT (0x80)
|
||||||
#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
|
#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Support macros for escaping strings. escape_backslash should be TRUE
|
||||||
|
* if generating a non-standard-conforming string. Prefixing a string
|
||||||
|
* with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
|
||||||
|
* Beware of multiple evaluation of the "ch" argument!
|
||||||
|
*/
|
||||||
|
#define SQL_STR_DOUBLE(ch, escape_backslash) \
|
||||||
|
((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
|
||||||
|
|
||||||
|
#define ESCAPE_STRING_SYNTAX 'E'
|
||||||
|
|
||||||
|
|
||||||
#define STATUS_OK (0)
|
#define STATUS_OK (0)
|
||||||
#define STATUS_ERROR (-1)
|
#define STATUS_ERROR (-1)
|
||||||
#define STATUS_EOF (-2)
|
#define STATUS_EOF (-2)
|
||||||
#define STATUS_FOUND (1)
|
#define STATUS_FOUND (1)
|
||||||
#define STATUS_WAITING (2)
|
#define STATUS_WAITING (2)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
|
* gettext support
|
||||||
* used in assert-enabled builds, to avoid compiler warnings about unused
|
|
||||||
* variables in assert-disabled builds.
|
|
||||||
*/
|
*/
|
||||||
#ifdef USE_ASSERT_CHECKING
|
|
||||||
#define PG_USED_FOR_ASSERTS_ONLY
|
#ifndef ENABLE_NLS
|
||||||
#else
|
/* stuff we'd otherwise get from <libintl.h> */
|
||||||
#define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
|
#define gettext(x) (x)
|
||||||
|
#define dgettext(d,x) (x)
|
||||||
|
#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
|
||||||
|
#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define _(x) gettext(x)
|
||||||
|
|
||||||
/* gettext domain name mangling */
|
/*
|
||||||
|
* Use this to mark string constants as needing translation at some later
|
||||||
|
* time, rather than immediately. This is useful for cases where you need
|
||||||
|
* access to the original string and translated string, and for cases where
|
||||||
|
* immediate translation is not possible, like when initializing global
|
||||||
|
* variables.
|
||||||
|
* http://www.gnu.org/software/autoconf/manual/gettext/Special-cases.html
|
||||||
|
*/
|
||||||
|
#define gettext_noop(x) (x)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* To better support parallel installations of major PostgreSQL
|
* To better support parallel installations of major PostgreSQL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user