26
26
* section description
27
27
* ------- ------------------------------------------------
28
28
* 0) pg_config.h and standard system headers
29
- * 1) hacks to cope with non-ANSI C compilers
29
+ * 1) compiler characteristics
30
30
* 2) bool, true, false, TRUE, FALSE, NULL
31
31
* 3) standard system types
32
32
* 4) IsValid macros for system types
90
90
#include <stdint.h>
91
91
#endif
92
92
#include <sys/types.h>
93
-
94
93
#include <errno.h>
95
94
#if defined(WIN32 ) || defined(__CYGWIN__ )
96
95
#include <fcntl.h> /* ensure O_BINARY is available */
97
96
#endif
97
+ #include <locale.h>
98
+ #ifdef ENABLE_NLS
99
+ #include <libintl.h>
100
+ #endif
98
101
99
102
#if defined(WIN32 ) || defined(__CYGWIN__ )
100
103
/* We have to redefine some system functions after they are included above. */
101
104
#include "pg_config_os.h"
102
105
#endif
103
106
104
- /* Must be before gettext() games below */
105
- #include <locale.h>
106
107
107
- #define _ (x ) gettext(x)
108
+ /* ----------------------------------------------------------------
109
+ * Section 1: compiler characteristics
110
+ *
111
+ * type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
112
+ * ----------------------------------------------------------------
113
+ */
108
114
109
- #ifdef ENABLE_NLS
110
- #include <libintl.h>
115
+ /*
116
+ * Function inlining support -- Allow modules to define functions that may be
117
+ * inlined, if the compiler supports it.
118
+ *
119
+ * The function bodies must be defined in the module header prefixed by
120
+ * STATIC_IF_INLINE, protected by a cpp symbol that the module's .c file must
121
+ * define. If the compiler doesn't support inline functions, the function
122
+ * definitions are pulled in by the .c file as regular (not inline) symbols.
123
+ *
124
+ * The header must also declare the functions' prototypes, protected by
125
+ * !PG_USE_INLINE.
126
+ */
127
+
128
+ /* declarations which are only visible when not inlining and in the .c file */
129
+ #ifdef PG_USE_INLINE
130
+ #define STATIC_IF_INLINE static inline
111
131
#else
112
- #define gettext (x ) (x)
113
- #define dgettext (d ,x ) (x)
114
- #define ngettext (s ,p ,n ) ((n) == 1 ? (s) : (p))
115
- #define dngettext (d ,s ,p ,n ) ((n) == 1 ? (s) : (p))
132
+ #define STATIC_IF_INLINE
133
+ #endif /* PG_USE_INLINE */
134
+
135
+ /* declarations which are marked inline when inlining, extern otherwise */
136
+ #ifdef PG_USE_INLINE
137
+ #define STATIC_IF_INLINE_DECLARE static inline
138
+ #else
139
+ #define STATIC_IF_INLINE_DECLARE extern
140
+ #endif /* PG_USE_INLINE */
141
+
142
+ /*
143
+ * Attribute macros
144
+ *
145
+ * GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
146
+ * GCC: https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
147
+ * Sunpro: https://docs.oracle.com/cd/E18659_01/html/821-1384/gjzke.html
148
+ * XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/function_attributes.html
149
+ * XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/type_attrib.html
150
+ */
151
+
152
+ /* only GCC supports the unused attribute */
153
+ #ifdef __GNUC__
154
+ #define pg_attribute_unused () __attribute__((unused))
155
+ #else
156
+ #define pg_attribute_unused ()
116
157
#endif
117
158
118
159
/*
119
- * Use this to mark string constants as needing translation at some later
120
- * time, rather than immediately. This is useful for cases where you need
121
- * access to the original string and translated string, and for cases where
122
- * immediate translation is not possible, like when initializing global
123
- * variables.
124
- * http://www.gnu.org/software/autoconf/manual/gettext/Special-cases.html
160
+ * Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
161
+ * used in assert-enabled builds, to avoid compiler warnings about unused
162
+ * variables in assert-disabled builds.
125
163
*/
126
- #define gettext_noop (x ) (x)
164
+ #ifdef USE_ASSERT_CHECKING
165
+ #define PG_USED_FOR_ASSERTS_ONLY
166
+ #else
167
+ #define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
168
+ #endif
127
169
170
+ /* GCC and XLC support format attributes */
171
+ #if defined(__GNUC__ ) || defined(__IBMC__ )
172
+ #define pg_attribute_format_arg (a ) __attribute__((format_arg(a)))
173
+ #define pg_attribute_printf (f ,a ) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
174
+ #else
175
+ #define pg_attribute_format_arg (a )
176
+ #define pg_attribute_printf (f ,a )
177
+ #endif
128
178
129
- /* ----------------------------------------------------------------
130
- * Section 1: hacks to cope with non-ANSI C compilers
131
- *
132
- * type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
133
- * ----------------------------------------------------------------
179
+ /* GCC, Sunpro and XLC support aligned, packed and noreturn */
180
+ #if defined(__GNUC__ ) || defined(__SUNPRO_C ) || defined(__IBMC__ )
181
+ #define pg_attribute_aligned (a ) __attribute__((aligned(a)))
182
+ #define pg_attribute_noreturn () __attribute__((noreturn))
183
+ #define pg_attribute_packed () __attribute__((packed))
184
+ #define HAVE_PG_ATTRIBUTE_NORETURN 1
185
+ #else
186
+ /*
187
+ * NB: aligned and packed are not given default definitions because they
188
+ * affect code functionality; they *must* be implemented by the compiler
189
+ * if they are to be used.
134
190
*/
191
+ #define pg_attribute_noreturn ()
192
+ #endif
193
+
194
+ /*
195
+ * Mark a point as unreachable in a portable fashion. This should preferably
196
+ * be something that the compiler understands, to aid code generation.
197
+ * In assert-enabled builds, we prefer abort() for debugging reasons.
198
+ */
199
+ #if defined(HAVE__BUILTIN_UNREACHABLE ) && !defined(USE_ASSERT_CHECKING )
200
+ #define pg_unreachable () __builtin_unreachable()
201
+ #elif defined(_MSC_VER ) && !defined(USE_ASSERT_CHECKING )
202
+ #define pg_unreachable () __assume(0)
203
+ #else
204
+ #define pg_unreachable () abort()
205
+ #endif
135
206
136
207
/*
137
208
* CppAsString
138
209
* Convert the argument to a string, using the C preprocessor.
210
+ * CppAsString2
211
+ * Convert the argument to a string, after one round of macro expansion.
139
212
* CppConcat
140
213
* Concatenate two arguments together, using the C preprocessor.
141
214
*
144
217
* backward compatibility with existing PostgreSQL code.
145
218
*/
146
219
#define CppAsString (identifier ) #identifier
220
+ #define CppAsString2 (x ) CppAsString(x)
147
221
#define CppConcat (x , y ) x##y
148
222
149
223
/*
156
230
#define dummyret char
157
231
#endif
158
232
233
+
159
234
/* ----------------------------------------------------------------
160
235
* Section 2: bool, true, false, TRUE, FALSE, NULL
161
236
* ----------------------------------------------------------------
@@ -182,6 +257,7 @@ typedef char bool;
182
257
#ifndef false
183
258
#define false ((bool) 0)
184
259
#endif
260
+
185
261
#endif /* not C++ */
186
262
187
263
typedef bool * BoolPtr ;
@@ -478,16 +554,6 @@ typedef NameData *Name;
478
554
479
555
#define NameStr (name ) ((name).data)
480
556
481
- /*
482
- * Support macros for escaping strings. escape_backslash should be TRUE
483
- * if generating a non-standard-conforming string. Prefixing a string
484
- * with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
485
- * Beware of multiple evaluation of the "ch" argument!
486
- */
487
- #define SQL_STR_DOUBLE (ch , escape_backslash ) \
488
- ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
489
-
490
- #define ESCAPE_STRING_SYNTAX 'E'
491
557
492
558
/* ----------------------------------------------------------------
493
559
* Section 4: IsValid macros for system types
@@ -552,6 +618,9 @@ typedef NameData *Name;
552
618
*
553
619
* NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2.
554
620
* That case seems extremely unlikely to be needed in practice, however.
621
+ *
622
+ * NOTE: MAXIMUM_ALIGNOF, and hence MAXALIGN(), intentionally exclude any
623
+ * larger-than-8-byte types the compiler might have.
555
624
* ----------------
556
625
*/
557
626
@@ -588,47 +657,6 @@ typedef NameData *Name;
588
657
/* we don't currently need wider versions of the other ALIGN macros */
589
658
#define MAXALIGN64 (LEN ) TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
590
659
591
- /* ----------------
592
- * Attribute macros
593
- *
594
- * GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
595
- * GCC: https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
596
- * Sunpro: https://docs.oracle.com/cd/E18659_01/html/821-1384/gjzke.html
597
- * XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/function_attributes.html
598
- * XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/type_attrib.html
599
- * ----------------
600
- */
601
-
602
- /* only GCC supports the unused attribute */
603
- #ifdef __GNUC__
604
- #define pg_attribute_unused () __attribute__((unused))
605
- #else
606
- #define pg_attribute_unused ()
607
- #endif
608
-
609
- /* GCC and XLC support format attributes */
610
- #if defined(__GNUC__ ) || defined(__IBMC__ )
611
- #define pg_attribute_format_arg (a ) __attribute__((format_arg(a)))
612
- #define pg_attribute_printf (f ,a ) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
613
- #else
614
- #define pg_attribute_format_arg (a )
615
- #define pg_attribute_printf (f ,a )
616
- #endif
617
-
618
- /* GCC, Sunpro and XLC support aligned, packed and noreturn */
619
- #if defined(__GNUC__ ) || defined(__SUNPRO_C ) || defined(__IBMC__ )
620
- #define pg_attribute_aligned (a ) __attribute__((aligned(a)))
621
- #define pg_attribute_noreturn () __attribute__((noreturn))
622
- #define pg_attribute_packed () __attribute__((packed))
623
- #define HAVE_PG_ATTRIBUTE_NORETURN 1
624
- #else
625
- /*
626
- * NB: aligned and packed are not given default definitions because they
627
- * affect code functionality; they *must* be implemented by the compiler
628
- * if they are to be used.
629
- */
630
- #define pg_attribute_noreturn ()
631
- #endif
632
660
633
661
/* ----
F438
------------------------------------------------------------
634
662
* Section 6: assertions
@@ -665,6 +693,7 @@ typedef NameData *Name;
665
693
#define AssertArg (condition ) assert(condition)
666
694
#define AssertState (condition ) assert(condition)
667
695
#define AssertPointerAlignment (ptr , bndr ) ((void)true)
696
+
668
697
#else /* USE_ASSERT_CHECKING && !FRONTEND */
669
698
670
699
/*
@@ -910,48 +939,6 @@ typedef NameData *Name;
910
939
} while (0)
911
940
912
941
913
- /*
914
- * Mark a point as unreachable in a portable fashion. This should preferably
915
- * be something that the compiler understands, to aid code generation.
916
- * In assert-enabled builds, we prefer abort() for debugging reasons.
917
- */
918
- #if defined(HAVE__BUILTIN_UNREACHABLE ) && !defined(USE_ASSERT_CHECKING )
919
- #define pg_unreachable () __builtin_unreachable()
920
- #elif defined(_MSC_VER ) && !defined(USE_ASSERT_CHECKING )
921
- #define pg_unreachable () __assume(0)
922
- #else
923
- #define pg_unreachable () abort()
924
- #endif
925
-
926
-
927
- /*
928
- * Function inlining support -- Allow modules to define functions that may be
929
- * inlined, if the compiler supports it.
930
- *
931
- * The function bodies must be defined in the module header prefixed by
932
- * STATIC_IF_INLINE, protected by a cpp symbol that the module's .c file must
933
- * define. If the compiler doesn't support inline functions, the function
934
- * definitions are pulled in by the .c file as regular (not inline) symbols.
935
- *
936
- * The header must also declare the functions' prototypes, protected by
937
- * !PG_USE_INLINE.
938
- */
939
-
940
- /* declarations which are only visible when not inlining and in the .c file */
941
- #ifdef PG_USE_INLINE
942
- #define STATIC_IF_INLINE static inline
943
- #else
944
- #define STATIC_IF_INLINE
945
- #endif /* PG_USE_INLINE */
946
-
947
- /* declarations which are marked inline when inlining, extern otherwise */
948
- #ifdef PG_USE_INLINE
949
- #define STATIC_IF_INLINE_DECLARE static inline
950
- #else
951
- #define STATIC_IF_INLINE_DECLARE extern
952
- #endif /* PG_USE_INLINE */
953
-
954
-
955
942
/* ----------------------------------------------------------------
956
943
* Section 8: random stuff
957
944
* ----------------------------------------------------------------
@@ -961,26 +948,47 @@ typedef NameData *Name;
961
948
#define HIGHBIT (0x80)
962
949
#define IS_HIGHBIT_SET (ch ) ((unsigned char)(ch) & HIGHBIT)
963
950
951
+ /*
952
+ * Support macros for escaping strings. escape_backslash should be TRUE
953
+ * if generating a non-standard-conforming string. Prefixing a string
954
+ * with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
955
+ * Beware of multiple evaluation of the "ch" argument!
956
+ */
957
+ #define SQL_STR_DOUBLE (ch , escape_backslash ) \
958
+ ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
959
+
960
+ #define ESCAPE_STRING_SYNTAX 'E'
961
+
962
+
964
963
#define STATUS_OK (0)
965
964
#define STATUS_ERROR (-1)
966
965
#define STATUS_EOF (-2)
967
966
#define STATUS_FOUND (1)
968
967
#define STATUS_WAITING (2)
969
968
970
-
971
969
/*
972
- * Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
973
- * used in assert-enabled builds, to avoid compiler warnings about unused
974
- * variables in assert-disabled builds.
970
+ * gettext support
975
971
*/
976
- #ifdef USE_ASSERT_CHECKING
977
- #define PG_USED_FOR_ASSERTS_ONLY
978
- #else
979
- #define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
972
+
973
+ #ifndef ENABLE_NLS
974
+ /* stuff we'd otherwise get from <libintl.h> */
975
+ #define gettext (x ) (x)
976
+ #define dgettext (d ,x ) (x)
977
+ #define ngettext (s ,p ,n ) ((n) == 1 ? (s) : (p))
978
+ #define dngettext (d ,s ,p ,n ) ((n) == 1 ? (s) : (p))
980
979
#endif
981
980
981
+ #define _ (x ) gettext(x)
982
982
983
- /* gettext domain name mangling */
983
+ /*
984
+ * Use this to mark string constants as needing translation at some later
985
+ * time, rather than immediately. This is useful for cases where you need
986
+ * access to the original string and translated string, and for cases where
987
+ * immediate translation is not possible, like when initializing global
988
+ * variables.
989
+ * http://www.gnu.org/software/autoconf/manual/gettext/Special-cases.html
990
+ */
991
+ #define gettext_noop (x ) (x)
984
992
985
993
/*
986
994
* To better support parallel installations of major PostgreSQL
@@ -995,10 +1003,6 @@ typedef NameData *Name;
995
1003
*
996
1004
* Make sure this matches the installation rules in nls-global.mk.
997
1005
*/
998
-
999
- /* need a second indirection because we want to stringize the macro value, not the name */
1000
- #define CppAsString2 (x ) CppAsString(x)
1001
-
1002
1006
#ifdef SO_MAJOR_VERSION
1003
1007
#define PG_TEXTDOMAIN (domain ) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1004
1008
#else
0 commit comments