59#include "pg_config_os.h"
76#if defined(WIN32) || defined(__CYGWIN__)
114#ifdef PG_FORCE_DISABLE_INLINE
137#ifndef __has_attribute
138#define __has_attribute(attribute) 0
144#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || (defined(__cplusplus) && __cplusplus >= 201703L)
145#define pg_attribute_unused() [[maybe_unused]]
146#elif defined(__GNUC__)
147#define pg_attribute_unused() __attribute__((unused))
149#define pg_attribute_unused()
156#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || (defined(__cplusplus) && __cplusplus >= 201703L)
157#define pg_fallthrough [[fallthrough]]
158#elif __has_attribute(fallthrough)
159#define pg_fallthrough __attribute__((fallthrough))
161#define pg_fallthrough
168#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || (defined(__cplusplus) && __cplusplus >= 201703L)
169#define pg_nodiscard [[nodiscard]]
170#elif defined(__GNUC__)
171#define pg_nodiscard __attribute__((warn_unused_result))
187#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || defined(__cplusplus)
188#define pg_noreturn [[noreturn]]
190#define pg_noreturn _Noreturn
197#if defined(__clang__) || __GNUC__ >= 8
198#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize("address")))
199#elif __has_attribute(no_sanitize_address)
201#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize_address))
203#define pg_attribute_no_sanitize_address()
212#if __clang_major__ >= 7 || __GNUC__ >= 8
213#define pg_attribute_no_sanitize_alignment() __attribute__((no_sanitize("alignment")))
215#define pg_attribute_no_sanitize_alignment()
223#if __has_attribute (nonnull)
224#define pg_attribute_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
226#define pg_attribute_nonnull(...)
235#if __has_attribute (target)
236#define pg_attribute_target(...) __attribute__((target(__VA_ARGS__)))
238#define pg_attribute_target(...)
246#ifdef USE_ASSERT_CHECKING
247#define PG_USED_FOR_ASSERTS_ONLY
249#define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
257#define PG_PRINTF_ATTRIBUTE PG_C_PRINTF_ATTRIBUTE
259#define PG_PRINTF_ATTRIBUTE PG_CXX_PRINTF_ATTRIBUTE
264#define pg_attribute_format_arg(a) __attribute__((format_arg(a)))
265#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
267#define pg_attribute_format_arg(a)
268#define pg_attribute_printf(f,a)
273#define pg_attribute_aligned(a) __attribute__((aligned(a)))
274#define pg_attribute_packed() __attribute__((packed))
275#elif defined(_MSC_VER)
282#define pg_attribute_aligned(a) __declspec(align(a))
297#if defined(__GNUC__) && defined(__OPTIMIZE__)
299#define pg_attribute_always_inline __attribute__((always_inline)) inline
300#elif defined(_MSC_VER)
302#define pg_attribute_always_inline __forceinline
305#define pg_attribute_always_inline inline
316#define pg_noinline __attribute__((noinline))
318#elif defined(_MSC_VER)
319#define pg_noinline __declspec(noinline)
333#if defined(__MINGW64__) && __GNUC__ == 8 && __GNUC_MINOR__ == 1
335#define pg_attribute_cold
336#define pg_attribute_hot
343#if __has_attribute (cold)
344#define pg_attribute_cold __attribute__((cold))
346#define pg_attribute_cold
349#if __has_attribute (hot)
350#define pg_attribute_hot __attribute__((hot))
352#define pg_attribute_hot
362#if defined(HAVE__BUILTIN_UNREACHABLE) && !defined(USE_ASSERT_CHECKING)
363#define pg_unreachable() __builtin_unreachable()
364#elif defined(_MSC_VER) && !defined(USE_ASSERT_CHECKING)
365#define pg_unreachable() __assume(0)
367#define pg_unreachable() abort()
377#if defined(HAVE__BUILTIN_CONSTANT_P)
380#define pg_integer_constant_p(x) __builtin_constant_p(x)
381#define HAVE_PG_INTEGER_CONSTANT_P
382#elif defined(_MSC_VER) && defined(__STDC_VERSION__)
391#define pg_integer_constant_p(x) \
392 _Generic((1 ? ((void *) ((x) * (uintptr_t) 0)) : &(int) {1}), int *: 1, void *: 0)
393#define HAVE_PG_INTEGER_CONSTANT_P
412#if defined(USE_ASSERT_CHECKING)
413#define pg_assume(expr) Assert(expr)
414#elif defined(HAVE__BUILTIN_UNREACHABLE)
415#define pg_assume(expr) \
418 __builtin_unreachable(); \
420#elif defined(_MSC_VER)
421#define pg_assume(expr) __assume(expr)
423#define pg_assume(expr) ((void) 0)
434#define likely(x) __builtin_expect((x) != 0, 1)
435#define unlikely(x) __builtin_expect((x) != 0, 0)
437#define likely(x) ((x) != 0)
438#define unlikely(x) ((x) != 0)
450#if defined(__clang__)
451#if __clang_major__ < 19
452#undef HAVE_TYPEOF_UNQUAL
455#define typeof_unqual __typeof_unqual__
469#if defined(__cplusplus)
472#define typeof(x) pg_cxx_typeof(x)
473#elif !defined(HAVE_CXX_TYPEOF)
474#define typeof(x) std::remove_reference<decltype(x)>::type
483#ifdef pg_cxx_typeof_unqual
484#define typeof_unqual(x) pg_cxx_typeof_unqual(x)
485#elif !defined(HAVE_CXX_TYPEOF_UNQUAL)
486#define typeof_unqual(x) std::remove_cv<std::remove_reference<decltype(x)>::type>::type
488#ifndef HAVE_TYPEOF_UNQUAL
489#define HAVE_TYPEOF_UNQUAL 1
505#define CppAsString(identifier) #identifier
506#define CppAsString2(x) CppAsString(x)
507#define CppConcat(x, y) x##y
523#define VA_ARGS_NARGS(...) \
524 VA_ARGS_NARGS_(__VA_ARGS__, \
526 59,58,57,56,55,54,53,52,51,50, \
527 49,48,47,46,45,44,43,42,41,40, \
528 39,38,37,36,35,34,33,32,31,30, \
529 29,28,27,26,25,24,23,22,21,20, \
530 19,18,17,16,15,14,13,12,11,10, \
531 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
533#define VA_ARGS_NARGS_( \
534 _01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
535 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
536 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
537 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
538 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
539 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
540 _61,_62,_63, N, ...) \
558#define FLEXIBLE_ARRAY_MEMBER
585#define HAVE_PRAGMA_GCC_SYSTEM_HEADER 1
630#define INT64CONST(x) INT64_C(x)
631#define UINT64CONST(x) UINT64_C(x)
634#define INT64_FORMAT "%" PRId64
635#define UINT64_FORMAT "%" PRIu64
636#define OID8_FORMAT "%" PRIu64
646#if defined(PG_INT128_TYPE)
647#if defined(pg_attribute_aligned) || ALIGNOF_PG_INT128_TYPE <= MAXIMUM_ALIGNOF
651#if defined(pg_attribute_aligned)
657#if defined(pg_attribute_aligned)
666#define PG_INT8_MIN INT8_MIN
667#define PG_INT8_MAX INT8_MAX
668#define PG_UINT8_MAX UINT8_MAX
669#define PG_INT16_MIN INT16_MIN
670#define PG_INT16_MAX INT16_MAX
671#define PG_UINT16_MAX UINT16_MAX
672#define PG_INT32_MIN INT32_MIN
673#define PG_INT32_MAX INT32_MAX
674#define PG_UINT32_MAX UINT32_MAX
675#define PG_INT64_MIN INT64_MIN
676#define PG_INT64_MAX INT64_MAX
677#define PG_UINT64_MAX UINT64_MAX
683#define HAVE_INT64_TIMESTAMP
720#define FLOAT8PASSBYVAL true
742#define InvalidSubTransactionId ((SubTransactionId) 0)
743#define TopSubTransactionId ((SubTransactionId) 1)
752#define FirstCommandId ((CommandId) 0)
753#define InvalidCommandId (~(CommandId)0)
758#define InvalidOid8 ((Oid8) 0)
759#define OID8_MAX UINT64_MAX
781#define VARHDRSZ ((int32) sizeof(int32))
835#define NameStr(name) ((name).data)
846#define BoolIsValid(boolean) ((boolean) == false || (boolean) == true)
852#define PointerIsAligned(pointer, type) \
853 (((uintptr_t)(pointer) % (sizeof (type))) == 0)
855#define OffsetToPointer(base, offset) \
856 ((void *)((char *) base + offset))
858#define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
860#define Oid8IsValid(objectId) ((bool) ((objectId) != InvalidOid8))
862#define RegProcedureIsValid(p) OidIsValid(p)
873#define lengthof(array) (sizeof (array) / sizeof ((array)[0]))
889#define TYPEALIGN(ALIGNVAL,LEN) \
890 (((uintptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
892#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
893#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
894#define INT64ALIGN(LEN) TYPEALIGN(ALIGNOF_INT64_T, (LEN))
895#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
896#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
898#define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN))
899#define CACHELINEALIGN(LEN) TYPEALIGN(PG_CACHE_LINE_SIZE, (LEN))
901#define TYPEALIGN_DOWN(ALIGNVAL,LEN) \
902 (((uintptr_t) (LEN)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
904#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
905#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
906#define INT64ALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT64_T, (LEN))
907#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
908#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
909#define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN))
917#define TYPEALIGN64(ALIGNVAL,LEN) \
918 (((uint64) (LEN) + ((ALIGNVAL) - 1)) & ~((uint64) ((ALIGNVAL) - 1)))
921#define MAXALIGN64(LEN) TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
941#ifndef USE_ASSERT_CHECKING
943#define Assert(condition) ((void)true)
944#define AssertMacro(condition) ((void)true)
946#elif defined(FRONTEND)
948#define Assert(p) assert(p)
949#define AssertMacro(p) ((void) assert(p))
957#define Assert(condition) \
960 ExceptionalCondition(#condition, __FILE__, __LINE__); \
969#define AssertMacro(condition) \
970 ((void) ((condition) || \
971 (ExceptionalCondition(#condition, __FILE__, __LINE__), 0)))
978#define AssertPointerAlignment(ptr, bndr) \
979 Assert(TYPEALIGN(bndr, (uintptr_t)(ptr)) == (uintptr_t)(ptr))
1008#define StaticAssertDecl(condition, errmessage) \
1009 static_assert(condition, errmessage)
1015#define StaticAssertStmt(condition, errmessage) \
1016 do { static_assert(condition, errmessage); } while(0)
1032#if !defined(_MSC_VER) || _MSC_VER >= 1933
1033#define StaticAssertExpr(condition, errmessage) \
1034 ((void) sizeof(struct {static_assert(condition, errmessage); char a;}))
1040#define StaticAssertExpr(condition, errmessage) \
1041 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
1044#define StaticAssertExpr(condition, errmessage) \
1045 ([]{static_assert(condition, errmessage);})
1060#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
1061#define StaticAssertVariableIsOfType(varname, typename) \
1062 StaticAssertDecl(__builtin_types_compatible_p(typeof(varname), typename), \
1063 CppAsString(varname) " does not have type " CppAsString(typename))
1064#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
1065 (StaticAssertExpr(__builtin_types_compatible_p(typeof(varname), typename), \
1066 CppAsString(varname) " does not have type " CppAsString(typename)))
1068#define StaticAssertVariableIsOfType(varname, typename) \
1069 StaticAssertDecl(sizeof(varname) == sizeof(typename), \
1070 CppAsString(varname) " does not have type " CppAsString(typename))
1071#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
1072 (StaticAssertExpr(sizeof(varname) == sizeof(typename), \
1073 CppAsString(varname) " does not have type " CppAsString(typename)))
1085#define Max(x, y) ((x) > (y) ? (x) : (y))
1091#define Min(x, y) ((x) < (y) ? (x) : (y))
1095#define SIZE_T_ALIGN_MASK (sizeof(size_t) - 1)
1107#define MemSet(start, val, len) \
1111 void *_vstart = (void *) (start); \
1113 Size _len = (len); \
1115 if ((((uintptr_t) _vstart) & SIZE_T_ALIGN_MASK) == 0 && \
1116 (_len & SIZE_T_ALIGN_MASK) == 0 && \
1118 _len <= MEMSET_LOOP_LIMIT && \
1123 MEMSET_LOOP_LIMIT != 0) \
1125 size_t *_start = (size_t *) _vstart; \
1126 size_t *_stop = (size_t *) ((char *) _start + _len); \
1127 while (_start < _stop) \
1131 memset(_vstart, _val, _len); \
1140#define MemSetAligned(start, val, len) \
1143 size_t *_start = (size_t *) (start); \
1145 Size _len = (len); \
1147 if ((_len & SIZE_T_ALIGN_MASK) == 0 && \
1149 _len <= MEMSET_LOOP_LIMIT && \
1150 MEMSET_LOOP_LIMIT != 0) \
1152 size_t *_stop = (size_t *) ((char *) _start + _len); \
1153 while (_start < _stop) \
1157 memset(_start, _val, _len); \
1172#define FLOAT4_FITS_IN_INT16(num) \
1173 ((num) >= (float4) PG_INT16_MIN && (num) < -((float4) PG_INT16_MIN))
1174#define FLOAT4_FITS_IN_INT32(num) \
1175 ((num) >= (float4) PG_INT32_MIN && (num) < -((float4) PG_INT32_MIN))
1176#define FLOAT4_FITS_IN_INT64(num) \
1177 ((num) >= (float4) PG_INT64_MIN && (num) < -((float4) PG_INT64_MIN))
1178#define FLOAT8_FITS_IN_INT16(num) \
1179 ((num) >= (float8) PG_INT16_MIN && (num) < -((float8) PG_INT16_MIN))
1180#define FLOAT8_FITS_IN_INT32(num) \
1181 ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))
1182#define FLOAT8_FITS_IN_INT64(num) \
1183 ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN))
1196#define INVERT_COMPARE_RESULT(var) \
1197 ((var) = ((var) < 0) ? 1 : -(var))
1216#if !(defined(__cplusplus) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 9)
1246#define HIGHBIT (0x80)
1247#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
1255#define SQL_STR_DOUBLE(ch, escape_backslash) \
1256 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
1258#define ESCAPE_STRING_SYNTAX 'E'
1261#define STATUS_OK (0)
1262#define STATUS_ERROR (-1)
1263#define STATUS_EOF (-2)
1271#define gettext(x) (x)
1272#define dgettext(d,x) (x)
1273#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
1274#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
1277#define _(x) gettext(x)
1288#define gettext_noop(x) (x)
1303#ifdef SO_MAJOR_VERSION
1304#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1306#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
1324#if defined(__cplusplus)
1325#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
1326#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
1328#define unconstify(underlying_type, expr) \
1329 (StaticAssertVariableIsOfTypeMacro(expr, const underlying_type), \
1330 (underlying_type) (expr))
1331#define unvolatize(underlying_type, expr) \
1332 (StaticAssertVariableIsOfTypeMacro(expr, volatile underlying_type), \
1333 (underlying_type) (expr))
1340#if (defined(__x86_64__) || defined(_M_AMD64))
1351#elif defined(__aarch64__) && defined(__ARM_NEON)
1371#if defined(WIN32) || defined(__CYGWIN__)
1372#define PG_BINARY O_BINARY
1373#define PG_BINARY_A "ab"
1374#define PG_BINARY_R "rb"
1375#define PG_BINARY_W "wb"
1378#define PG_BINARY_A "a"
1379#define PG_BINARY_R "r"
1380#define PG_BINARY_W "w"
1388#if !HAVE_DECL_FDATASYNC
1398#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))
1399#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base))
1400#elif SIZEOF_LONG_LONG == 8
1401#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base))
1402#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base))
1404#error "cannot find integer type of the same size as int64_t"
1411#define i64abs(i) ((int64) labs(i))
1412#elif SIZEOF_LONG_LONG == 8
1413#define i64abs(i) ((int64) llabs(i))
1415#error "cannot find integer type of the same size as int64_t"
1436#ifdef HAVE_VISIBILITY_ATTRIBUTE
1437#define PGDLLEXPORT __attribute__((visibility("default")))
1465#define SIGNAL_ARGS int postgres_signal_arg, const pg_signal_info *pg_siginfo
1476#define sigsetjmp(x,y) __builtin_setjmp(x)
1477#define siglongjmp __builtin_longjmp
1479#define sigjmp_buf jmp_buf
1480#define sigsetjmp(x,y) setjmp(x)
1481#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]