59#include "pg_config_os.h"
76#if defined(WIN32) || defined(__CYGWIN__)
106#ifdef PG_FORCE_DISABLE_INLINE
124#ifndef __has_attribute
125#define __has_attribute(attribute) 0
130#define pg_attribute_unused() __attribute__((unused))
132#define pg_attribute_unused()
139#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || (defined(__cplusplus) && __cplusplus >= 201703L)
140#define pg_fallthrough [[fallthrough]]
141#elif __has_attribute(fallthrough)
142#define pg_fallthrough __attribute__((fallthrough))
144#define pg_fallthrough
154#define pg_nodiscard __attribute__((warn_unused_result))
169#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) && !defined(__cplusplus)
170#define pg_noreturn _Noreturn
171#elif defined(__GNUC__)
172#define pg_noreturn __attribute__((noreturn))
173#elif defined(_MSC_VER)
174#define pg_noreturn __declspec(noreturn)
183#if defined(__clang__) || __GNUC__ >= 8
184#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize("address")))
185#elif __has_attribute(no_sanitize_address)
187#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize_address))
189#define pg_attribute_no_sanitize_address()
198#if __clang_major__ >= 7 || __GNUC__ >= 8
199#define pg_attribute_no_sanitize_alignment() __attribute__((no_sanitize("alignment")))
201#define pg_attribute_no_sanitize_alignment()
209#if __has_attribute (nonnull)
210#define pg_attribute_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
212#define pg_attribute_nonnull(...)
221#if __has_attribute (target)
222#define pg_attribute_target(...) __attribute__((target(__VA_ARGS__)))
224#define pg_attribute_target(...)
232#ifdef USE_ASSERT_CHECKING
233#define PG_USED_FOR_ASSERTS_ONLY
235#define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
243#define PG_PRINTF_ATTRIBUTE PG_C_PRINTF_ATTRIBUTE
245#define PG_PRINTF_ATTRIBUTE PG_CXX_PRINTF_ATTRIBUTE
250#define pg_attribute_format_arg(a) __attribute__((format_arg(a)))
251#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
253#define pg_attribute_format_arg(a)
254#define pg_attribute_printf(f,a)
259#define pg_attribute_aligned(a) __attribute__((aligned(a)))
260#define pg_attribute_packed() __attribute__((packed))
261#elif defined(_MSC_VER)
268#define pg_attribute_aligned(a) __declspec(align(a))
283#if defined(__GNUC__) && defined(__OPTIMIZE__)
285#define pg_attribute_always_inline __attribute__((always_inline)) inline
286#elif defined(_MSC_VER)
288#define pg_attribute_always_inline __forceinline
291#define pg_attribute_always_inline inline
302#define pg_noinline __attribute__((noinline))
304#elif defined(_MSC_VER)
305#define pg_noinline __declspec(noinline)
319#if defined(__MINGW64__) && __GNUC__ == 8 && __GNUC_MINOR__ == 1
321#define pg_attribute_cold
322#define pg_attribute_hot
329#if __has_attribute (cold)
330#define pg_attribute_cold __attribute__((cold))
332#define pg_attribute_cold
335#if __has_attribute (hot)
336#define pg_attribute_hot __attribute__((hot))
338#define pg_attribute_hot
348#if defined(HAVE__BUILTIN_UNREACHABLE) && !defined(USE_ASSERT_CHECKING)
349#define pg_unreachable() __builtin_unreachable()
350#elif defined(_MSC_VER) && !defined(USE_ASSERT_CHECKING)
351#define pg_unreachable() __assume(0)
353#define pg_unreachable() abort()
363#if defined(HAVE__BUILTIN_CONSTANT_P)
366#define pg_integer_constant_p(x) __builtin_constant_p(x)
367#define HAVE_PG_INTEGER_CONSTANT_P
368#elif defined(_MSC_VER) && defined(__STDC_VERSION__)
377#define pg_integer_constant_p(x) \
378 _Generic((1 ? ((void *) ((x) * (uintptr_t) 0)) : &(int) {1}), int *: 1, void *: 0)
379#define HAVE_PG_INTEGER_CONSTANT_P
398#if defined(USE_ASSERT_CHECKING)
399#define pg_assume(expr) Assert(expr)
400#elif defined(HAVE__BUILTIN_UNREACHABLE)
401#define pg_assume(expr) \
404 __builtin_unreachable(); \
406#elif defined(_MSC_VER)
407#define pg_assume(expr) __assume(expr)
409#define pg_assume(expr) ((void) 0)
420#define likely(x) __builtin_expect((x) != 0, 1)
421#define unlikely(x) __builtin_expect((x) != 0, 0)
423#define likely(x) ((x) != 0)
424#define unlikely(x) ((x) != 0)
437#if defined(__cplusplus)
439#define typeof(x) pg_cxx_typeof(x)
440#elif !defined(HAVE_CXX_TYPEOF)
441#define typeof(x) std::remove_reference_t<decltype(x)>
460#define CppAsString(identifier) #identifier
461#define CppAsString2(x) CppAsString(x)
462#define CppConcat(x, y) x##y
478#define VA_ARGS_NARGS(...) \
479 VA_ARGS_NARGS_(__VA_ARGS__, \
481 59,58,57,56,55,54,53,52,51,50, \
482 49,48,47,46,45,44,43,42,41,40, \
483 39,38,37,36,35,34,33,32,31,30, \
484 29,28,27,26,25,24,23,22,21,20, \
485 19,18,17,16,15,14,13,12,11,10, \
486 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
488#define VA_ARGS_NARGS_( \
489 _01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
490 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
491 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
492 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
493 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
494 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
495 _61,_62,_63, N, ...) \
513#define FLEXIBLE_ARRAY_MEMBER
540#define HAVE_PRAGMA_GCC_SYSTEM_HEADER 1
593#define INT64CONST(x) INT64_C(x)
594#define UINT64CONST(x) UINT64_C(x)
597#define INT64_FORMAT "%" PRId64
598#define UINT64_FORMAT "%" PRIu64
599#define OID8_FORMAT "%" PRIu64
609#if defined(PG_INT128_TYPE)
610#if defined(pg_attribute_aligned) || ALIGNOF_PG_INT128_TYPE <= MAXIMUM_ALIGNOF
614#if defined(pg_attribute_aligned)
620#if defined(pg_attribute_aligned)
629#define PG_INT8_MIN INT8_MIN
630#define PG_INT8_MAX INT8_MAX
631#define PG_UINT8_MAX UINT8_MAX
632#define PG_INT16_MIN INT16_MIN
633#define PG_INT16_MAX INT16_MAX
634#define PG_UINT16_MAX UINT16_MAX
635#define PG_INT32_MIN INT32_MIN
636#define PG_INT32_MAX INT32_MAX
637#define PG_UINT32_MAX UINT32_MAX
638#define PG_INT64_MIN INT64_MIN
639#define PG_INT64_MAX INT64_MAX
640#define PG_UINT64_MAX UINT64_MAX
646#define HAVE_INT64_TIMESTAMP
683#define FLOAT8PASSBYVAL true
705#define InvalidSubTransactionId ((SubTransactionId) 0)
706#define TopSubTransactionId ((SubTransactionId) 1)
715#define FirstCommandId ((CommandId) 0)
716#define InvalidCommandId (~(CommandId)0)
721#define InvalidOid8 ((Oid8) 0)
722#define OID8_MAX UINT64_MAX
744#define VARHDRSZ ((int32) sizeof(int32))
798#define NameStr(name) ((name).data)
809#define BoolIsValid(boolean) ((boolean) == false || (boolean) == true)
815#define PointerIsAligned(pointer, type) \
816 (((uintptr_t)(pointer) % (sizeof (type))) == 0)
818#define OffsetToPointer(base, offset) \
819 ((void *)((char *) base + offset))
821#define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
823#define Oid8IsValid(objectId) ((bool) ((objectId) != InvalidOid8))
825#define RegProcedureIsValid(p) OidIsValid(p)
836#define lengthof(array) (sizeof (array) / sizeof ((array)[0]))
852#define TYPEALIGN(ALIGNVAL,LEN) \
853 (((uintptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
855#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
856#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
857#define INT64ALIGN(LEN) TYPEALIGN(ALIGNOF_INT64_T, (LEN))
858#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
859#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
861#define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN))
862#define CACHELINEALIGN(LEN) TYPEALIGN(PG_CACHE_LINE_SIZE, (LEN))
864#define TYPEALIGN_DOWN(ALIGNVAL,LEN) \
865 (((uintptr_t) (LEN)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
867#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
868#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
869#define INT64ALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT64_T, (LEN))
870#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
871#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
872#define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN))
880#define TYPEALIGN64(ALIGNVAL,LEN) \
881 (((uint64) (LEN) + ((ALIGNVAL) - 1)) & ~((uint64) ((ALIGNVAL) - 1)))
884#define MAXALIGN64(LEN) TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
904#ifndef USE_ASSERT_CHECKING
906#define Assert(condition) ((void)true)
907#define AssertMacro(condition) ((void)true)
909#elif defined(FRONTEND)
911#define Assert(p) assert(p)
912#define AssertMacro(p) ((void) assert(p))
920#define Assert(condition) \
923 ExceptionalCondition(#condition, __FILE__, __LINE__); \
932#define AssertMacro(condition) \
933 ((void) ((condition) || \
934 (ExceptionalCondition(#condition, __FILE__, __LINE__), 0)))
941#define AssertPointerAlignment(ptr, bndr) \
942 Assert(TYPEALIGN(bndr, (uintptr_t)(ptr)) == (uintptr_t)(ptr))
971#define StaticAssertDecl(condition, errmessage) \
972 static_assert(condition, errmessage)
978#define StaticAssertStmt(condition, errmessage) \
979 do { static_assert(condition, errmessage); } while(0)
989#ifdef HAVE_STATEMENT_EXPRESSIONS
990#define StaticAssertExpr(condition, errmessage) \
991 ((void) ({ static_assert(condition, errmessage); true; }))
993#define StaticAssertExpr(condition, errmessage) \
994 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
1009#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
1010#define StaticAssertVariableIsOfType(varname, typename) \
1011 StaticAssertDecl(__builtin_types_compatible_p(__typeof__(varname), typename), \
1012 CppAsString(varname) " does not have type " CppAsString(typename))
1013#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
1014 (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
1015 CppAsString(varname) " does not have type " CppAsString(typename)))
1017#define StaticAssertVariableIsOfType(varname, typename) \
1018 StaticAssertDecl(sizeof(varname) == sizeof(typename), \
1019 CppAsString(varname) " does not have type " CppAsString(typename))
1020#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
1021 (StaticAssertExpr(sizeof(varname) == sizeof(typename), \
1022 CppAsString(varname) " does not have type " CppAsString(typename)))
1034#define Max(x, y) ((x) > (y) ? (x) : (y))
1040#define Min(x, y) ((x) < (y) ? (x) : (y))
1044#define SIZE_T_ALIGN_MASK (sizeof(size_t) - 1)
1056#define MemSet(start, val, len) \
1060 void *_vstart = (void *) (start); \
1062 Size _len = (len); \
1064 if ((((uintptr_t) _vstart) & SIZE_T_ALIGN_MASK) == 0 && \
1065 (_len & SIZE_T_ALIGN_MASK) == 0 && \
1067 _len <= MEMSET_LOOP_LIMIT && \
1072 MEMSET_LOOP_LIMIT != 0) \
1074 size_t *_start = (size_t *) _vstart; \
1075 size_t *_stop = (size_t *) ((char *) _start + _len); \
1076 while (_start < _stop) \
1080 memset(_vstart, _val, _len); \
1089#define MemSetAligned(start, val, len) \
1092 size_t *_start = (size_t *) (start); \
1094 Size _len = (len); \
1096 if ((_len & SIZE_T_ALIGN_MASK) == 0 && \
1098 _len <= MEMSET_LOOP_LIMIT && \
1099 MEMSET_LOOP_LIMIT != 0) \
1101 size_t *_stop = (size_t *) ((char *) _start + _len); \
1102 while (_start < _stop) \
1106 memset(_start, _val, _len); \
1121#define FLOAT4_FITS_IN_INT16(num) \
1122 ((num) >= (float4) PG_INT16_MIN && (num) < -((float4) PG_INT16_MIN))
1123#define FLOAT4_FITS_IN_INT32(num) \
1124 ((num) >= (float4) PG_INT32_MIN && (num) < -((float4) PG_INT32_MIN))
1125#define FLOAT4_FITS_IN_INT64(num) \
1126 ((num) >= (float4) PG_INT64_MIN && (num) < -((float4) PG_INT64_MIN))
1127#define FLOAT8_FITS_IN_INT16(num) \
1128 ((num) >= (float8) PG_INT16_MIN && (num) < -((float8) PG_INT16_MIN))
1129#define FLOAT8_FITS_IN_INT32(num) \
1130 ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))
1131#define FLOAT8_FITS_IN_INT64(num) \
1132 ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN))
1145#define INVERT_COMPARE_RESULT(var) \
1146 ((var) = ((var) < 0) ? 1 : -(var))
1165#if !(defined(__cplusplus) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 9)
1195#define HIGHBIT (0x80)
1196#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
1204#define SQL_STR_DOUBLE(ch, escape_backslash) \
1205 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
1207#define ESCAPE_STRING_SYNTAX 'E'
1210#define STATUS_OK (0)
1211#define STATUS_ERROR (-1)
1212#define STATUS_EOF (-2)
1220#define gettext(x) (x)
1221#define dgettext(d,x) (x)
1222#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
1223#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
1226#define _(x) gettext(x)
1237#define gettext_noop(x) (x)
1252#ifdef SO_MAJOR_VERSION
1253#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1255#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
1273#if defined(__cplusplus)
1274#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
1275#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
1276#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
1277#define unconstify(underlying_type, expr) \
1278 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
1280 (underlying_type) (expr))
1281#define unvolatize(underlying_type, expr) \
1282 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
1284 (underlying_type) (expr))
1286#define unconstify(underlying_type, expr) \
1287 ((underlying_type) (expr))
1288#define unvolatize(underlying_type, expr) \
1289 ((underlying_type) (expr))
1296#if (defined(__x86_64__) || defined(_M_AMD64))
1307#elif defined(__aarch64__) && defined(__ARM_NEON)
1327#if defined(WIN32) || defined(__CYGWIN__)
1328#define PG_BINARY O_BINARY
1329#define PG_BINARY_A "ab"
1330#define PG_BINARY_R "rb"
1331#define PG_BINARY_W "wb"
1334#define PG_BINARY_A "a"
1335#define PG_BINARY_R "r"
1336#define PG_BINARY_W "w"
1344#if !HAVE_DECL_FDATASYNC
1354#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))
1355#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base))
1356#elif SIZEOF_LONG_LONG == 8
1357#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base))
1358#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base))
1360#error "cannot find integer type of the same size as int64_t"
1367#define i64abs(i) ((int64) labs(i))
1368#elif SIZEOF_LONG_LONG == 8
1369#define i64abs(i) ((int64) llabs(i))
1371#error "cannot find integer type of the same size as int64_t"
1392#ifdef HAVE_VISIBILITY_ATTRIBUTE
1393#define PGDLLEXPORT __attribute__((visibility("default")))
1409#define SIGNAL_ARGS int postgres_signal_arg
1421#define sigsetjmp(x,y) __builtin_setjmp(x)
1422#define siglongjmp __builtin_longjmp
1424#define sigjmp_buf jmp_buf
1425#define sigsetjmp(x,y) setjmp(x)
1426#define siglongjmp longjmp
static Datum values[MAXATTR]
pg_noreturn void ExceptionalCondition(const char *conditionName, const char *fileName, int lineNumber)
TransactionId MultiXactId
#define FLEXIBLE_ARRAY_MEMBER
uint32 LocalTransactionId
void(* pg_funcptr_t)(void)
static int fd(const char *x, int i)
char vl_dat[FLEXIBLE_ARRAY_MEMBER]