944 {
static_assert(condition,
errmessage); }
while(0)
945#ifdef HAVE_STATEMENT_EXPRESSIONS
946#define StaticAssertExpr(condition, errmessage) \
947 ((void) ({ static_assert(condition, errmessage); true; }))
948#else
949#define StaticAssertExpr(condition, errmessage) \
950 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
951#endif
952
953
954
955
956
957
958
959
960
961
962
963
964
965#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
966#define AssertVariableIsOfType(varname, typename) \
967 StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
968 CppAsString(varname) " does not have type " CppAsString(typename))
969#define AssertVariableIsOfTypeMacro(varname, typename) \
970 (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
971 CppAsString(varname) " does not have type " CppAsString(typename)))
972#else
973#define AssertVariableIsOfType(varname, typename) \
974 StaticAssertStmt(sizeof(varname) == sizeof(typename), \
975 CppAsString(varname) " does not have type " CppAsString(typename))
976#define AssertVariableIsOfTypeMacro(varname, typename) \
977 (StaticAssertExpr(sizeof(varname) == sizeof(typename), \
978 CppAsString(varname) " does not have type " CppAsString(typename)))
979#endif
980
981
982
983
984
985
986
987
988
989
990#define Max(x, y) ((x) > (y) ? (x) : (y))
991
992
993
994
995
996#define Min(x, y) ((x) < (y) ? (x) : (y))
997
998
999
1000#define SIZE_T_ALIGN_MASK (sizeof(size_t) - 1)
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012#define MemSet(start, val, len) \
1013 do \
1014 { \
1015 \
1016 void *_vstart = (void *) (start); \
1017 int _val = (val); \
1018 Size _len = (len); \
1019\
1020 if ((((uintptr_t) _vstart) & SIZE_T_ALIGN_MASK) == 0 && \
1021 (_len & SIZE_T_ALIGN_MASK) == 0 && \
1022 _val == 0 && \
1023 _len <= MEMSET_LOOP_LIMIT && \
1024
1025
1026
1027 \
1028 MEMSET_LOOP_LIMIT != 0) \
1029 { \
1030 size_t *_start = (size_t *) _vstart; \
1031 size_t *_stop = (size_t *) ((char *) _start + _len); \
1032 while (_start < _stop) \
1033 *_start++ = 0; \
1034 } \
1035 else \
1036 memset(_vstart, _val, _len); \
1037 } while (0)
1038
1039
1040
1041
1042
1043
1044
1045#define MemSetAligned(start, val, len) \
1046 do \
1047 { \
1048 size_t *_start = (size_t *) (start); \
1049 int _val = (val); \
1050 Size _len = (len); \
1051\
1052 if ((_len & SIZE_T_ALIGN_MASK) == 0 && \
1053 _val == 0 && \
1054 _len <= MEMSET_LOOP_LIMIT && \
1055 MEMSET_LOOP_LIMIT != 0) \
1056 { \
1057 size_t *_stop = (size_t *) ((char *) _start + _len); \
1058 while (_start < _stop) \
1059 *_start++ = 0; \
1060 } \
1061 else \
1062 memset(_start, _val, _len); \
1063 } while (0)
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077#define FLOAT4_FITS_IN_INT16(num) \
1078 ((num) >= (float4) PG_INT16_MIN && (num) < -((float4) PG_INT16_MIN))
1079#define FLOAT4_FITS_IN_INT32(num) \
1080 ((num) >= (float4) PG_INT32_MIN && (num) < -((float4) PG_INT32_MIN))
1081#define FLOAT4_FITS_IN_INT64(num) \
1082 ((num) >= (float4) PG_INT64_MIN && (num) < -((float4) PG_INT64_MIN))
1083#define FLOAT8_FITS_IN_INT16(num) \
1084 ((num) >= (float8) PG_INT16_MIN && (num) < -((float8) PG_INT16_MIN))
1085#define FLOAT8_FITS_IN_INT32(num) \
1086 ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))
1087#define FLOAT8_FITS_IN_INT64(num) \
1088 ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN))
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101#define INVERT_COMPARE_RESULT(var) \
1102 ((var) = ((var) < 0) ? 1 : -(var))
1103
1104
1105
1106
1107
1108
1109
1111{
1114
1115
1116
1117
1118
1119
1120
1121#if !(defined(__cplusplus) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 9)
1122
1123
1124
1125
1126
1127
1128
1129
1130
1132{
1135
1136
1138{
1141
1142#endif
1143
1144
1145#define HIGHBIT (0x80)
1146#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
1147
1148
1149
1150
1151
1152
1153
1154#define SQL_STR_DOUBLE(ch, escape_backslash) \
1155 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
1156
1157#define ESCAPE_STRING_SYNTAX 'E'
1158
1159
1160#define STATUS_OK (0)
1161#define STATUS_ERROR (-1)
1162#define STATUS_EOF (-2)
1163
1164
1165
1166
1167
1168#ifndef ENABLE_NLS
1169
1170#define gettext(x) (x)
1171#define dgettext(d,x) (x)
1172#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
1173#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
1174#endif
1175
1176#define _(x) gettext(x)
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187#define gettext_noop(x) (x)
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202#ifdef SO_MAJOR_VERSION
1203#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1204#else
1205#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
1206#endif
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223#if defined(__cplusplus)
1224#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
1225#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
1226#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
1227#define unconstify(underlying_type, expr) \
1228 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
1229 "wrong cast"), \
1230 (underlying_type) (expr))
1231#define unvolatize(underlying_type, expr) \
1232 (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
1233 "wrong cast"), \
1234 (underlying_type) (expr))
1235#else
1236#define unconstify(underlying_type, expr) \
1237 ((underlying_type) (expr))
1238#define unvolatize(underlying_type, expr) \
1239 ((underlying_type) (expr))
1240#endif
1241
1242
1243
1244
1245
1246#if (defined(__x86_64__) || defined(_M_AMD64))
1247#define USE_SSE2
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257#elif defined(__aarch64__) && defined(__ARM_NEON)
1258#define USE_NEON
1259#endif
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277#if defined(WIN32) || defined(__CYGWIN__)
1278#define PG_BINARY O_BINARY
1279#define PG_BINARY_A "ab"
1280#define PG_BINARY_R "rb"
1281#define PG_BINARY_W "wb"
1282#else
1283#define PG_BINARY 0
1284#define PG_BINARY_A "a"
1285#define PG_BINARY_R "r"
1286#define PG_BINARY_W "w"
1287#endif
1288
1289
1290
1291
1292
1293
1294#if !HAVE_DECL_FDATASYNC
1296#endif
1297
1298
1299
1300
1301
1302
1303#if SIZEOF_LONG == 8
1304#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))
1305#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base))
1306#elif SIZEOF_LONG_LONG == 8
1307#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base))
1308#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base))
1309#else
1310#error "cannot find integer type of the same size as int64_t"
1311#endif
1312
1313
1314
1315
1316#if SIZEOF_LONG == 8
1317#define i64abs(i) ((int64) labs(i))
1318#elif SIZEOF_LONG_LONG == 8
1319#define i64abs(i) ((int64) llabs(i))
1320#else
1321#error "cannot find integer type of the same size as int64_t"
1322#endif
1323
1324
1325
1326
1327
1328
1329#ifndef PGDLLIMPORT
1330#define PGDLLIMPORT
1331#endif
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341#ifndef PGDLLEXPORT
1342#ifdef HAVE_VISIBILITY_ATTRIBUTE
1343#define PGDLLEXPORT __attribute__((visibility("default")))
1344#else
1345#define PGDLLEXPORT
1346#endif
1347#endif
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358#ifndef SIGNAL_ARGS
1359#define SIGNAL_ARGS int postgres_signal_arg
1360#endif
1361
1362
1363
1364
1365
1366
1367
1368#ifdef WIN32
1369#ifdef __MINGW64__
1371#define sigsetjmp(x,y) __builtin_setjmp(x)
1372#define siglongjmp __builtin_longjmp
1373#else
1374#define sigjmp_buf jmp_buf
1375#define sigsetjmp(x,y) setjmp(x)
1376#define siglongjmp longjmp
1377#endif
1378#endif
1379
1380
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397#ifdef HAVE_UCHAR_H
1398#include <uchar.h>
1399#else
1400#ifndef __cplusplus
1403#endif
1404#endif
1405
1406
1407
1408#endif
static int fd(const char *x, int i)