59#include "pg_config_os.h"
76#if defined(WIN32) || defined(__CYGWIN__)
106#ifdef PG_FORCE_DISABLE_INLINE
115#define pg_restrict restrict
130#ifndef __has_attribute
131#define __has_attribute(attribute) 0
136#define pg_attribute_unused() __attribute__((unused))
138#define pg_attribute_unused()
148#define pg_nodiscard __attribute__((warn_unused_result))
163#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
164#define pg_noreturn _Noreturn
165#elif defined(__GNUC__)
166#define pg_noreturn __attribute__((noreturn))
167#elif defined(_MSC_VER)
168#define pg_noreturn __declspec(noreturn)
177#if defined(__clang__) || __GNUC__ >= 8
178#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize("address")))
179#elif __has_attribute(no_sanitize_address)
181#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize_address))
183#define pg_attribute_no_sanitize_address()
192#if __clang_major__ >= 7 || __GNUC__ >= 8
193#define pg_attribute_no_sanitize_alignment() __attribute__((no_sanitize("alignment")))
195#define pg_attribute_no_sanitize_alignment()
203#if __has_attribute (nonnull)
204#define pg_attribute_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
206#define pg_attribute_nonnull(...)
215#if __has_attribute (target)
216#define pg_attribute_target(...) __attribute__((target(__VA_ARGS__)))
218#define pg_attribute_target(...)
226#ifdef USE_ASSERT_CHECKING
227#define PG_USED_FOR_ASSERTS_ONLY
229#define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
237#define PG_PRINTF_ATTRIBUTE PG_C_PRINTF_ATTRIBUTE
239#define PG_PRINTF_ATTRIBUTE PG_CXX_PRINTF_ATTRIBUTE
244#define pg_attribute_format_arg(a) __attribute__((format_arg(a)))
245#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
247#define pg_attribute_format_arg(a)
248#define pg_attribute_printf(f,a)
253#define pg_attribute_aligned(a) __attribute__((aligned(a)))
254#define pg_attribute_packed() __attribute__((packed))
255#elif defined(_MSC_VER)
262#define pg_attribute_aligned(a) __declspec(align(a))
277#if defined(__GNUC__) && defined(__OPTIMIZE__)
279#define pg_attribute_always_inline __attribute__((always_inline)) inline
280#elif defined(_MSC_VER)
282#define pg_attribute_always_inline __forceinline
285#define pg_attribute_always_inline inline
296#define pg_noinline __attribute__((noinline))
298#elif defined(_MSC_VER)
299#define pg_noinline __declspec(noinline)
313#if defined(__MINGW64__) && __GNUC__ == 8 && __GNUC_MINOR__ == 1
315#define pg_attribute_cold
316#define pg_attribute_hot
323#if __has_attribute (cold)
324#define pg_attribute_cold __attribute__((cold))
326#define pg_attribute_cold
329#if __has_attribute (hot)
330#define pg_attribute_hot __attribute__((hot))
332#define pg_attribute_hot
342#if defined(HAVE__BUILTIN_UNREACHABLE) && !defined(USE_ASSERT_CHECKING)
343#define pg_unreachable() __builtin_unreachable()
344#elif defined(_MSC_VER) && !defined(USE_ASSERT_CHECKING)
345#define pg_unreachable() __assume(0)
347#define pg_unreachable() abort()
357#if defined(HAVE__BUILTIN_CONSTANT_P)
360#define pg_integer_constant_p(x) __builtin_constant_p(x)
361#define HAVE_PG_INTEGER_CONSTANT_P
362#elif defined(_MSC_VER) && defined(__STDC_VERSION__)
371#define pg_integer_constant_p(x) \
372 _Generic((1 ? ((void *) ((x) * (uintptr_t) 0)) : &(int) {1}), int *: 1, void *: 0)
373#define HAVE_PG_INTEGER_CONSTANT_P
392#if defined(USE_ASSERT_CHECKING)
393#define pg_assume(expr) Assert(expr)
394#elif defined(HAVE__BUILTIN_UNREACHABLE)
395#define pg_assume(expr) \
398 __builtin_unreachable(); \
400#elif defined(_MSC_VER)
401#define pg_assume(expr) __assume(expr)
403#define pg_assume(expr) ((void) 0)
414#define likely(x) __builtin_expect((x) != 0, 1)
415#define unlikely(x) __builtin_expect((x) != 0, 0)
417#define likely(x) ((x) != 0)
418#define unlikely(x) ((x) != 0)
433#define CppAsString(identifier) #identifier
434#define CppAsString2(x) CppAsString(x)
435#define CppConcat(x, y) x##y
451#define VA_ARGS_NARGS(...) \
452 VA_ARGS_NARGS_(__VA_ARGS__, \
454 59,58,57,56,55,54,53,52,51,50, \
455 49,48,47,46,45,44,43,42,41,40, \
456 39,38,37,36,35,34,33,32,31,30, \
457 29,28,27,26,25,24,23,22,21,20, \
458 19,18,17,16,15,14,13,12,11,10, \
459 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
461#define VA_ARGS_NARGS_( \
462 _01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
463 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
464 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
465 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
466 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
467 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
468 _61,_62,_63, N, ...) \
486#define FLEXIBLE_ARRAY_MEMBER
513#define HAVE_PRAGMA_GCC_SYSTEM_HEADER 1
566#define INT64CONST(x) INT64_C(x)
567#define UINT64CONST(x) UINT64_C(x)
570#define INT64_FORMAT "%" PRId64
571#define UINT64_FORMAT "%" PRIu64
581#if defined(PG_INT128_TYPE)
582#if defined(pg_attribute_aligned) || ALIGNOF_PG_INT128_TYPE <= MAXIMUM_ALIGNOF
585typedef PG_INT128_TYPE int128
586#if defined(pg_attribute_aligned)
587 pg_attribute_aligned(MAXIMUM_ALIGNOF)
591typedef unsigned PG_INT128_TYPE uint128
592#if defined(pg_attribute_aligned)
593 pg_attribute_aligned(MAXIMUM_ALIGNOF)
601#define PG_INT8_MIN INT8_MIN
602#define PG_INT8_MAX INT8_MAX
603#define PG_UINT8_MAX UINT8_MAX
604#define PG_INT16_MIN INT16_MIN
605#define PG_INT16_MAX INT16_MAX
606#define PG_UINT16_MAX UINT16_MAX
607#define PG_INT32_MIN INT32_MIN
608#define PG_INT32_MAX INT32_MAX
609#define PG_UINT32_MAX UINT32_MAX
610#define PG_INT64_MIN INT64_MIN
611#define PG_INT64_MAX INT64_MAX
612#define PG_UINT64_MAX UINT64_MAX
618#define HAVE_INT64_TIMESTAMP
655#define FLOAT8PASSBYVAL true
677#define InvalidSubTransactionId ((SubTransactionId) 0)
678#define TopSubTransactionId ((SubTransactionId) 1)
687#define FirstCommandId ((CommandId) 0)
688#define InvalidCommandId (~(CommandId)0)
711#define VARHDRSZ ((int32) sizeof(int32))
765#define NameStr(name) ((name).data)
776#define BoolIsValid(boolean) ((boolean) == false || (boolean) == true)
782#define PointerIsAligned(pointer, type) \
783 (((uintptr_t)(pointer) % (sizeof (type))) == 0)
785#define OffsetToPointer(base, offset) \
786 ((void *)((char *) base + offset))
788#define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
790#define RegProcedureIsValid(p) OidIsValid(p)
801#define lengthof(array) (sizeof (array) / sizeof ((array)[0]))
817#define TYPEALIGN(ALIGNVAL,LEN) \
818 (((uintptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
820#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
821#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
822#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
823#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
824#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
826#define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN))
827#define CACHELINEALIGN(LEN) TYPEALIGN(PG_CACHE_LINE_SIZE, (LEN))
829#define TYPEALIGN_DOWN(ALIGNVAL,LEN) \
830 (((uintptr_t) (LEN)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
832#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
833#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
834#define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
835#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
836#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
837#define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN))
845#define TYPEALIGN64(ALIGNVAL,LEN) \
846 (((uint64) (LEN) + ((ALIGNVAL) - 1)) & ~((uint64) ((ALIGNVAL) - 1)))
849#define MAXALIGN64(LEN) TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
869#ifndef USE_ASSERT_CHECKING
871#define Assert(condition) ((void)true)
872#define AssertMacro(condition) ((void)true)
874#elif defined(FRONTEND)
876#define Assert(p) assert(p)
877#define AssertMacro(p) ((void) assert(p))
885#define Assert(condition) \
888 ExceptionalCondition(#condition, __FILE__, __LINE__); \
897#define AssertMacro(condition) \
898 ((void) ((condition) || \
899 (ExceptionalCondition(#condition, __FILE__, __LINE__), 0)))
906#define AssertPointerAlignment(ptr, bndr) \
907 Assert(TYPEALIGN(bndr, (uintptr_t)(ptr)) == (uintptr_t)(ptr))
917 const char *fileName,
int lineNumber);
940#ifdef HAVE__STATIC_ASSERT
941#define StaticAssertDecl(condition, errmessage) \
942 _Static_assert(condition, errmessage)
943#define StaticAssertStmt(condition, errmessage) \
944 do { _Static_assert(condition, errmessage); } while(0)
945#define StaticAssertExpr(condition, errmessage) \
946 ((void) ({ StaticAssertStmt(condition, errmessage); true; }))
948#define StaticAssertDecl(condition, errmessage) \
949 extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1])
950#define StaticAssertStmt(condition, errmessage) \
951 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
952#define StaticAssertExpr(condition, errmessage) \
953 StaticAssertStmt(condition, errmessage)
956#if defined(__cpp_static_assert) && __cpp_static_assert >= 200410
957#define StaticAssertDecl(condition, errmessage) \
958 static_assert(condition, errmessage)
959#define StaticAssertStmt(condition, errmessage) \
960 static_assert(condition, errmessage)
961#define StaticAssertExpr(condition, errmessage) \
962 ({ static_assert(condition, errmessage); })
964#define StaticAssertDecl(condition, errmessage) \
965 extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1])
966#define StaticAssertStmt(condition, errmessage) \
967 do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0)
968#define StaticAssertExpr(condition, errmessage) \
969 ((void) ({ StaticAssertStmt(condition, errmessage); }))
985#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
986#define AssertVariableIsOfType(varname, typename) \
987 StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
988 CppAsString(varname) " does not have type " CppAsString(typename))
989#define AssertVariableIsOfTypeMacro(varname, typename) \
990 (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
991 CppAsString(varname) " does not have type " CppAsString(typename)))
993#define AssertVariableIsOfType(varname, typename) \
994 StaticAssertStmt(sizeof(varname) == sizeof(typename), \
995 CppAsString(varname) " does not have type " CppAsString(typename))
996#define AssertVariableIsOfTypeMacro(varname, typename) \
997 (StaticAssertExpr(sizeof(varname) == sizeof(typename), \
998 CppAsString(varname) " does not have type " CppAsString(typename)))
1010#define Max(x, y) ((x) > (y) ? (x) : (y))
1016#define Min(x, y) ((x) < (y) ? (x) : (y))
1020#define SIZE_T_ALIGN_MASK (sizeof(size_t) - 1)
1032#define MemSet(start, val, len) \
1036 void *_vstart = (void *) (start); \
1038 Size _len = (len); \
1040 if ((((uintptr_t) _vstart) & SIZE_T_ALIGN_MASK) == 0 && \
1041 (_len & SIZE_T_ALIGN_MASK) == 0 && \
1043 _len <= MEMSET_LOOP_LIMIT && \
1048 MEMSET_LOOP_LIMIT != 0) \
1050 size_t *_start = (size_t *) _vstart; \
1051 size_t *_stop = (size_t *) ((char *) _start + _len); \
1052 while (_start < _stop) \
1056 memset(_vstart, _val, _len); \
1065#define MemSetAligned(start, val, len) \
1068 size_t *_start = (size_t *) (start); \
1070 Size _len = (len); \
1072 if ((_len & SIZE_T_ALIGN_MASK) == 0 && \
1074 _len <= MEMSET_LOOP_LIMIT && \
1075 MEMSET_LOOP_LIMIT != 0) \
1077 size_t *_stop = (size_t *) ((char *) _start + _len); \
1078 while (_start < _stop) \
1082 memset(_start, _val, _len); \
1097#define FLOAT4_FITS_IN_INT16(num) \
1098 ((num) >= (float4) PG_INT16_MIN && (num) < -((float4) PG_INT16_MIN))
1099#define FLOAT4_FITS_IN_INT32(num) \
1100 ((num) >= (float4) PG_INT32_MIN && (num) < -((float4) PG_INT32_MIN))
1101#define FLOAT4_FITS_IN_INT64(num) \
1102 ((num) >= (float4) PG_INT64_MIN && (num) < -((float4) PG_INT64_MIN))
1103#define FLOAT8_FITS_IN_INT16(num) \
1104 ((num) >= (float8) PG_INT16_MIN && (num) < -((float8) PG_INT16_MIN))
1105#define FLOAT8_FITS_IN_INT32(num) \
1106 ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))
1107#define FLOAT8_FITS_IN_INT64(num) \
1108 ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN))
1121#define INVERT_COMPARE_RESULT(var) \
1122 ((var) = ((var) < 0) ? 1 : -(var))
1132 alignas(MAXIMUM_ALIGNOF)
char data[BLCKSZ];
1155#define HIGHBIT (0x80)
1156#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
1164#define SQL_STR_DOUBLE(ch, escape_backslash) \
1165 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
1167#define ESCAPE_STRING_SYNTAX 'E'
1170#define STATUS_OK (0)
1171#define STATUS_ERROR (-1)
1172#define STATUS_EOF (-2)
1180#define gettext(x) (x)
1181#define dgettext(d,x) (x)
1182#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
1183#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
1186#define _(x) gettext(x)
1197#define gettext_noop(x) (x)
1212#ifdef SO_MAJOR_VERSION
1213#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1215#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
1233#if defined(__cplusplus)
1234#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
1235#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
1236#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
1237#define unconstify(underlying_type, expr) \
1238 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
1240 (underlying_type) (expr))
1241#define unvolatize(underlying_type, expr) \
1242 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
1244 (underlying_type) (expr))
1246#define unconstify(underlying_type, expr) \
1247 ((underlying_type) (expr))
1248#define unvolatize(underlying_type, expr) \
1249 ((underlying_type) (expr))
1268#if defined(WIN32) || defined(__CYGWIN__)
1269#define PG_BINARY O_BINARY
1270#define PG_BINARY_A "ab"
1271#define PG_BINARY_R "rb"
1272#define PG_BINARY_W "wb"
1275#define PG_BINARY_A "a"
1276#define PG_BINARY_R "r"
1277#define PG_BINARY_W "w"
1285#if !HAVE_DECL_FDATASYNC
1295#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))
1296#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base))
1297#elif SIZEOF_LONG_LONG == 8
1298#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base))
1299#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base))
1301#error "cannot find integer type of the same size as int64_t"
1308#define i64abs(i) ((int64) labs(i))
1309#elif SIZEOF_LONG_LONG == 8
1310#define i64abs(i) ((int64) llabs(i))
1312#error "cannot find integer type of the same size as int64_t"
1333#ifdef HAVE_VISIBILITY_ATTRIBUTE
1334#define PGDLLEXPORT __attribute__((visibility("default")))
1350#define SIGNAL_ARGS int postgres_signal_arg
1361typedef intptr_t sigjmp_buf[5];
1362#define sigsetjmp(x,y) __builtin_setjmp(x)
1363#define siglongjmp __builtin_longjmp
1365#define sigjmp_buf jmp_buf
1366#define sigsetjmp(x,y) setjmp(x)
1367#define siglongjmp longjmp
static Datum values[MAXATTR]
struct PGAlignedBlock PGAlignedBlock
pg_noreturn void ExceptionalCondition(const char *conditionName, const char *fileName, int lineNumber)
struct PGAlignedXLogBlock PGAlignedXLogBlock
TransactionId MultiXactId
#define FLEXIBLE_ARRAY_MEMBER
struct PGIOAlignedBlock PGIOAlignedBlock
uint32 LocalTransactionId
int fdatasync(int fildes)
void(* pg_funcptr_t)(void)
char vl_dat[FLEXIBLE_ARRAY_MEMBER]