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