54 #include "pg_config.h" 56 #include "pg_config_os.h" 68 #include <sys/types.h> 70 #if defined(WIN32) || defined(__CYGWIN__) 91 #ifdef PG_FORCE_DISABLE_INLINE 112 #ifndef __has_attribute 113 #define __has_attribute(attribute) 0 118 #define pg_attribute_unused() __attribute__((unused)) 120 #define pg_attribute_unused() 130 #define pg_nodiscard __attribute__((warn_unused_result)) 141 #if __clang_major__ >= 7 || __GNUC__ >= 8 142 #define pg_attribute_no_sanitize_alignment() __attribute__((no_sanitize("alignment"))) 144 #define pg_attribute_no_sanitize_alignment() 152 #ifdef USE_ASSERT_CHECKING 153 #define PG_USED_FOR_ASSERTS_ONLY 155 #define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused() 159 #if defined(__GNUC__) || defined(__IBMC__) 160 #define pg_attribute_format_arg(a) __attribute__((format_arg(a))) 161 #define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a))) 163 #define pg_attribute_format_arg(a) 164 #define pg_attribute_printf(f,a) 168 #if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__) 169 #define pg_attribute_aligned(a) __attribute__((aligned(a))) 170 #define pg_attribute_noreturn() __attribute__((noreturn)) 171 #define pg_attribute_packed() __attribute__((packed)) 172 #define HAVE_PG_ATTRIBUTE_NORETURN 1 179 #define pg_attribute_noreturn() 188 #if (defined(__GNUC__) && __GNUC__ > 3 && defined(__OPTIMIZE__)) || defined(__SUNPRO_C) || defined(__IBMC__) 190 #define pg_attribute_always_inline __attribute__((always_inline)) inline 191 #elif defined(_MSC_VER) 193 #define pg_attribute_always_inline __forceinline 196 #define pg_attribute_always_inline inline 206 #if (defined(__GNUC__) && __GNUC__ > 2) || defined(__SUNPRO_C) || defined(__IBMC__) 207 #define pg_noinline __attribute__((noinline)) 209 #elif defined(_MSC_VER) 210 #define pg_noinline __declspec(noinline) 224 #if defined(__MINGW64__) && __GNUC__ == 8 && __GNUC_MINOR__ == 1 226 #define pg_attribute_cold 227 #define pg_attribute_hot 234 #if __has_attribute (cold) 235 #define pg_attribute_cold __attribute__((cold)) 237 #define pg_attribute_cold 240 #if __has_attribute (hot) 241 #define pg_attribute_hot __attribute__((hot)) 243 #define pg_attribute_hot 253 #if defined(HAVE__BUILTIN_UNREACHABLE) && !defined(USE_ASSERT_CHECKING) 254 #define pg_unreachable() __builtin_unreachable() 255 #elif defined(_MSC_VER) && !defined(USE_ASSERT_CHECKING) 256 #define pg_unreachable() __assume(0) 258 #define pg_unreachable() abort() 269 #define likely(x) __builtin_expect((x) != 0, 1) 270 #define unlikely(x) __builtin_expect((x) != 0, 0) 272 #define likely(x) ((x) != 0) 273 #define unlikely(x) ((x) != 0) 288 #define CppAsString(identifier) #identifier 289 #define CppAsString2(x) CppAsString(x) 290 #define CppConcat(x, y) x##y 306 #define VA_ARGS_NARGS(...) \ 307 VA_ARGS_NARGS_(__VA_ARGS__, \ 309 59,58,57,56,55,54,53,52,51,50, \ 310 49,48,47,46,45,44,43,42,41,40, \ 311 39,38,37,36,35,34,33,32,31,30, \ 312 29,28,27,26,25,24,23,22,21,20, \ 313 19,18,17,16,15,14,13,12,11,10, \ 314 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) 315 #define VA_ARGS_NARGS_( \ 316 _01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \ 317 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \ 318 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \ 319 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \ 320 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \ 321 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \ 322 _61,_62,_63, N, ...) \ 330 #define dummyret void 332 #define dummyret char 350 #define FLEXIBLE_ARRAY_MEMBER 353 #ifdef HAVE_FUNCNAME__FUNC 354 #define PG_FUNCNAME_MACRO __func__ 356 #ifdef HAVE_FUNCNAME__FUNCTION 357 #define PG_FUNCNAME_MACRO __FUNCTION__ 359 #define PG_FUNCNAME_MACRO NULL 386 #ifdef PG_USE_STDBOOL 395 #define true ((bool) 1) 399 #define false ((bool) 0) 455 #ifdef HAVE_LONG_INT_64 459 typedef long int int64;
462 typedef unsigned long int uint64;
464 #define INT64CONST(x) (x##L) 465 #define UINT64CONST(x) (x##UL) 466 #elif defined(HAVE_LONG_LONG_INT_64) 470 typedef long long int int64;
473 typedef unsigned long long int uint64;
475 #define INT64CONST(x) (x##LL) 476 #define UINT64CONST(x) (x##ULL) 479 #error must have a working 64-bit integer datatype 483 #define INT64_FORMAT "%" INT64_MODIFIER "d" 484 #define UINT64_FORMAT "%" INT64_MODIFIER "u" 494 #if defined(PG_INT128_TYPE) 495 #if defined(pg_attribute_aligned) || ALIGNOF_PG_INT128_TYPE <= MAXIMUM_ALIGNOF 496 #define HAVE_INT128 1 498 typedef PG_INT128_TYPE int128
499 #if defined(pg_attribute_aligned) 500 pg_attribute_aligned(MAXIMUM_ALIGNOF)
504 typedef unsigned PG_INT128_TYPE uint128
505 #if defined(pg_attribute_aligned) 506 pg_attribute_aligned(MAXIMUM_ALIGNOF)
517 #define PG_INT8_MIN (-0x7F-1) 518 #define PG_INT8_MAX (0x7F) 519 #define PG_UINT8_MAX (0xFF) 520 #define PG_INT16_MIN (-0x7FFF-1) 521 #define PG_INT16_MAX (0x7FFF) 522 #define PG_UINT16_MAX (0xFFFF) 523 #define PG_INT32_MIN (-0x7FFFFFFF-1) 524 #define PG_INT32_MAX (0x7FFFFFFF) 525 #define PG_UINT32_MAX (0xFFFFFFFFU) 526 #define PG_INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1) 527 #define PG_INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF) 528 #define PG_UINT64_MAX UINT64CONST(0xFFFFFFFFFFFFFFFF) 534 #define HAVE_INT64_TIMESTAMP 567 #ifdef USE_FLOAT8_BYVAL 568 #define FLOAT8PASSBYVAL true 570 #define FLOAT8PASSBYVAL false 593 #define InvalidSubTransactionId ((SubTransactionId) 0) 594 #define TopSubTransactionId ((SubTransactionId) 1) 603 #define FirstCommandId ((CommandId) 0) 604 #define InvalidCommandId (~(CommandId)0) 627 #define VARHDRSZ ((int32) sizeof(int32)) 681 #define NameStr(name) ((name).data) 692 #define BoolIsValid(boolean) ((boolean) == false || (boolean) == true) 698 #define PointerIsValid(pointer) ((const void*)(pointer) != NULL) 704 #define PointerIsAligned(pointer, type) \ 705 (((uintptr_t)(pointer) % (sizeof (type))) == 0) 707 #define OffsetToPointer(base, offset) \ 708 ((void *)((char *) base + offset)) 710 #define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid)) 712 #define RegProcedureIsValid(p) OidIsValid(p) 727 #define offsetof(type, field) ((long) &((type *)0)->field) 734 #define lengthof(array) (sizeof (array) / sizeof ((array)[0])) 750 #define TYPEALIGN(ALIGNVAL,LEN) \ 751 (((uintptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uintptr_t) ((ALIGNVAL) - 1))) 753 #define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN)) 754 #define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN)) 755 #define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN)) 756 #define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN)) 757 #define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN)) 759 #define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN)) 760 #define CACHELINEALIGN(LEN) TYPEALIGN(PG_CACHE_LINE_SIZE, (LEN)) 762 #define TYPEALIGN_DOWN(ALIGNVAL,LEN) \ 763 (((uintptr_t) (LEN)) & ~((uintptr_t) ((ALIGNVAL) - 1))) 765 #define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN)) 766 #define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN)) 767 #define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN)) 768 #define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN)) 769 #define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN)) 770 #define BUFFERALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_BUFFER, (LEN)) 778 #define TYPEALIGN64(ALIGNVAL,LEN) \ 779 (((uint64) (LEN) + ((ALIGNVAL) - 1)) & ~((uint64) ((ALIGNVAL) - 1))) 782 #define MAXALIGN64(LEN) TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN)) 802 #ifndef USE_ASSERT_CHECKING 804 #define Assert(condition) ((void)true) 805 #define AssertMacro(condition) ((void)true) 806 #define AssertArg(condition) ((void)true) 807 #define AssertState(condition) ((void)true) 808 #define AssertPointerAlignment(ptr, bndr) ((void)true) 809 #define Trap(condition, errorType) ((void)true) 810 #define TrapMacro(condition, errorType) (true) 812 #elif defined(FRONTEND) 815 #define Assert(p) assert(p) 816 #define AssertMacro(p) ((void) assert(p)) 817 #define AssertArg(condition) assert(condition) 818 #define AssertState(condition) assert(condition) 819 #define AssertPointerAlignment(ptr, bndr) ((void)true) 827 #define Trap(condition, errorType) \ 830 ExceptionalCondition(#condition, (errorType), \ 831 __FILE__, __LINE__); \ 841 #define TrapMacro(condition, errorType) \ 842 ((bool) (! (condition) || \ 843 (ExceptionalCondition(#condition, (errorType), \ 844 __FILE__, __LINE__), 0))) 846 #define Assert(condition) \ 849 ExceptionalCondition(#condition, "FailedAssertion", \ 850 __FILE__, __LINE__); \ 853 #define AssertMacro(condition) \ 854 ((void) ((condition) || \ 855 (ExceptionalCondition(#condition, "FailedAssertion", \ 856 __FILE__, __LINE__), 0))) 858 #define AssertArg(condition) \ 861 ExceptionalCondition(#condition, "BadArgument", \ 862 __FILE__, __LINE__); \ 865 #define AssertState(condition) \ 868 ExceptionalCondition(#condition, "BadState", \ 869 __FILE__, __LINE__); \ 875 #define AssertPointerAlignment(ptr, bndr) \ 876 Trap(TYPEALIGN(bndr, (uintptr_t)(ptr)) != (uintptr_t)(ptr), \ 889 const char *errorType,
910 #ifdef HAVE__STATIC_ASSERT 911 #define StaticAssertStmt(condition, errmessage) \ 912 do { _Static_assert(condition, errmessage); } while(0) 913 #define StaticAssertExpr(condition, errmessage) \ 914 ((void) ({ StaticAssertStmt(condition, errmessage); true; })) 915 #define StaticAssertDecl(condition, errmessage) \ 916 _Static_assert(condition, errmessage) 918 #define StaticAssertStmt(condition, errmessage) \ 919 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; })) 920 #define StaticAssertExpr(condition, errmessage) \ 921 StaticAssertStmt(condition, errmessage) 922 #define StaticAssertDecl(condition, errmessage) \ 923 extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1]) 926 #if defined(__cpp_static_assert) && __cpp_static_assert >= 200410 927 #define StaticAssertStmt(condition, errmessage) \ 928 static_assert(condition, errmessage) 929 #define StaticAssertExpr(condition, errmessage) \ 930 ({ static_assert(condition, errmessage); }) 931 #define StaticAssertDecl(condition, errmessage) \ 932 static_assert(condition, errmessage) 934 #define StaticAssertStmt(condition, errmessage) \ 935 do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0) 936 #define StaticAssertExpr(condition, errmessage) \ 937 ((void) ({ StaticAssertStmt(condition, errmessage); })) 938 #define StaticAssertDecl(condition, errmessage) \ 939 extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1]) 955 #ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P 956 #define AssertVariableIsOfType(varname, typename) \ 957 StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \ 958 CppAsString(varname) " does not have type " CppAsString(typename)) 959 #define AssertVariableIsOfTypeMacro(varname, typename) \ 960 (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \ 961 CppAsString(varname) " does not have type " CppAsString(typename))) 963 #define AssertVariableIsOfType(varname, typename) \ 964 StaticAssertStmt(sizeof(varname) == sizeof(typename), \ 965 CppAsString(varname) " does not have type " CppAsString(typename)) 966 #define AssertVariableIsOfTypeMacro(varname, typename) \ 967 (StaticAssertExpr(sizeof(varname) == sizeof(typename), \ 968 CppAsString(varname) " does not have type " CppAsString(typename))) 980 #define Max(x, y) ((x) > (y) ? (x) : (y)) 986 #define Min(x, y) ((x) < (y) ? (x) : (y)) 992 #define Abs(x) ((x) >= 0 ? (x) : -(x)) 996 #define LONG_ALIGN_MASK (sizeof(long) - 1) 1008 #define MemSet(start, val, len) \ 1012 void *_vstart = (void *) (start); \ 1014 Size _len = (len); \ 1016 if ((((uintptr_t) _vstart) & LONG_ALIGN_MASK) == 0 && \ 1017 (_len & LONG_ALIGN_MASK) == 0 && \ 1019 _len <= MEMSET_LOOP_LIMIT && \ 1024 MEMSET_LOOP_LIMIT != 0) \ 1026 long *_start = (long *) _vstart; \ 1027 long *_stop = (long *) ((char *) _start + _len); \ 1028 while (_start < _stop) \ 1032 memset(_vstart, _val, _len); \ 1041 #define MemSetAligned(start, val, len) \ 1044 long *_start = (long *) (start); \ 1046 Size _len = (len); \ 1048 if ((_len & LONG_ALIGN_MASK) == 0 && \ 1050 _len <= MEMSET_LOOP_LIMIT && \ 1051 MEMSET_LOOP_LIMIT != 0) \ 1053 long *_stop = (long *) ((char *) _start + _len); \ 1054 while (_start < _stop) \ 1058 memset(_start, _val, _len); \ 1070 #define MemSetTest(val, len) \ 1071 ( ((len) & LONG_ALIGN_MASK) == 0 && \ 1072 (len) <= MEMSET_LOOP_LIMIT && \ 1073 MEMSET_LOOP_LIMIT != 0 && \ 1076 #define MemSetLoop(start, val, len) \ 1079 long * _start = (long *) (start); \ 1080 long * _stop = (long *) ((char *) _start + (Size) (len)); \ 1082 while (_start < _stop) \ 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)) 1116 #ifdef HAVE_STRUCT_SOCKADDR_UN 1117 #define HAVE_UNIX_SOCKETS 1 1125 #define INVERT_COMPARE_RESULT(var) \ 1126 ((var) = ((var) < 0) ? 1 : -(var)) 1149 char data[XLOG_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(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)) 1265 #if defined(WIN32) || defined(__CYGWIN__) 1266 #define PG_BINARY O_BINARY 1267 #define PG_BINARY_A "ab" 1268 #define PG_BINARY_R "rb" 1269 #define PG_BINARY_W "wb" 1272 #define PG_BINARY_A "a" 1273 #define PG_BINARY_R "r" 1274 #define PG_BINARY_W "w" 1282 #if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC 1283 extern int fdatasync(
int fildes);
1287 #if !defined(HAVE_STRTOLL) && defined(HAVE___STRTOLL) 1288 #define strtoll __strtoll 1289 #define HAVE_STRTOLL 1 1292 #if !defined(HAVE_STRTOLL) && defined(HAVE_STRTOQ) 1293 #define strtoll strtoq 1294 #define HAVE_STRTOLL 1 1297 #if !defined(HAVE_STRTOULL) && defined(HAVE___STRTOULL) 1298 #define strtoull __strtoull 1299 #define HAVE_STRTOULL 1 1302 #if !defined(HAVE_STRTOULL) && defined(HAVE_STRTOUQ) 1303 #define strtoull strtouq 1304 #define HAVE_STRTOULL 1 1307 #if defined(HAVE_STRTOLL) && !HAVE_DECL_STRTOLL 1308 extern long long strtoll(
const char *
str,
char **endptr,
int base);
1311 #if defined(HAVE_STRTOULL) && !HAVE_DECL_STRTOULL 1312 extern unsigned long long strtoull(
const char *
str,
char **endptr,
int base);
1333 #define SIGNAL_ARGS int postgres_signal_arg 1342 #define sigjmp_buf jmp_buf 1343 #define sigsetjmp(x,y) setjmp(x) 1344 #define siglongjmp longjmp 1349 #define NON_EXEC_STATIC 1351 #define NON_EXEC_STATIC static
#define pg_attribute_noreturn()
#define FLEXIBLE_ARRAY_MEMBER
union PGAlignedXLogBlock PGAlignedXLogBlock
union PGAlignedBlock PGAlignedBlock
uint32 LocalTransactionId
char vl_dat[FLEXIBLE_ARRAY_MEMBER]
TransactionId MultiXactId
static Datum values[MAXATTR]
void(* pg_funcptr_t)(void)
void ExceptionalCondition(const char *conditionName, const char *errorType, const char *fileName, int lineNumber) pg_attribute_noreturn()