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()
142#define pg_nodiscard __attribute__((warn_unused_result))
157#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) && !defined(__cplusplus)
158#define pg_noreturn _Noreturn
159#elif defined(__GNUC__)
160#define pg_noreturn __attribute__((noreturn))
161#elif defined(_MSC_VER)
162#define pg_noreturn __declspec(noreturn)
171#if defined(__clang__) || __GNUC__ >= 8
172#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize("address")))
173#elif __has_attribute(no_sanitize_address)
175#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize_address))
177#define pg_attribute_no_sanitize_address()
186#if __clang_major__ >= 7 || __GNUC__ >= 8
187#define pg_attribute_no_sanitize_alignment() __attribute__((no_sanitize("alignment")))
189#define pg_attribute_no_sanitize_alignment()
197#if __has_attribute (nonnull)
198#define pg_attribute_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
200#define pg_attribute_nonnull(...)
209#if __has_attribute (target)
210#define pg_attribute_target(...) __attribute__((target(__VA_ARGS__)))
212#define pg_attribute_target(...)
220#ifdef USE_ASSERT_CHECKING
221#define PG_USED_FOR_ASSERTS_ONLY
223#define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
231#define PG_PRINTF_ATTRIBUTE PG_C_PRINTF_ATTRIBUTE
233#define PG_PRINTF_ATTRIBUTE PG_CXX_PRINTF_ATTRIBUTE
238#define pg_attribute_format_arg(a) __attribute__((format_arg(a)))
239#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
241#define pg_attribute_format_arg(a)
242#define pg_attribute_printf(f,a)
247#define pg_attribute_aligned(a) __attribute__((aligned(a)))
248#define pg_attribute_packed() __attribute__((packed))
249#elif defined(_MSC_VER)
256#define pg_attribute_aligned(a) __declspec(align(a))
271#if defined(__GNUC__) && defined(__OPTIMIZE__)
273#define pg_attribute_always_inline __attribute__((always_inline)) inline
274#elif defined(_MSC_VER)
276#define pg_attribute_always_inline __forceinline
279#define pg_attribute_always_inline inline
290#define pg_noinline __attribute__((noinline))
292#elif defined(_MSC_VER)
293#define pg_noinline __declspec(noinline)
307#if defined(__MINGW64__) && __GNUC__ == 8 && __GNUC_MINOR__ == 1
309#define pg_attribute_cold
310#define pg_attribute_hot
317#if __has_attribute (cold)
318#define pg_attribute_cold __attribute__((cold))
320#define pg_attribute_cold
323#if __has_attribute (hot)
324#define pg_attribute_hot __attribute__((hot))
326#define pg_attribute_hot
336#if defined(HAVE__BUILTIN_UNREACHABLE) && !defined(USE_ASSERT_CHECKING)
337#define pg_unreachable() __builtin_unreachable()
338#elif defined(_MSC_VER) && !defined(USE_ASSERT_CHECKING)
339#define pg_unreachable() __assume(0)
341#define pg_unreachable() abort()
351#if defined(HAVE__BUILTIN_CONSTANT_P)
354#define pg_integer_constant_p(x) __builtin_constant_p(x)
355#define HAVE_PG_INTEGER_CONSTANT_P
356#elif defined(_MSC_VER) && defined(__STDC_VERSION__)
365#define pg_integer_constant_p(x) \
366 _Generic((1 ? ((void *) ((x) * (uintptr_t) 0)) : &(int) {1}), int *: 1, void *: 0)
367#define HAVE_PG_INTEGER_CONSTANT_P
386#if defined(USE_ASSERT_CHECKING)
387#define pg_assume(expr) Assert(expr)
388#elif defined(HAVE__BUILTIN_UNREACHABLE)
389#define pg_assume(expr) \
392 __builtin_unreachable(); \
394#elif defined(_MSC_VER)
395#define pg_assume(expr) __assume(expr)
397#define pg_assume(expr) ((void) 0)
408#define likely(x) __builtin_expect((x) != 0, 1)
409#define unlikely(x) __builtin_expect((x) != 0, 0)
411#define likely(x) ((x) != 0)
412#define unlikely(x) ((x) != 0)
427#define CppAsString(identifier) #identifier
428#define CppAsString2(x) CppAsString(x)
429#define CppConcat(x, y) x##y
445#define VA_ARGS_NARGS(...) \
446 VA_ARGS_NARGS_(__VA_ARGS__, \
448 59,58,57,56,55,54,53,52,51,50, \
449 49,48,47,46,45,44,43,42,41,40, \
450 39,38,37,36,35,34,33,32,31,30, \
451 29,28,27,26,25,24,23,22,21,20, \
452 19,18,17,16,15,14,13,12,11,10, \
453 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
455#define VA_ARGS_NARGS_( \
456 _01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
457 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
458 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
459 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
460 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
461 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
462 _61,_62,_63, N, ...) \
480#define FLEXIBLE_ARRAY_MEMBER
507#define HAVE_PRAGMA_GCC_SYSTEM_HEADER 1
560#define INT64CONST(x) INT64_C(x)
561#define UINT64CONST(x) UINT64_C(x)
564#define INT64_FORMAT "%" PRId64
565#define UINT64_FORMAT "%" PRIu64
566#define OID8_FORMAT "%" PRIu64
576#if defined(PG_INT128_TYPE)
577#if defined(pg_attribute_aligned) || ALIGNOF_PG_INT128_TYPE <= MAXIMUM_ALIGNOF
581#if defined(pg_attribute_aligned)
587#if defined(pg_attribute_aligned)
596#define PG_INT8_MIN INT8_MIN
597#define PG_INT8_MAX INT8_MAX
598#define PG_UINT8_MAX UINT8_MAX
599#define PG_INT16_MIN INT16_MIN
600#define PG_INT16_MAX INT16_MAX
601#define PG_UINT16_MAX UINT16_MAX
602#define PG_INT32_MIN INT32_MIN
603#define PG_INT32_MAX INT32_MAX
604#define PG_UINT32_MAX UINT32_MAX
605#define PG_INT64_MIN INT64_MIN
606#define PG_INT64_MAX INT64_MAX
607#define PG_UINT64_MAX UINT64_MAX
613#define HAVE_INT64_TIMESTAMP
650#define FLOAT8PASSBYVAL true
672#define InvalidSubTransactionId ((SubTransactionId) 0)
673#define TopSubTransactionId ((SubTransactionId) 1)
682#define FirstCommandId ((CommandId) 0)
683#define InvalidCommandId (~(CommandId)0)
688#define InvalidOid8 ((Oid8) 0)
689#define OID8_MAX UINT64_MAX
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 Oid8IsValid(objectId) ((bool) ((objectId) != InvalidOid8))
792#define RegProcedureIsValid(p) OidIsValid(p)
803#define lengthof(array) (sizeof (array) / sizeof ((array)[0]))
819#define TYPEALIGN(ALIGNVAL,LEN) \
820 (((uintptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
822#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
823#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
824#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
825#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
826#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
828#define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN))
829#define CACHELINEALIGN(LEN) TYPEALIGN(PG_CACHE_LINE_SIZE, (LEN))
831#define TYPEALIGN_DOWN(ALIGNVAL,LEN) \
832 (((uintptr_t) (LEN)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
834#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
835#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
836#define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
837#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
838#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
839#define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN))
847#define TYPEALIGN64(ALIGNVAL,LEN) \
848 (((uint64) (LEN) + ((ALIGNVAL) - 1)) & ~((uint64) ((ALIGNVAL) - 1)))
851#define MAXALIGN64(LEN) TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
871#ifndef USE_ASSERT_CHECKING
873#define Assert(condition) ((void)true)
874#define AssertMacro(condition) ((void)true)
876#elif defined(FRONTEND)
878#define Assert(p) assert(p)
879#define AssertMacro(p) ((void) assert(p))
887#define Assert(condition) \
890 ExceptionalCondition(#condition, __FILE__, __LINE__); \
899#define AssertMacro(condition) \
900 ((void) ((condition) || \
901 (ExceptionalCondition(#condition, __FILE__, __LINE__), 0)))
908#define AssertPointerAlignment(ptr, bndr) \
909 Assert(TYPEALIGN(bndr, (uintptr_t)(ptr)) == (uintptr_t)(ptr))
942#define StaticAssertDecl(condition, errmessage) \
943 static_assert(condition, errmessage)
944#define StaticAssertStmt(condition, errmessage) \
945 do { static_assert(condition, errmessage); } while(0)
946#ifdef HAVE_STATEMENT_EXPRESSIONS
947#define StaticAssertExpr(condition, errmessage) \
948 ((void) ({ static_assert(condition, errmessage); true; }))
950#define StaticAssertExpr(condition, errmessage) \
951 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
966#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
967#define StaticAssertVariableIsOfType(varname, typename) \
968 StaticAssertDecl(__builtin_types_compatible_p(__typeof__(varname), typename), \
969 CppAsString(varname) " does not have type " CppAsString(typename))
970#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
971 (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
972 CppAsString(varname) " does not have type " CppAsString(typename)))
974#define StaticAssertVariableIsOfType(varname, typename) \
975 StaticAssertDecl(sizeof(varname) == sizeof(typename), \
976 CppAsString(varname) " does not have type " CppAsString(typename))
977#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
978 (StaticAssertExpr(sizeof(varname) == sizeof(typename), \
979 CppAsString(varname) " does not have type " CppAsString(typename)))
991#define Max(x, y) ((x) > (y) ? (x) : (y))
997#define Min(x, y) ((x) < (y) ? (x) : (y))
1001#define SIZE_T_ALIGN_MASK (sizeof(size_t) - 1)
1013#define MemSet(start, val, len) \
1017 void *_vstart = (void *) (start); \
1019 Size _len = (len); \
1021 if ((((uintptr_t) _vstart) & SIZE_T_ALIGN_MASK) == 0 && \
1022 (_len & SIZE_T_ALIGN_MASK) == 0 && \
1024 _len <= MEMSET_LOOP_LIMIT && \
1029 MEMSET_LOOP_LIMIT != 0) \
1031 size_t *_start = (size_t *) _vstart; \
1032 size_t *_stop = (size_t *) ((char *) _start + _len); \
1033 while (_start < _stop) \
1037 memset(_vstart, _val, _len); \
1046#define MemSetAligned(start, val, len) \
1049 size_t *_start = (size_t *) (start); \
1051 Size _len = (len); \
1053 if ((_len & SIZE_T_ALIGN_MASK) == 0 && \
1055 _len <= MEMSET_LOOP_LIMIT && \
1056 MEMSET_LOOP_LIMIT != 0) \
1058 size_t *_stop = (size_t *) ((char *) _start + _len); \
1059 while (_start < _stop) \
1063 memset(_start, _val, _len); \
1078#define FLOAT4_FITS_IN_INT16(num) \
1079 ((num) >= (float4) PG_INT16_MIN && (num) < -((float4) PG_INT16_MIN))
1080#define FLOAT4_FITS_IN_INT32(num) \
1081 ((num) >= (float4) PG_INT32_MIN && (num) < -((float4) PG_INT32_MIN))
1082#define FLOAT4_FITS_IN_INT64(num) \
1083 ((num) >= (float4) PG_INT64_MIN && (num) < -((float4) PG_INT64_MIN))
1084#define FLOAT8_FITS_IN_INT16(num) \
1085 ((num) >= (float8) PG_INT16_MIN && (num) < -((float8) PG_INT16_MIN))
1086#define FLOAT8_FITS_IN_INT32(num) \
1087 ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))
1088#define FLOAT8_FITS_IN_INT64(num) \
1089 ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN))
1102#define INVERT_COMPARE_RESULT(var) \
1103 ((var) = ((var) < 0) ? 1 : -(var))
1122#if !(defined(__cplusplus) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 9)
1152#define HIGHBIT (0x80)
1153#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
1161#define SQL_STR_DOUBLE(ch, escape_backslash) \
1162 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
1164#define ESCAPE_STRING_SYNTAX 'E'
1167#define STATUS_OK (0)
1168#define STATUS_ERROR (-1)
1169#define STATUS_EOF (-2)
1177#define gettext(x) (x)
1178#define dgettext(d,x) (x)
1179#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
1180#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
1183#define _(x) gettext(x)
1194#define gettext_noop(x) (x)
1209#ifdef SO_MAJOR_VERSION
1210#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1212#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
1230#if defined(__cplusplus)
1231#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
1232#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
1233#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
1234#define unconstify(underlying_type, expr) \
1235 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
1237 (underlying_type) (expr))
1238#define unvolatize(underlying_type, expr) \
1239 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
1241 (underlying_type) (expr))
1243#define unconstify(underlying_type, expr) \
1244 ((underlying_type) (expr))
1245#define unvolatize(underlying_type, expr) \
1246 ((underlying_type) (expr))
1253#if (defined(__x86_64__) || defined(_M_AMD64))
1264#elif defined(__aarch64__) && defined(__ARM_NEON)
1284#if defined(WIN32) || defined(__CYGWIN__)
1285#define PG_BINARY O_BINARY
1286#define PG_BINARY_A "ab"
1287#define PG_BINARY_R "rb"
1288#define PG_BINARY_W "wb"
1291#define PG_BINARY_A "a"
1292#define PG_BINARY_R "r"
1293#define PG_BINARY_W "w"
1301#if !HAVE_DECL_FDATASYNC
1311#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))
1312#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base))
1313#elif SIZEOF_LONG_LONG == 8
1314#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base))
1315#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base))
1317#error "cannot find integer type of the same size as int64_t"
1324#define i64abs(i) ((int64) labs(i))
1325#elif SIZEOF_LONG_LONG == 8
1326#define i64abs(i) ((int64) llabs(i))
1328#error "cannot find integer type of the same size as int64_t"
1349#ifdef HAVE_VISIBILITY_ATTRIBUTE
1350#define PGDLLEXPORT __attribute__((visibility("default")))
1366#define SIGNAL_ARGS int postgres_signal_arg
1378#define sigsetjmp(x,y) __builtin_setjmp(x)
1379#define siglongjmp __builtin_longjmp
1381#define sigjmp_buf jmp_buf
1382#define sigsetjmp(x,y) setjmp(x)
1383#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]