PostgreSQL Source Code  git master
c.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * c.h
4  * Fundamental C definitions. This is included by every .c file in
5  * PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate).
6  *
7  * Note that the definitions here are not intended to be exposed to clients
8  * of the frontend interface libraries --- so we don't worry much about
9  * polluting the namespace with lots of stuff...
10  *
11  *
12  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
13  * Portions Copyright (c) 1994, Regents of the University of California
14  *
15  * src/include/c.h
16  *
17  *-------------------------------------------------------------------------
18  */
19 /*
20  *----------------------------------------------------------------
21  * TABLE OF CONTENTS
22  *
23  * When adding stuff to this file, please try to put stuff
24  * into the relevant section, or add new sections as appropriate.
25  *
26  * section description
27  * ------- ------------------------------------------------
28  * 0) pg_config.h and standard system headers
29  * 1) compiler characteristics
30  * 2) bool, true, false
31  * 3) standard system types
32  * 4) IsValid macros for system types
33  * 5) offsetof, lengthof, alignment
34  * 6) assertions
35  * 7) widely useful macros
36  * 8) random stuff
37  * 9) system-specific hacks
38  *
39  * NOTE: since this file is included by both frontend and backend modules,
40  * it's usually wrong to put an "extern" declaration here, unless it's
41  * ifdef'd so that it's seen in only one case or the other.
42  * typedefs and macros are the kind of thing that might go here.
43  *
44  *----------------------------------------------------------------
45  */
46 #ifndef C_H
47 #define C_H
48 
49 #include "postgres_ext.h"
50 
51 /* Must undef pg_config_ext.h symbols before including pg_config.h */
52 #undef PG_INT64_TYPE
53 
54 #include "pg_config.h"
55 #include "pg_config_manual.h" /* must be after pg_config.h */
56 #include "pg_config_os.h" /* must be before any system header files */
57 
58 /* System header files that should be available everywhere in Postgres */
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include <stddef.h>
63 #include <stdarg.h>
64 #ifdef HAVE_STRINGS_H
65 #include <strings.h>
66 #endif
67 #include <stdint.h>
68 #include <sys/types.h>
69 #include <errno.h>
70 #if defined(WIN32) || defined(__CYGWIN__)
71 #include <fcntl.h> /* ensure O_BINARY is available */
72 #endif
73 #include <locale.h>
74 #ifdef ENABLE_NLS
75 #include <libintl.h>
76 #endif
77 
78 
79 /* ----------------------------------------------------------------
80  * Section 1: compiler characteristics
81  *
82  * type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
83  * ----------------------------------------------------------------
84  */
85 
86 /*
87  * Disable "inline" if PG_FORCE_DISABLE_INLINE is defined.
88  * This is used to work around compiler bugs and might also be useful for
89  * investigatory purposes.
90  */
91 #ifdef PG_FORCE_DISABLE_INLINE
92 #undef inline
93 #define inline
94 #endif
95 
96 /*
97  * Attribute macros
98  *
99  * GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
100  * GCC: https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
101  * Clang: https://clang.llvm.org/docs/AttributeReference.html
102  * Sunpro: https://docs.oracle.com/cd/E18659_01/html/821-1384/gjzke.html
103  * XLC: https://www.ibm.com/support/knowledgecenter/SSGH2K_13.1.2/com.ibm.xlc131.aix.doc/language_ref/function_attributes.html
104  * XLC: https://www.ibm.com/support/knowledgecenter/SSGH2K_13.1.2/com.ibm.xlc131.aix.doc/language_ref/type_attrib.html
105  */
106 
107 /*
108  * For compilers which don't support __has_attribute, we just define
109  * __has_attribute(x) to 0 so that we can define macros for various
110  * __attribute__s more easily below.
111  */
112 #ifndef __has_attribute
113 #define __has_attribute(attribute) 0
114 #endif
115 
116 /* only GCC supports the unused attribute */
117 #ifdef __GNUC__
118 #define pg_attribute_unused() __attribute__((unused))
119 #else
120 #define pg_attribute_unused()
121 #endif
122 
123 /*
124  * pg_nodiscard means the compiler should warn if the result of a function
125  * call is ignored. The name "nodiscard" is chosen in alignment with
126  * (possibly future) C and C++ standards. For maximum compatibility, use it
127  * as a function declaration specifier, so it goes before the return type.
128  */
129 #ifdef __GNUC__
130 #define pg_nodiscard __attribute__((warn_unused_result))
131 #else
132 #define pg_nodiscard
133 #endif
134 
135 /*
136  * Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
137  * used in assert-enabled builds, to avoid compiler warnings about unused
138  * variables in assert-disabled builds.
139  */
140 #ifdef USE_ASSERT_CHECKING
141 #define PG_USED_FOR_ASSERTS_ONLY
142 #else
143 #define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
144 #endif
145 
146 /* GCC and XLC support format attributes */
147 #if defined(__GNUC__) || defined(__IBMC__)
148 #define pg_attribute_format_arg(a) __attribute__((format_arg(a)))
149 #define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
150 #else
151 #define pg_attribute_format_arg(a)
152 #define pg_attribute_printf(f,a)
153 #endif
154 
155 /* GCC, Sunpro and XLC support aligned, packed and noreturn */
156 #if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__)
157 #define pg_attribute_aligned(a) __attribute__((aligned(a)))
158 #define pg_attribute_noreturn() __attribute__((noreturn))
159 #define pg_attribute_packed() __attribute__((packed))
160 #define HAVE_PG_ATTRIBUTE_NORETURN 1
161 #else
162 /*
163  * NB: aligned and packed are not given default definitions because they
164  * affect code functionality; they *must* be implemented by the compiler
165  * if they are to be used.
166  */
167 #define pg_attribute_noreturn()
168 #endif
169 
170 /*
171  * Use "pg_attribute_always_inline" in place of "inline" for functions that
172  * we wish to force inlining of, even when the compiler's heuristics would
173  * choose not to. But, if possible, don't force inlining in unoptimized
174  * debug builds.
175  */
176 #if (defined(__GNUC__) && __GNUC__ > 3 && defined(__OPTIMIZE__)) || defined(__SUNPRO_C) || defined(__IBMC__)
177 /* GCC > 3, Sunpro and XLC support always_inline via __attribute__ */
178 #define pg_attribute_always_inline __attribute__((always_inline)) inline
179 #elif defined(_MSC_VER)
180 /* MSVC has a special keyword for this */
181 #define pg_attribute_always_inline __forceinline
182 #else
183 /* Otherwise, the best we can do is to say "inline" */
184 #define pg_attribute_always_inline inline
185 #endif
186 
187 /*
188  * Forcing a function not to be inlined can be useful if it's the slow path of
189  * a performance-critical function, or should be visible in profiles to allow
190  * for proper cost attribution. Note that unlike the pg_attribute_XXX macros
191  * above, this should be placed before the function's return type and name.
192  */
193 /* GCC, Sunpro and XLC support noinline via __attribute__ */
194 #if (defined(__GNUC__) && __GNUC__ > 2) || defined(__SUNPRO_C) || defined(__IBMC__)
195 #define pg_noinline __attribute__((noinline))
196 /* msvc via declspec */
197 #elif defined(_MSC_VER)
198 #define pg_noinline __declspec(noinline)
199 #else
200 #define pg_noinline
201 #endif
202 
203 /*
204  * For now, just define pg_attribute_cold and pg_attribute_hot to be empty
205  * macros on minGW 8.1. There appears to be a compiler bug that results in
206  * compilation failure. At this time, we still have at least one buildfarm
207  * animal running that compiler, so this should make that green again. It's
208  * likely this compiler is not popular enough to warrant keeping this code
209  * around forever, so let's just remove it once the last buildfarm animal
210  * upgrades.
211  */
212 #if defined(__MINGW64__) && __GNUC__ == 8 && __GNUC_MINOR__ == 1
213 
214 #define pg_attribute_cold
215 #define pg_attribute_hot
216 
217 #else
218 /*
219  * Marking certain functions as "hot" or "cold" can be useful to assist the
220  * compiler in arranging the assembly code in a more efficient way.
221  */
222 #if __has_attribute (cold)
223 #define pg_attribute_cold __attribute__((cold))
224 #else
225 #define pg_attribute_cold
226 #endif
227 
228 #if __has_attribute (hot)
229 #define pg_attribute_hot __attribute__((hot))
230 #else
231 #define pg_attribute_hot
232 #endif
233 
234 #endif /* defined(__MINGW64__) && __GNUC__ == 8 &&
235  * __GNUC_MINOR__ == 1 */
236 /*
237  * Mark a point as unreachable in a portable fashion. This should preferably
238  * be something that the compiler understands, to aid code generation.
239  * In assert-enabled builds, we prefer abort() for debugging reasons.
240  */
241 #if defined(HAVE__BUILTIN_UNREACHABLE) && !defined(USE_ASSERT_CHECKING)
242 #define pg_unreachable() __builtin_unreachable()
243 #elif defined(_MSC_VER) && !defined(USE_ASSERT_CHECKING)
244 #define pg_unreachable() __assume(0)
245 #else
246 #define pg_unreachable() abort()
247 #endif
248 
249 /*
250  * Hints to the compiler about the likelihood of a branch. Both likely() and
251  * unlikely() return the boolean value of the contained expression.
252  *
253  * These should only be used sparingly, in very hot code paths. It's very easy
254  * to mis-estimate likelihoods.
255  */
256 #if __GNUC__ >= 3
257 #define likely(x) __builtin_expect((x) != 0, 1)
258 #define unlikely(x) __builtin_expect((x) != 0, 0)
259 #else
260 #define likely(x) ((x) != 0)
261 #define unlikely(x) ((x) != 0)
262 #endif
263 
264 /*
265  * CppAsString
266  * Convert the argument to a string, using the C preprocessor.
267  * CppAsString2
268  * Convert the argument to a string, after one round of macro expansion.
269  * CppConcat
270  * Concatenate two arguments together, using the C preprocessor.
271  *
272  * Note: There used to be support here for pre-ANSI C compilers that didn't
273  * support # and ##. Nowadays, these macros are just for clarity and/or
274  * backward compatibility with existing PostgreSQL code.
275  */
276 #define CppAsString(identifier) #identifier
277 #define CppAsString2(x) CppAsString(x)
278 #define CppConcat(x, y) x##y
279 
280 /*
281  * VA_ARGS_NARGS
282  * Returns the number of macro arguments it is passed.
283  *
284  * An empty argument still counts as an argument, so effectively, this is
285  * "one more than the number of commas in the argument list".
286  *
287  * This works for up to 63 arguments. Internally, VA_ARGS_NARGS_() is passed
288  * 64+N arguments, and the C99 standard only requires macros to allow up to
289  * 127 arguments, so we can't portably go higher. The implementation is
290  * pretty trivial: VA_ARGS_NARGS_() returns its 64th argument, and we set up
291  * the call so that that is the appropriate one of the list of constants.
292  * This idea is due to Laurent Deniau.
293  */
294 #define VA_ARGS_NARGS(...) \
295  VA_ARGS_NARGS_(__VA_ARGS__, \
296  63,62,61,60, \
297  59,58,57,56,55,54,53,52,51,50, \
298  49,48,47,46,45,44,43,42,41,40, \
299  39,38,37,36,35,34,33,32,31,30, \
300  29,28,27,26,25,24,23,22,21,20, \
301  19,18,17,16,15,14,13,12,11,10, \
302  9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
303 #define VA_ARGS_NARGS_( \
304  _01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
305  _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
306  _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
307  _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
308  _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
309  _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
310  _61,_62,_63, N, ...) \
311  (N)
312 
313 /*
314  * dummyret is used to set return values in macros that use ?: to make
315  * assignments. gcc wants these to be void, other compilers like char
316  */
317 #ifdef __GNUC__ /* GNU cc */
318 #define dummyret void
319 #else
320 #define dummyret char
321 #endif
322 
323 /*
324  * Generic function pointer. This can be used in the rare cases where it's
325  * necessary to cast a function pointer to a seemingly incompatible function
326  * pointer type while avoiding gcc's -Wcast-function-type warnings.
327  */
328 typedef void (*pg_funcptr_t) (void);
329 
330 /*
331  * We require C99, hence the compiler should understand flexible array
332  * members. However, for documentation purposes we still consider it to be
333  * project style to write "field[FLEXIBLE_ARRAY_MEMBER]" not just "field[]".
334  * When computing the size of such an object, use "offsetof(struct s, f)"
335  * for portability. Don't use "offsetof(struct s, f[0])", as this doesn't
336  * work with MSVC and with C++ compilers.
337  */
338 #define FLEXIBLE_ARRAY_MEMBER /* empty */
339 
340 /* Which __func__ symbol do we have, if any? */
341 #ifdef HAVE_FUNCNAME__FUNC
342 #define PG_FUNCNAME_MACRO __func__
343 #else
344 #ifdef HAVE_FUNCNAME__FUNCTION
345 #define PG_FUNCNAME_MACRO __FUNCTION__
346 #else
347 #define PG_FUNCNAME_MACRO NULL
348 #endif
349 #endif
350 
351 
352 /* ----------------------------------------------------------------
353  * Section 2: bool, true, false
354  * ----------------------------------------------------------------
355  */
356 
357 /*
358  * bool
359  * Boolean value, either true or false.
360  *
361  * We use stdbool.h if available and its bool has size 1. That's useful for
362  * better compiler and debugger output and for compatibility with third-party
363  * libraries. But PostgreSQL currently cannot deal with bool of other sizes;
364  * there are static assertions around the code to prevent that.
365  *
366  * For C++ compilers, we assume the compiler has a compatible built-in
367  * definition of bool.
368  *
369  * See also the version of this code in src/interfaces/ecpg/include/ecpglib.h.
370  */
371 
372 #ifndef __cplusplus
373 
374 #ifdef PG_USE_STDBOOL
375 #include <stdbool.h>
376 #else
377 
378 #ifndef bool
379 typedef unsigned char bool;
380 #endif
381 
382 #ifndef true
383 #define true ((bool) 1)
384 #endif
385 
386 #ifndef false
387 #define false ((bool) 0)
388 #endif
389 
390 #endif /* not PG_USE_STDBOOL */
391 #endif /* not C++ */
392 
393 
394 /* ----------------------------------------------------------------
395  * Section 3: standard system types
396  * ----------------------------------------------------------------
397  */
398 
399 /*
400  * Pointer
401  * Variable holding address of any memory resident object.
402  *
403  * XXX Pointer arithmetic is done with this, so it can't be void *
404  * under "true" ANSI compilers.
405  */
406 typedef char *Pointer;
407 
408 /*
409  * intN
410  * Signed integer, EXACTLY N BITS IN SIZE,
411  * used for numerical computations and the
412  * frontend/backend protocol.
413  */
414 #ifndef HAVE_INT8
415 typedef signed char int8; /* == 8 bits */
416 typedef signed short int16; /* == 16 bits */
417 typedef signed int int32; /* == 32 bits */
418 #endif /* not HAVE_INT8 */
419 
420 /*
421  * uintN
422  * Unsigned integer, EXACTLY N BITS IN SIZE,
423  * used for numerical computations and the
424  * frontend/backend protocol.
425  */
426 #ifndef HAVE_UINT8
427 typedef unsigned char uint8; /* == 8 bits */
428 typedef unsigned short uint16; /* == 16 bits */
429 typedef unsigned int uint32; /* == 32 bits */
430 #endif /* not HAVE_UINT8 */
431 
432 /*
433  * bitsN
434  * Unit of bitwise operation, AT LEAST N BITS IN SIZE.
435  */
436 typedef uint8 bits8; /* >= 8 bits */
437 typedef uint16 bits16; /* >= 16 bits */
438 typedef uint32 bits32; /* >= 32 bits */
439 
440 /*
441  * 64-bit integers
442  */
443 #ifdef HAVE_LONG_INT_64
444 /* Plain "long int" fits, use it */
445 
446 #ifndef HAVE_INT64
447 typedef long int int64;
448 #endif
449 #ifndef HAVE_UINT64
450 typedef unsigned long int uint64;
451 #endif
452 #define INT64CONST(x) (x##L)
453 #define UINT64CONST(x) (x##UL)
454 #elif defined(HAVE_LONG_LONG_INT_64)
455 /* We have working support for "long long int", use that */
456 
457 #ifndef HAVE_INT64
458 typedef long long int int64;
459 #endif
460 #ifndef HAVE_UINT64
461 typedef unsigned long long int uint64;
462 #endif
463 #define INT64CONST(x) (x##LL)
464 #define UINT64CONST(x) (x##ULL)
465 #else
466 /* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */
467 #error must have a working 64-bit integer datatype
468 #endif
469 
470 /* snprintf format strings to use for 64-bit integers */
471 #define INT64_FORMAT "%" INT64_MODIFIER "d"
472 #define UINT64_FORMAT "%" INT64_MODIFIER "u"
473 
474 /*
475  * 128-bit signed and unsigned integers
476  * There currently is only limited support for such types.
477  * E.g. 128bit literals and snprintf are not supported; but math is.
478  * Also, because we exclude such types when choosing MAXIMUM_ALIGNOF,
479  * it must be possible to coerce the compiler to allocate them on no
480  * more than MAXALIGN boundaries.
481  */
482 #if defined(PG_INT128_TYPE)
483 #if defined(pg_attribute_aligned) || ALIGNOF_PG_INT128_TYPE <= MAXIMUM_ALIGNOF
484 #define HAVE_INT128 1
485 
486 typedef PG_INT128_TYPE int128
487 #if defined(pg_attribute_aligned)
488  pg_attribute_aligned(MAXIMUM_ALIGNOF)
489 #endif
490  ;
491 
492 typedef unsigned PG_INT128_TYPE uint128
493 #if defined(pg_attribute_aligned)
494  pg_attribute_aligned(MAXIMUM_ALIGNOF)
495 #endif
496  ;
497 
498 #endif
499 #endif
500 
501 /*
502  * stdint.h limits aren't guaranteed to have compatible types with our fixed
503  * width types. So just define our own.
504  */
505 #define PG_INT8_MIN (-0x7F-1)
506 #define PG_INT8_MAX (0x7F)
507 #define PG_UINT8_MAX (0xFF)
508 #define PG_INT16_MIN (-0x7FFF-1)
509 #define PG_INT16_MAX (0x7FFF)
510 #define PG_UINT16_MAX (0xFFFF)
511 #define PG_INT32_MIN (-0x7FFFFFFF-1)
512 #define PG_INT32_MAX (0x7FFFFFFF)
513 #define PG_UINT32_MAX (0xFFFFFFFFU)
514 #define PG_INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
515 #define PG_INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF)
516 #define PG_UINT64_MAX UINT64CONST(0xFFFFFFFFFFFFFFFF)
517 
518 /*
519  * We now always use int64 timestamps, but keep this symbol defined for the
520  * benefit of external code that might test it.
521  */
522 #define HAVE_INT64_TIMESTAMP
523 
524 /*
525  * Size
526  * Size of any memory resident object, as returned by sizeof.
527  */
528 typedef size_t Size;
529 
530 /*
531  * Index
532  * Index into any memory resident array.
533  *
534  * Note:
535  * Indices are non negative.
536  */
537 typedef unsigned int Index;
538 
539 /*
540  * Offset
541  * Offset into any memory resident array.
542  *
543  * Note:
544  * This differs from an Index in that an Index is always
545  * non negative, whereas Offset may be negative.
546  */
547 typedef signed int Offset;
548 
549 /*
550  * Common Postgres datatype names (as used in the catalogs)
551  */
552 typedef float float4;
553 typedef double float8;
554 
555 #ifdef USE_FLOAT8_BYVAL
556 #define FLOAT8PASSBYVAL true
557 #else
558 #define FLOAT8PASSBYVAL false
559 #endif
560 
561 /*
562  * Oid, RegProcedure, TransactionId, SubTransactionId, MultiXactId,
563  * CommandId
564  */
565 
566 /* typedef Oid is in postgres_ext.h */
567 
568 /*
569  * regproc is the type name used in the include/catalog headers, but
570  * RegProcedure is the preferred name in C code.
571  */
572 typedef Oid regproc;
573 typedef regproc RegProcedure;
574 
576 
578 
580 
581 #define InvalidSubTransactionId ((SubTransactionId) 0)
582 #define TopSubTransactionId ((SubTransactionId) 1)
583 
584 /* MultiXactId must be equivalent to TransactionId, to fit in t_xmax */
585 typedef TransactionId MultiXactId;
586 
588 
590 
591 #define FirstCommandId ((CommandId) 0)
592 #define InvalidCommandId (~(CommandId)0)
593 
594 /*
595  * Array indexing support
596  */
597 #define MAXDIM 6
598 typedef struct
599 {
600  int indx[MAXDIM];
601 } IntArray;
602 
603 /* ----------------
604  * Variable-length datatypes all share the 'struct varlena' header.
605  *
606  * NOTE: for TOASTable types, this is an oversimplification, since the value
607  * may be compressed or moved out-of-line. However datatype-specific routines
608  * are mostly content to deal with de-TOASTed values only, and of course
609  * client-side routines should never see a TOASTed value. But even in a
610  * de-TOASTed value, beware of touching vl_len_ directly, as its
611  * representation is no longer convenient. It's recommended that code always
612  * use macros VARDATA_ANY, VARSIZE_ANY, VARSIZE_ANY_EXHDR, VARDATA, VARSIZE,
613  * and SET_VARSIZE instead of relying on direct mentions of the struct fields.
614  * See postgres.h for details of the TOASTed form.
615  * ----------------
616  */
617 struct varlena
618 {
619  char vl_len_[4]; /* Do not touch this field directly! */
620  char vl_dat[FLEXIBLE_ARRAY_MEMBER]; /* Data content is here */
621 };
622 
623 #define VARHDRSZ ((int32) sizeof(int32))
624 
625 /*
626  * These widely-used datatypes are just a varlena header and the data bytes.
627  * There is no terminating null or anything like that --- the data length is
628  * always VARSIZE_ANY_EXHDR(ptr).
629  */
630 typedef struct varlena bytea;
631 typedef struct varlena text;
632 typedef struct varlena BpChar; /* blank-padded char, ie SQL char(n) */
633 typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */
634 
635 /*
636  * Specialized array types. These are physically laid out just the same
637  * as regular arrays (so that the regular array subscripting code works
638  * with them). They exist as distinct types mostly for historical reasons:
639  * they have nonstandard I/O behavior which we don't want to change for fear
640  * of breaking applications that look at the system catalogs. There is also
641  * an implementation issue for oidvector: it's part of the primary key for
642  * pg_proc, and we can't use the normal btree array support routines for that
643  * without circularity.
644  */
645 typedef struct
646 {
647  int32 vl_len_; /* these fields must match ArrayType! */
648  int ndim; /* always 1 for int2vector */
649  int32 dataoffset; /* always 0 for int2vector */
651  int dim1;
652  int lbound1;
654 } int2vector;
655 
656 typedef struct
657 {
658  int32 vl_len_; /* these fields must match ArrayType! */
659  int ndim; /* always 1 for oidvector */
660  int32 dataoffset; /* always 0 for oidvector */
662  int dim1;
663  int lbound1;
665 } oidvector;
666 
667 /*
668  * Representation of a Name: effectively just a C string, but null-padded to
669  * exactly NAMEDATALEN bytes. The use of a struct is historical.
670  */
671 typedef struct nameData
672 {
673  char data[NAMEDATALEN];
674 } NameData;
675 typedef NameData *Name;
676 
677 #define NameStr(name) ((name).data)
678 
679 
680 /* ----------------------------------------------------------------
681  * Section 4: IsValid macros for system types
682  * ----------------------------------------------------------------
683  */
684 /*
685  * BoolIsValid
686  * True iff bool is valid.
687  */
688 #define BoolIsValid(boolean) ((boolean) == false || (boolean) == true)
689 
690 /*
691  * PointerIsValid
692  * True iff pointer is valid.
693  */
694 #define PointerIsValid(pointer) ((const void*)(pointer) != NULL)
695 
696 /*
697  * PointerIsAligned
698  * True iff pointer is properly aligned to point to the given type.
699  */
700 #define PointerIsAligned(pointer, type) \
701  (((uintptr_t)(pointer) % (sizeof (type))) == 0)
702 
703 #define OffsetToPointer(base, offset) \
704  ((void *)((char *) base + offset))
705 
706 #define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
707 
708 #define RegProcedureIsValid(p) OidIsValid(p)
709 
710 
711 /* ----------------------------------------------------------------
712  * Section 5: offsetof, lengthof, alignment
713  * ----------------------------------------------------------------
714  */
715 /*
716  * offsetof
717  * Offset of a structure/union field within that structure/union.
718  *
719  * XXX This is supposed to be part of stddef.h, but isn't on
720  * some systems (like SunOS 4).
721  */
722 #ifndef offsetof
723 #define offsetof(type, field) ((long) &((type *)0)->field)
724 #endif /* offsetof */
725 
726 /*
727  * lengthof
728  * Number of elements in an array.
729  */
730 #define lengthof(array) (sizeof (array) / sizeof ((array)[0]))
731 
732 /* ----------------
733  * Alignment macros: align a length or address appropriately for a given type.
734  * The fooALIGN() macros round up to a multiple of the required alignment,
735  * while the fooALIGN_DOWN() macros round down. The latter are more useful
736  * for problems like "how many X-sized structures will fit in a page?".
737  *
738  * NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2.
739  * That case seems extremely unlikely to be needed in practice, however.
740  *
741  * NOTE: MAXIMUM_ALIGNOF, and hence MAXALIGN(), intentionally exclude any
742  * larger-than-8-byte types the compiler might have.
743  * ----------------
744  */
745 
746 #define TYPEALIGN(ALIGNVAL,LEN) \
747  (((uintptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
748 
749 #define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
750 #define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
751 #define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
752 #define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
753 #define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
754 /* MAXALIGN covers only built-in types, not buffers */
755 #define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN))
756 #define CACHELINEALIGN(LEN) TYPEALIGN(PG_CACHE_LINE_SIZE, (LEN))
757 
758 #define TYPEALIGN_DOWN(ALIGNVAL,LEN) \
759  (((uintptr_t) (LEN)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
760 
761 #define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
762 #define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
763 #define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
764 #define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
765 #define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
766 #define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN))
767 
768 /*
769  * The above macros will not work with types wider than uintptr_t, like with
770  * uint64 on 32-bit platforms. That's not problem for the usual use where a
771  * pointer or a length is aligned, but for the odd case that you need to
772  * align something (potentially) wider, use TYPEALIGN64.
773  */
774 #define TYPEALIGN64(ALIGNVAL,LEN) \
775  (((uint64) (LEN) + ((ALIGNVAL) - 1)) & ~((uint64) ((ALIGNVAL) - 1)))
776 
777 /* we don't currently need wider versions of the other ALIGN macros */
778 #define MAXALIGN64(LEN) TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
779 
780 
781 /* ----------------------------------------------------------------
782  * Section 6: assertions
783  * ----------------------------------------------------------------
784  */
785 
786 /*
787  * USE_ASSERT_CHECKING, if defined, turns on all the assertions.
788  * - plai 9/5/90
789  *
790  * It should _NOT_ be defined in releases or in benchmark copies
791  */
792 
793 /*
794  * Assert() can be used in both frontend and backend code. In frontend code it
795  * just calls the standard assert, if it's available. If use of assertions is
796  * not configured, it does nothing.
797  */
798 #ifndef USE_ASSERT_CHECKING
799 
800 #define Assert(condition) ((void)true)
801 #define AssertMacro(condition) ((void)true)
802 #define AssertArg(condition) ((void)true)
803 #define AssertState(condition) ((void)true)
804 #define AssertPointerAlignment(ptr, bndr) ((void)true)
805 #define Trap(condition, errorType) ((void)true)
806 #define TrapMacro(condition, errorType) (true)
807 
808 #elif defined(FRONTEND)
809 
810 #include <assert.h>
811 #define Assert(p) assert(p)
812 #define AssertMacro(p) ((void) assert(p))
813 #define AssertArg(condition) assert(condition)
814 #define AssertState(condition) assert(condition)
815 #define AssertPointerAlignment(ptr, bndr) ((void)true)
816 
817 #else /* USE_ASSERT_CHECKING && !FRONTEND */
818 
819 /*
820  * Trap
821  * Generates an exception if the given condition is true.
822  */
823 #define Trap(condition, errorType) \
824  do { \
825  if (condition) \
826  ExceptionalCondition(#condition, (errorType), \
827  __FILE__, __LINE__); \
828  } while (0)
829 
830 /*
831  * TrapMacro is the same as Trap but it's intended for use in macros:
832  *
833  * #define foo(x) (AssertMacro(x != 0), bar(x))
834  *
835  * Isn't CPP fun?
836  */
837 #define TrapMacro(condition, errorType) \
838  ((bool) (! (condition) || \
839  (ExceptionalCondition(#condition, (errorType), \
840  __FILE__, __LINE__), 0)))
841 
842 #define Assert(condition) \
843  do { \
844  if (!(condition)) \
845  ExceptionalCondition(#condition, "FailedAssertion", \
846  __FILE__, __LINE__); \
847  } while (0)
848 
849 #define AssertMacro(condition) \
850  ((void) ((condition) || \
851  (ExceptionalCondition(#condition, "FailedAssertion", \
852  __FILE__, __LINE__), 0)))
853 
854 #define AssertArg(condition) \
855  do { \
856  if (!(condition)) \
857  ExceptionalCondition(#condition, "BadArgument", \
858  __FILE__, __LINE__); \
859  } while (0)
860 
861 #define AssertState(condition) \
862  do { \
863  if (!(condition)) \
864  ExceptionalCondition(#condition, "BadState", \
865  __FILE__, __LINE__); \
866  } while (0)
867 
868 /*
869  * Check that `ptr' is `bndr' aligned.
870  */
871 #define AssertPointerAlignment(ptr, bndr) \
872  Trap(TYPEALIGN(bndr, (uintptr_t)(ptr)) != (uintptr_t)(ptr), \
873  "UnalignedPointer")
874 
875 #endif /* USE_ASSERT_CHECKING && !FRONTEND */
876 
877 /*
878  * ExceptionalCondition is compiled into the backend whether or not
879  * USE_ASSERT_CHECKING is defined, so as to support use of extensions
880  * that are built with that #define with a backend that isn't. Hence,
881  * we should declare it as long as !FRONTEND.
882  */
883 #ifndef FRONTEND
884 extern void ExceptionalCondition(const char *conditionName,
885  const char *errorType,
886  const char *fileName, int lineNumber) pg_attribute_noreturn();
887 #endif
888 
889 /*
890  * Macros to support compile-time assertion checks.
891  *
892  * If the "condition" (a compile-time-constant expression) evaluates to false,
893  * throw a compile error using the "errmessage" (a string literal).
894  *
895  * gcc 4.6 and up supports _Static_assert(), but there are bizarre syntactic
896  * placement restrictions. Macros StaticAssertStmt() and StaticAssertExpr()
897  * make it safe to use as a statement or in an expression, respectively.
898  * The macro StaticAssertDecl() is suitable for use at file scope (outside of
899  * any function).
900  *
901  * Otherwise we fall back on a kluge that assumes the compiler will complain
902  * about a negative width for a struct bit-field. This will not include a
903  * helpful error message, but it beats not getting an error at all.
904  */
905 #ifndef __cplusplus
906 #ifdef HAVE__STATIC_ASSERT
907 #define StaticAssertStmt(condition, errmessage) \
908  do { _Static_assert(condition, errmessage); } while(0)
909 #define StaticAssertExpr(condition, errmessage) \
910  ((void) ({ StaticAssertStmt(condition, errmessage); true; }))
911 #define StaticAssertDecl(condition, errmessage) \
912  _Static_assert(condition, errmessage)
913 #else /* !HAVE__STATIC_ASSERT */
914 #define StaticAssertStmt(condition, errmessage) \
915  ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
916 #define StaticAssertExpr(condition, errmessage) \
917  StaticAssertStmt(condition, errmessage)
918 #define StaticAssertDecl(condition, errmessage) \
919  extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1])
920 #endif /* HAVE__STATIC_ASSERT */
921 #else /* C++ */
922 #if defined(__cpp_static_assert) && __cpp_static_assert >= 200410
923 #define StaticAssertStmt(condition, errmessage) \
924  static_assert(condition, errmessage)
925 #define StaticAssertExpr(condition, errmessage) \
926  ({ static_assert(condition, errmessage); })
927 #define StaticAssertDecl(condition, errmessage) \
928  static_assert(condition, errmessage)
929 #else /* !__cpp_static_assert */
930 #define StaticAssertStmt(condition, errmessage) \
931  do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0)
932 #define StaticAssertExpr(condition, errmessage) \
933  ((void) ({ StaticAssertStmt(condition, errmessage); }))
934 #define StaticAssertDecl(condition, errmessage) \
935  extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1])
936 #endif /* __cpp_static_assert */
937 #endif /* C++ */
938 
939 
940 /*
941  * Compile-time checks that a variable (or expression) has the specified type.
942  *
943  * AssertVariableIsOfType() can be used as a statement.
944  * AssertVariableIsOfTypeMacro() is intended for use in macros, eg
945  * #define foo(x) (AssertVariableIsOfTypeMacro(x, int), bar(x))
946  *
947  * If we don't have __builtin_types_compatible_p, we can still assert that
948  * the types have the same size. This is far from ideal (especially on 32-bit
949  * platforms) but it provides at least some coverage.
950  */
951 #ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
952 #define AssertVariableIsOfType(varname, typename) \
953  StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
954  CppAsString(varname) " does not have type " CppAsString(typename))
955 #define AssertVariableIsOfTypeMacro(varname, typename) \
956  (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
957  CppAsString(varname) " does not have type " CppAsString(typename)))
958 #else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
959 #define AssertVariableIsOfType(varname, typename) \
960  StaticAssertStmt(sizeof(varname) == sizeof(typename), \
961  CppAsString(varname) " does not have type " CppAsString(typename))
962 #define AssertVariableIsOfTypeMacro(varname, typename) \
963  (StaticAssertExpr(sizeof(varname) == sizeof(typename), \
964  CppAsString(varname) " does not have type " CppAsString(typename)))
965 #endif /* HAVE__BUILTIN_TYPES_COMPATIBLE_P */
966 
967 
968 /* ----------------------------------------------------------------
969  * Section 7: widely useful macros
970  * ----------------------------------------------------------------
971  */
972 /*
973  * Max
974  * Return the maximum of two numbers.
975  */
976 #define Max(x, y) ((x) > (y) ? (x) : (y))
977 
978 /*
979  * Min
980  * Return the minimum of two numbers.
981  */
982 #define Min(x, y) ((x) < (y) ? (x) : (y))
983 
984 /*
985  * Abs
986  * Return the absolute value of the argument.
987  */
988 #define Abs(x) ((x) >= 0 ? (x) : -(x))
989 
990 
991 /* Get a bit mask of the bits set in non-long aligned addresses */
992 #define LONG_ALIGN_MASK (sizeof(long) - 1)
993 
994 /*
995  * MemSet
996  * Exactly the same as standard library function memset(), but considerably
997  * faster for zeroing small word-aligned structures (such as parsetree nodes).
998  * This has to be a macro because the main point is to avoid function-call
999  * overhead. However, we have also found that the loop is faster than
1000  * native libc memset() on some platforms, even those with assembler
1001  * memset() functions. More research needs to be done, perhaps with
1002  * MEMSET_LOOP_LIMIT tests in configure.
1003  */
1004 #define MemSet(start, val, len) \
1005  do \
1006  { \
1007  /* must be void* because we don't know if it is integer aligned yet */ \
1008  void *_vstart = (void *) (start); \
1009  int _val = (val); \
1010  Size _len = (len); \
1011 \
1012  if ((((uintptr_t) _vstart) & LONG_ALIGN_MASK) == 0 && \
1013  (_len & LONG_ALIGN_MASK) == 0 && \
1014  _val == 0 && \
1015  _len <= MEMSET_LOOP_LIMIT && \
1016  /* \
1017  * If MEMSET_LOOP_LIMIT == 0, optimizer should find \
1018  * the whole "if" false at compile time. \
1019  */ \
1020  MEMSET_LOOP_LIMIT != 0) \
1021  { \
1022  long *_start = (long *) _vstart; \
1023  long *_stop = (long *) ((char *) _start + _len); \
1024  while (_start < _stop) \
1025  *_start++ = 0; \
1026  } \
1027  else \
1028  memset(_vstart, _val, _len); \
1029  } while (0)
1030 
1031 /*
1032  * MemSetAligned is the same as MemSet except it omits the test to see if
1033  * "start" is word-aligned. This is okay to use if the caller knows a-priori
1034  * that the pointer is suitably aligned (typically, because he just got it
1035  * from palloc(), which always delivers a max-aligned pointer).
1036  */
1037 #define MemSetAligned(start, val, len) \
1038  do \
1039  { \
1040  long *_start = (long *) (start); \
1041  int _val = (val); \
1042  Size _len = (len); \
1043 \
1044  if ((_len & LONG_ALIGN_MASK) == 0 && \
1045  _val == 0 && \
1046  _len <= MEMSET_LOOP_LIMIT && \
1047  MEMSET_LOOP_LIMIT != 0) \
1048  { \
1049  long *_stop = (long *) ((char *) _start + _len); \
1050  while (_start < _stop) \
1051  *_start++ = 0; \
1052  } \
1053  else \
1054  memset(_start, _val, _len); \
1055  } while (0)
1056 
1057 
1058 /*
1059  * MemSetTest/MemSetLoop are a variant version that allow all the tests in
1060  * MemSet to be done at compile time in cases where "val" and "len" are
1061  * constants *and* we know the "start" pointer must be word-aligned.
1062  * If MemSetTest succeeds, then it is okay to use MemSetLoop, otherwise use
1063  * MemSetAligned. Beware of multiple evaluations of the arguments when using
1064  * this approach.
1065  */
1066 #define MemSetTest(val, len) \
1067  ( ((len) & LONG_ALIGN_MASK) == 0 && \
1068  (len) <= MEMSET_LOOP_LIMIT && \
1069  MEMSET_LOOP_LIMIT != 0 && \
1070  (val) == 0 )
1071 
1072 #define MemSetLoop(start, val, len) \
1073  do \
1074  { \
1075  long * _start = (long *) (start); \
1076  long * _stop = (long *) ((char *) _start + (Size) (len)); \
1077  \
1078  while (_start < _stop) \
1079  *_start++ = 0; \
1080  } while (0)
1081 
1082 /*
1083  * Macros for range-checking float values before converting to integer.
1084  * We must be careful here that the boundary values are expressed exactly
1085  * in the float domain. PG_INTnn_MIN is an exact power of 2, so it will
1086  * be represented exactly; but PG_INTnn_MAX isn't, and might get rounded
1087  * off, so avoid using that.
1088  * The input must be rounded to an integer beforehand, typically with rint(),
1089  * else we might draw the wrong conclusion about close-to-the-limit values.
1090  * These macros will do the right thing for Inf, but not necessarily for NaN,
1091  * so check isnan(num) first if that's a possibility.
1092  */
1093 #define FLOAT4_FITS_IN_INT16(num) \
1094  ((num) >= (float4) PG_INT16_MIN && (num) < -((float4) PG_INT16_MIN))
1095 #define FLOAT4_FITS_IN_INT32(num) \
1096  ((num) >= (float4) PG_INT32_MIN && (num) < -((float4) PG_INT32_MIN))
1097 #define FLOAT4_FITS_IN_INT64(num) \
1098  ((num) >= (float4) PG_INT64_MIN && (num) < -((float4) PG_INT64_MIN))
1099 #define FLOAT8_FITS_IN_INT16(num) \
1100  ((num) >= (float8) PG_INT16_MIN && (num) < -((float8) PG_INT16_MIN))
1101 #define FLOAT8_FITS_IN_INT32(num) \
1102  ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))
1103 #define FLOAT8_FITS_IN_INT64(num) \
1104  ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN))
1105 
1106 
1107 /* ----------------------------------------------------------------
1108  * Section 8: random stuff
1109  * ----------------------------------------------------------------
1110  */
1111 
1112 #ifdef HAVE_STRUCT_SOCKADDR_UN
1113 #define HAVE_UNIX_SOCKETS 1
1114 #endif
1115 
1116 /*
1117  * Invert the sign of a qsort-style comparison result, ie, exchange negative
1118  * and positive integer values, being careful not to get the wrong answer
1119  * for INT_MIN. The argument should be an integral variable.
1120  */
1121 #define INVERT_COMPARE_RESULT(var) \
1122  ((var) = ((var) < 0) ? 1 : -(var))
1123 
1124 /*
1125  * Use this, not "char buf[BLCKSZ]", to declare a field or local variable
1126  * holding a page buffer, if that page might be accessed as a page and not
1127  * just a string of bytes. Otherwise the variable might be under-aligned,
1128  * causing problems on alignment-picky hardware. (In some places, we use
1129  * this to declare buffers even though we only pass them to read() and
1130  * write(), because copying to/from aligned buffers is usually faster than
1131  * using unaligned buffers.) We include both "double" and "int64" in the
1132  * union to ensure that the compiler knows the value must be MAXALIGN'ed
1133  * (cf. configure's computation of MAXIMUM_ALIGNOF).
1134  */
1135 typedef union PGAlignedBlock
1136 {
1137  char data[BLCKSZ];
1140 } PGAlignedBlock;
1141 
1142 /* Same, but for an XLOG_BLCKSZ-sized buffer */
1143 typedef union PGAlignedXLogBlock
1144 {
1145  char data[XLOG_BLCKSZ];
1149 
1150 /* msb for char */
1151 #define HIGHBIT (0x80)
1152 #define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
1153 
1154 /*
1155  * Support macros for escaping strings. escape_backslash should be true
1156  * if generating a non-standard-conforming string. Prefixing a string
1157  * with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
1158  * Beware of multiple evaluation of the "ch" argument!
1159  */
1160 #define SQL_STR_DOUBLE(ch, escape_backslash) \
1161  ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
1162 
1163 #define ESCAPE_STRING_SYNTAX 'E'
1164 
1165 
1166 #define STATUS_OK (0)
1167 #define STATUS_ERROR (-1)
1168 #define STATUS_EOF (-2)
1169 
1170 /*
1171  * gettext support
1172  */
1173 
1174 #ifndef ENABLE_NLS
1175 /* stuff we'd otherwise get from <libintl.h> */
1176 #define gettext(x) (x)
1177 #define dgettext(d,x) (x)
1178 #define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
1179 #define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
1180 #endif
1181 
1182 #define _(x) gettext(x)
1183 
1184 /*
1185  * Use this to mark string constants as needing translation at some later
1186  * time, rather than immediately. This is useful for cases where you need
1187  * access to the original string and translated string, and for cases where
1188  * immediate translation is not possible, like when initializing global
1189  * variables.
1190  *
1191  * https://www.gnu.org/software/gettext/manual/html_node/Special-cases.html
1192  */
1193 #define gettext_noop(x) (x)
1194 
1195 /*
1196  * To better support parallel installations of major PostgreSQL
1197  * versions as well as parallel installations of major library soname
1198  * versions, we mangle the gettext domain name by appending those
1199  * version numbers. The coding rule ought to be that wherever the
1200  * domain name is mentioned as a literal, it must be wrapped into
1201  * PG_TEXTDOMAIN(). The macros below do not work on non-literals; but
1202  * that is somewhat intentional because it avoids having to worry
1203  * about multiple states of premangling and postmangling as the values
1204  * are being passed around.
1205  *
1206  * Make sure this matches the installation rules in nls-global.mk.
1207  */
1208 #ifdef SO_MAJOR_VERSION
1209 #define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1210 #else
1211 #define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
1212 #endif
1213 
1214 /*
1215  * Macro that allows to cast constness and volatile away from an expression, but doesn't
1216  * allow changing the underlying type. Enforcement of the latter
1217  * currently only works for gcc like compilers.
1218  *
1219  * Please note IT IS NOT SAFE to cast constness away if the result will ever
1220  * be modified (it would be undefined behaviour). Doing so anyway can cause
1221  * compiler misoptimizations or runtime crashes (modifying readonly memory).
1222  * It is only safe to use when the result will not be modified, but API
1223  * design or language restrictions prevent you from declaring that
1224  * (e.g. because a function returns both const and non-const variables).
1225  *
1226  * Note that this only works in function scope, not for global variables (it'd
1227  * be nice, but not trivial, to improve that).
1228  */
1229 #if defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
1230 #define unconstify(underlying_type, expr) \
1231  (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
1232  "wrong cast"), \
1233  (underlying_type) (expr))
1234 #define unvolatize(underlying_type, expr) \
1235  (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
1236  "wrong cast"), \
1237  (underlying_type) (expr))
1238 #else
1239 #define unconstify(underlying_type, expr) \
1240  ((underlying_type) (expr))
1241 #define unvolatize(underlying_type, expr) \
1242  ((underlying_type) (expr))
1243 #endif
1244 
1245 /* ----------------------------------------------------------------
1246  * Section 9: system-specific hacks
1247  *
1248  * This should be limited to things that absolutely have to be
1249  * included in every source file. The port-specific header file
1250  * is usually a better place for this sort of thing.
1251  * ----------------------------------------------------------------
1252  */
1253 
1254 /*
1255  * NOTE: this is also used for opening text files.
1256  * WIN32 treats Control-Z as EOF in files opened in text mode.
1257  * Therefore, we open files in binary mode on Win32 so we can read
1258  * literal control-Z. The other affect is that we see CRLF, but
1259  * that is OK because we can already handle those cleanly.
1260  */
1261 #if defined(WIN32) || defined(__CYGWIN__)
1262 #define PG_BINARY O_BINARY
1263 #define PG_BINARY_A "ab"
1264 #define PG_BINARY_R "rb"
1265 #define PG_BINARY_W "wb"
1266 #else
1267 #define PG_BINARY 0
1268 #define PG_BINARY_A "a"
1269 #define PG_BINARY_R "r"
1270 #define PG_BINARY_W "w"
1271 #endif
1272 
1273 /*
1274  * Provide prototypes for routines not present in a particular machine's
1275  * standard C library.
1276  */
1277 
1278 #if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC
1279 extern int fdatasync(int fildes);
1280 #endif
1281 
1282 /* Older platforms may provide strto[u]ll functionality under other names */
1283 #if !defined(HAVE_STRTOLL) && defined(HAVE___STRTOLL)
1284 #define strtoll __strtoll
1285 #define HAVE_STRTOLL 1
1286 #endif
1287 
1288 #if !defined(HAVE_STRTOLL) && defined(HAVE_STRTOQ)
1289 #define strtoll strtoq
1290 #define HAVE_STRTOLL 1
1291 #endif
1292 
1293 #if !defined(HAVE_STRTOULL) && defined(HAVE___STRTOULL)
1294 #define strtoull __strtoull
1295 #define HAVE_STRTOULL 1
1296 #endif
1297 
1298 #if !defined(HAVE_STRTOULL) && defined(HAVE_STRTOUQ)
1299 #define strtoull strtouq
1300 #define HAVE_STRTOULL 1
1301 #endif
1302 
1303 #if defined(HAVE_STRTOLL) && !HAVE_DECL_STRTOLL
1304 extern long long strtoll(const char *str, char **endptr, int base);
1305 #endif
1306 
1307 #if defined(HAVE_STRTOULL) && !HAVE_DECL_STRTOULL
1308 extern unsigned long long strtoull(const char *str, char **endptr, int base);
1309 #endif
1310 
1311 /* no special DLL markers on most ports */
1312 #ifndef PGDLLIMPORT
1313 #define PGDLLIMPORT
1314 #endif
1315 #ifndef PGDLLEXPORT
1316 #define PGDLLEXPORT
1317 #endif
1318 
1319 /*
1320  * The following is used as the arg list for signal handlers. Any ports
1321  * that take something other than an int argument should override this in
1322  * their pg_config_os.h file. Note that variable names are required
1323  * because it is used in both the prototypes as well as the definitions.
1324  * Note also the long name. We expect that this won't collide with
1325  * other names causing compiler warnings.
1326  */
1327 
1328 #ifndef SIGNAL_ARGS
1329 #define SIGNAL_ARGS int postgres_signal_arg
1330 #endif
1331 
1332 /*
1333  * When there is no sigsetjmp, its functionality is provided by plain
1334  * setjmp. Incidentally, nothing provides setjmp's functionality in
1335  * that case. We now support the case only on Windows.
1336  */
1337 #ifdef WIN32
1338 #define sigjmp_buf jmp_buf
1339 #define sigsetjmp(x,y) setjmp(x)
1340 #define siglongjmp longjmp
1341 #endif
1342 
1343 /* EXEC_BACKEND defines */
1344 #ifdef EXEC_BACKEND
1345 #define NON_EXEC_STATIC
1346 #else
1347 #define NON_EXEC_STATIC static
1348 #endif
1349 
1350 /* /port compatibility functions */
1351 #include "port.h"
1352 
1353 #endif /* C_H */
signed short int16
Definition: c.h:416
uint32 CommandId
Definition: c.h:589
int lbound1
Definition: c.h:652
Definition: c.h:656
#define pg_attribute_noreturn()
Definition: c.h:167
uint32 MultiXactOffset
Definition: c.h:587
uint32 TransactionId
Definition: c.h:575
#define MAXDIM
Definition: c.h:597
uint16 bits16
Definition: c.h:437
regproc RegProcedure
Definition: c.h:573
int64 force_align_i64
Definition: c.h:1147
unsigned char uint8
Definition: c.h:427
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:338
int32 dataoffset
Definition: c.h:660
Oid elemtype
Definition: c.h:650
uint32 SubTransactionId
Definition: c.h:579
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:417
char vl_len_[4]
Definition: c.h:619
#define NAMEDATALEN
unsigned short uint16
Definition: c.h:428
char * Pointer
Definition: c.h:406
int32 dataoffset
Definition: c.h:649
double float8
Definition: c.h:553
union PGAlignedXLogBlock PGAlignedXLogBlock
union PGAlignedBlock PGAlignedBlock
double force_align_d
Definition: c.h:1146
int32 vl_len_
Definition: c.h:658
Definition: c.h:671
int dim1
Definition: c.h:662
int ndim
Definition: c.h:648
unsigned int uint32
Definition: c.h:429
uint32 LocalTransactionId
Definition: c.h:577
char vl_dat[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:620
signed char int8
Definition: c.h:415
float float4
Definition: c.h:552
uint8 bits8
Definition: c.h:436
Definition: c.h:645
int dim1
Definition: c.h:651
unsigned int Index
Definition: c.h:537
TransactionId MultiXactId
Definition: c.h:585
uint32 bits32
Definition: c.h:438
int32 vl_len_
Definition: c.h:647
signed int Offset
Definition: c.h:547
size_t Size
Definition: c.h:528
int lbound1
Definition: c.h:663
int64 force_align_i64
Definition: c.h:1139
Oid regproc
Definition: c.h:572
static Datum values[MAXATTR]
Definition: bootstrap.c:165
Definition: c.h:598
Oid elemtype
Definition: c.h:661
double force_align_d
Definition: c.h:1138
struct nameData NameData
void(* pg_funcptr_t)(void)
Definition: c.h:328
Definition: c.h:617
NameData * Name
Definition: c.h:675
int ndim
Definition: c.h:659
void ExceptionalCondition(const char *conditionName, const char *errorType, const char *fileName, int lineNumber) pg_attribute_noreturn()
Definition: assert.c:30
unsigned char bool
Definition: c.h:379