59#include "pg_config_os.h"
74#if defined(WIN32) || defined(__CYGWIN__)
106#ifdef PG_FORCE_DISABLE_INLINE
125#ifndef __has_attribute
126#define __has_attribute(attribute) 0
131#define pg_attribute_unused() __attribute__((unused))
133#define pg_attribute_unused()
143#define pg_nodiscard __attribute__((warn_unused_result))
152#if defined(__clang__) || __GNUC__ >= 8
153#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize("address")))
154#elif __has_attribute(no_sanitize_address)
156#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize_address))
158#define pg_attribute_no_sanitize_address()
167#if __clang_major__ >= 7 || __GNUC__ >= 8
168#define pg_attribute_no_sanitize_alignment() __attribute__((no_sanitize("alignment")))
170#define pg_attribute_no_sanitize_alignment()
178#if __has_attribute (nonnull)
179#define pg_attribute_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
181#define pg_attribute_nonnull(...)
190#if __has_attribute (target)
191#define pg_attribute_target(...) __attribute__((target(__VA_ARGS__)))
193#define pg_attribute_target(...)
201#ifdef USE_ASSERT_CHECKING
202#define PG_USED_FOR_ASSERTS_ONLY
204#define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
209#define pg_attribute_format_arg(a) __attribute__((format_arg(a)))
210#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
212#define pg_attribute_format_arg(a)
213#define pg_attribute_printf(f,a)
217#if defined(__GNUC__) || defined(__SUNPRO_C)
218#define pg_attribute_aligned(a) __attribute__((aligned(a)))
219#define pg_attribute_noreturn() __attribute__((noreturn))
220#define pg_attribute_packed() __attribute__((packed))
221#define HAVE_PG_ATTRIBUTE_NORETURN 1
222#elif defined(_MSC_VER)
231#define pg_attribute_aligned(a) __declspec(align(a))
232#define pg_attribute_noreturn()
239#define pg_attribute_noreturn()
248#if (defined(__GNUC__) && __GNUC__ > 3 && defined(__OPTIMIZE__)) || defined(__SUNPRO_C)
250#define pg_attribute_always_inline __attribute__((always_inline)) inline
251#elif defined(_MSC_VER)
253#define pg_attribute_always_inline __forceinline
256#define pg_attribute_always_inline inline
266#if (defined(__GNUC__) && __GNUC__ > 2) || defined(__SUNPRO_C)
267#define pg_noinline __attribute__((noinline))
269#elif defined(_MSC_VER)
270#define pg_noinline __declspec(noinline)
284#if defined(__MINGW64__) && __GNUC__ == 8 && __GNUC_MINOR__ == 1
286#define pg_attribute_cold
287#define pg_attribute_hot
294#if __has_attribute (cold)
295#define pg_attribute_cold __attribute__((cold))
297#define pg_attribute_cold
300#if __has_attribute (hot)
301#define pg_attribute_hot __attribute__((hot))
303#define pg_attribute_hot
313#if defined(HAVE__BUILTIN_UNREACHABLE) && !defined(USE_ASSERT_CHECKING)
314#define pg_unreachable() __builtin_unreachable()
315#elif defined(_MSC_VER) && !defined(USE_ASSERT_CHECKING)
316#define pg_unreachable() __assume(0)
318#define pg_unreachable() abort()
329#define likely(x) __builtin_expect((x) != 0, 1)
330#define unlikely(x) __builtin_expect((x) != 0, 0)
332#define likely(x) ((x) != 0)
333#define unlikely(x) ((x) != 0)
348#define CppAsString(identifier) #identifier
349#define CppAsString2(x) CppAsString(x)
350#define CppConcat(x, y) x##y
372#define EXPAND(args) args
373#define VA_ARGS_NARGS(...) \
374 VA_ARGS_NARGS_ EXPAND((__VA_ARGS__, \
376 59,58,57,56,55,54,53,52,51,50, \
377 49,48,47,46,45,44,43,42,41,40, \
378 39,38,37,36,35,34,33,32,31,30, \
379 29,28,27,26,25,24,23,22,21,20, \
380 19,18,17,16,15,14,13,12,11,10, \
381 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
384#define VA_ARGS_NARGS(...) \
385 VA_ARGS_NARGS_(__VA_ARGS__, \
387 59,58,57,56,55,54,53,52,51,50, \
388 49,48,47,46,45,44,43,42,41,40, \
389 39,38,37,36,35,34,33,32,31,30, \
390 29,28,27,26,25,24,23,22,21,20, \
391 19,18,17,16,15,14,13,12,11,10, \
392 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
395#define VA_ARGS_NARGS_( \
396 _01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
397 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
398 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
399 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
400 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
401 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
402 _61,_62,_63, N, ...) \
420#define FLEXIBLE_ARRAY_MEMBER
447#define HAVE_PRAGMA_GCC_SYSTEM_HEADER 1
502#define INT64CONST(x) INT64_C(x)
503#define UINT64CONST(x) UINT64_C(x)
506#define INT64_FORMAT "%" PRId64
507#define UINT64_FORMAT "%" PRIu64
508#define INT64_HEX_FORMAT "%" PRIx64
509#define UINT64_HEX_FORMAT "%" PRIx64
519#if defined(PG_INT128_TYPE)
520#if defined(pg_attribute_aligned) || ALIGNOF_PG_INT128_TYPE <= MAXIMUM_ALIGNOF
523typedef PG_INT128_TYPE int128
524#if defined(pg_attribute_aligned)
529typedef unsigned PG_INT128_TYPE uint128
530#if defined(pg_attribute_aligned)
539#define PG_INT8_MIN INT8_MIN
540#define PG_INT8_MAX INT8_MAX
541#define PG_UINT8_MAX UINT8_MAX
542#define PG_INT16_MIN INT16_MIN
543#define PG_INT16_MAX INT16_MAX
544#define PG_UINT16_MAX UINT16_MAX
545#define PG_INT32_MIN INT32_MIN
546#define PG_INT32_MAX INT32_MAX
547#define PG_UINT32_MAX UINT32_MAX
548#define PG_INT64_MIN INT64_MIN
549#define PG_INT64_MAX INT64_MAX
550#define PG_UINT64_MAX UINT64_MAX
556#define HAVE_INT64_TIMESTAMP
589#ifdef USE_FLOAT8_BYVAL
590#define FLOAT8PASSBYVAL true
592#define FLOAT8PASSBYVAL false
615#define InvalidSubTransactionId ((SubTransactionId) 0)
616#define TopSubTransactionId ((SubTransactionId) 1)
625#define FirstCommandId ((CommandId) 0)
626#define InvalidCommandId (~(CommandId)0)
649#define VARHDRSZ ((int32) sizeof(int32))
703#define NameStr(name) ((name).data)
714#define BoolIsValid(boolean) ((boolean) == false || (boolean) == true)
720#define PointerIsValid(pointer) ((const void*)(pointer) != NULL)
726#define PointerIsAligned(pointer, type) \
727 (((uintptr_t)(pointer) % (sizeof (type))) == 0)
729#define OffsetToPointer(base, offset) \
730 ((void *)((char *) base + offset))
732#define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
734#define RegProcedureIsValid(p) OidIsValid(p)
745#define lengthof(array) (sizeof (array) / sizeof ((array)[0]))
761#define TYPEALIGN(ALIGNVAL,LEN) \
762 (((uintptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
764#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
765#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
766#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
767#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
768#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
770#define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN))
771#define CACHELINEALIGN(LEN) TYPEALIGN(PG_CACHE_LINE_SIZE, (LEN))
773#define TYPEALIGN_DOWN(ALIGNVAL,LEN) \
774 (((uintptr_t) (LEN)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
776#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
777#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
778#define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
779#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
780#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
781#define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN))
789#define TYPEALIGN64(ALIGNVAL,LEN) \
790 (((uint64) (LEN) + ((ALIGNVAL) - 1)) & ~((uint64) ((ALIGNVAL) - 1)))
793#define MAXALIGN64(LEN) TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
813#ifndef USE_ASSERT_CHECKING
815#define Assert(condition) ((void)true)
816#define AssertMacro(condition) ((void)true)
818#elif defined(FRONTEND)
821#define Assert(p) assert(p)
822#define AssertMacro(p) ((void) assert(p))
830#define Assert(condition) \
833 ExceptionalCondition(#condition, __FILE__, __LINE__); \
842#define AssertMacro(condition) \
843 ((void) ((condition) || \
844 (ExceptionalCondition(#condition, __FILE__, __LINE__), 0)))
851#define AssertPointerAlignment(ptr, bndr) \
852 Assert(TYPEALIGN(bndr, (uintptr_t)(ptr)) == (uintptr_t)(ptr))
885#ifdef HAVE__STATIC_ASSERT
886#define StaticAssertDecl(condition, errmessage) \
887 _Static_assert(condition, errmessage)
888#define StaticAssertStmt(condition, errmessage) \
889 do { _Static_assert(condition, errmessage); } while(0)
890#define StaticAssertExpr(condition, errmessage) \
891 ((void) ({ StaticAssertStmt(condition, errmessage); true; }))
893#define StaticAssertDecl(condition, errmessage) \
894 extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1])
895#define StaticAssertStmt(condition, errmessage) \
896 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
897#define StaticAssertExpr(condition, errmessage) \
898 StaticAssertStmt(condition, errmessage)
901#if defined(__cpp_static_assert) && __cpp_static_assert >= 200410
902#define StaticAssertDecl(condition, errmessage) \
903 static_assert(condition, errmessage)
904#define StaticAssertStmt(condition, errmessage) \
905 static_assert(condition, errmessage)
906#define StaticAssertExpr(condition, errmessage) \
907 ({ static_assert(condition, errmessage); })
909#define StaticAssertDecl(condition, errmessage) \
910 extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1])
911#define StaticAssertStmt(condition, errmessage) \
912 do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0)
913#define StaticAssertExpr(condition, errmessage) \
914 ((void) ({ StaticAssertStmt(condition, errmessage); }))
930#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
931#define AssertVariableIsOfType(varname, typename) \
932 StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
933 CppAsString(varname) " does not have type " CppAsString(typename))
934#define AssertVariableIsOfTypeMacro(varname, typename) \
935 (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
936 CppAsString(varname) " does not have type " CppAsString(typename)))
938#define AssertVariableIsOfType(varname, typename) \
939 StaticAssertStmt(sizeof(varname) == sizeof(typename), \
940 CppAsString(varname) " does not have type " CppAsString(typename))
941#define AssertVariableIsOfTypeMacro(varname, typename) \
942 (StaticAssertExpr(sizeof(varname) == sizeof(typename), \
943 CppAsString(varname) " does not have type " CppAsString(typename)))
955#define Max(x, y) ((x) > (y) ? (x) : (y))
961#define Min(x, y) ((x) < (y) ? (x) : (y))
965#define LONG_ALIGN_MASK (sizeof(long) - 1)
977#define MemSet(start, val, len) \
981 void *_vstart = (void *) (start); \
985 if ((((uintptr_t) _vstart) & LONG_ALIGN_MASK) == 0 && \
986 (_len & LONG_ALIGN_MASK) == 0 && \
988 _len <= MEMSET_LOOP_LIMIT && \
993 MEMSET_LOOP_LIMIT != 0) \
995 long *_start = (long *) _vstart; \
996 long *_stop = (long *) ((char *) _start + _len); \
997 while (_start < _stop) \
1001 memset(_vstart, _val, _len); \
1010#define MemSetAligned(start, val, len) \
1013 long *_start = (long *) (start); \
1015 Size _len = (len); \
1017 if ((_len & LONG_ALIGN_MASK) == 0 && \
1019 _len <= MEMSET_LOOP_LIMIT && \
1020 MEMSET_LOOP_LIMIT != 0) \
1022 long *_stop = (long *) ((char *) _start + _len); \
1023 while (_start < _stop) \
1027 memset(_start, _val, _len); \
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))
1066#define INVERT_COMPARE_RESULT(var) \
1067 ((var) = ((var) < 0) ? 1 : -(var))
1094#ifdef pg_attribute_aligned
1105#ifdef pg_attribute_aligned
1114#define HIGHBIT (0x80)
1115#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
1123#define SQL_STR_DOUBLE(ch, escape_backslash) \
1124 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
1126#define ESCAPE_STRING_SYNTAX 'E'
1129#define STATUS_OK (0)
1130#define STATUS_ERROR (-1)
1131#define STATUS_EOF (-2)
1139#define gettext(x) (x)
1140#define dgettext(d,x) (x)
1141#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
1142#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
1145#define _(x) gettext(x)
1156#define gettext_noop(x) (x)
1171#ifdef SO_MAJOR_VERSION
1172#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1174#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
1192#if defined(__cplusplus)
1193#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
1194#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
1195#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
1196#define unconstify(underlying_type, expr) \
1197 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
1199 (underlying_type) (expr))
1200#define unvolatize(underlying_type, expr) \
1201 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
1203 (underlying_type) (expr))
1205#define unconstify(underlying_type, expr) \
1206 ((underlying_type) (expr))
1207#define unvolatize(underlying_type, expr) \
1208 ((underlying_type) (expr))
1227#if defined(WIN32) || defined(__CYGWIN__)
1228#define PG_BINARY O_BINARY
1229#define PG_BINARY_A "ab"
1230#define PG_BINARY_R "rb"
1231#define PG_BINARY_W "wb"
1234#define PG_BINARY_A "a"
1235#define PG_BINARY_R "r"
1236#define PG_BINARY_W "w"
1244#if !HAVE_DECL_FDATASYNC
1254#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))
1255#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base))
1256#elif SIZEOF_LONG_LONG == 8
1257#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base))
1258#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base))
1260#error "cannot find integer type of the same size as int64_t"
1267#define i64abs(i) labs(i)
1268#elif SIZEOF_LONG_LONG == 8
1269#define i64abs(i) llabs(i)
1271#error "cannot find integer type of the same size as int64_t"
1292#ifdef HAVE_VISIBILITY_ATTRIBUTE
1293#define PGDLLEXPORT __attribute__((visibility("default")))
1309#define SIGNAL_ARGS int postgres_signal_arg
1320typedef intptr_t sigjmp_buf[5];
1321#define sigsetjmp(x,y) __builtin_setjmp(x)
1322#define siglongjmp __builtin_longjmp
1324#define sigjmp_buf jmp_buf
1325#define sigsetjmp(x,y) setjmp(x)
1326#define siglongjmp longjmp
static Datum values[MAXATTR]
union PGAlignedBlock PGAlignedBlock
union PGAlignedXLogBlock PGAlignedXLogBlock
#define pg_attribute_noreturn()
TransactionId MultiXactId
#define FLEXIBLE_ARRAY_MEMBER
uint32 LocalTransactionId
union PGIOAlignedBlock PGIOAlignedBlock
int fdatasync(int fildes)
void ExceptionalCondition(const char *conditionName, const char *fileName, int lineNumber) pg_attribute_noreturn()
void(* pg_funcptr_t)(void)
struct pg_attribute_aligned(8) pg_atomic_uint64
char vl_dat[FLEXIBLE_ARRAY_MEMBER]