1074 {
static_assert(condition,
errmessage); }
while(0)
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084#ifndef __cplusplus
1085#define StaticAssertExpr(condition, errmessage) \
1086 ((void) sizeof(struct {static_assert(condition, errmessage); char a;}))
1087#else
1088#define StaticAssertExpr(condition, errmessage) \
1089 ([]{static_assert(condition, errmessage);})
1090#endif
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108#define StaticAssertVariableIsOfType(varname, typename) \
1109 StaticAssertDecl(_Generic((varname), typename: 1, default: 0), \
1110 CppAsString(varname) " does not have type " CppAsString(typename))
1111#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
1112 (StaticAssertExpr(_Generic((varname), typename: 1, default: 0), \
1113 CppAsString(varname) " does not have type " CppAsString(typename)))
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124#define Max(x, y) ((x) > (y) ? (x) : (y))
1125
1126
1127
1128
1129
1130#define Min(x, y) ((x) < (y) ? (x) : (y))
1131
1132
1133
1134#define SIZE_T_ALIGN_MASK (sizeof(size_t) - 1)
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146#define MemSet(start, val, len) \
1147 do \
1148 { \
1149 \
1150 void *_vstart = (void *) (start); \
1151 int _val = (val); \
1152 Size _len = (len); \
1153\
1154 if ((((uintptr_t) _vstart) & SIZE_T_ALIGN_MASK) == 0 && \
1155 (_len & SIZE_T_ALIGN_MASK) == 0 && \
1156 _val == 0 && \
1157 _len <= MEMSET_LOOP_LIMIT && \
1158
1159
1160
1161 \
1162 MEMSET_LOOP_LIMIT != 0) \
1163 { \
1164 size_t *_start = (size_t *) _vstart; \
1165 size_t *_stop = (size_t *) ((char *) _start + _len); \
1166 while (_start < _stop) \
1167 *_start++ = 0; \
1168 } \
1169 else \
1170 memset(_vstart, _val, _len); \
1171 } while (0)
1172
1173
1174
1175
1176
1177
1178
1179#define MemSetAligned(start, val, len) \
1180 do \
1181 { \
1182 size_t *_start = (size_t *) (start); \
1183 int _val = (val); \
1184 Size _len = (len); \
1185\
1186 if ((_len & SIZE_T_ALIGN_MASK) == 0 && \
1187 _val == 0 && \
1188 _len <= MEMSET_LOOP_LIMIT && \
1189 MEMSET_LOOP_LIMIT != 0) \
1190 { \
1191 size_t *_stop = (size_t *) ((char *) _start + _len); \
1192 while (_start < _stop) \
1193 *_start++ = 0; \
1194 } \
1195 else \
1196 memset(_start, _val, _len); \
1197 } while (0)
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211#define FLOAT4_FITS_IN_INT16(num) \
1212 ((num) >= (float4) PG_INT16_MIN && (num) < -((float4) PG_INT16_MIN))
1213#define FLOAT4_FITS_IN_INT32(num) \
1214 ((num) >= (float4) PG_INT32_MIN && (num) < -((float4) PG_INT32_MIN))
1215#define FLOAT4_FITS_IN_INT64(num) \
1216 ((num) >= (float4) PG_INT64_MIN && (num) < -((float4) PG_INT64_MIN))
1217#define FLOAT8_FITS_IN_INT16(num) \
1218 ((num) >= (float8) PG_INT16_MIN && (num) < -((float8) PG_INT16_MIN))
1219#define FLOAT8_FITS_IN_INT32(num) \
1220 ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))
1221#define FLOAT8_FITS_IN_INT64(num) \
1222 ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN))
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235#define INVERT_COMPARE_RESULT(var) \
1236 ((var) = ((var) < 0) ? 1 : -(var))
1237
1238
1239
1240
1241
1242
1243
1245{
1248
1249
1250
1251
1252
1253
1254
1255#if !(defined(__cplusplus) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 9)
1256
1257
1258
1259
1260
1261
1262
1263
1264
1266{
1269
1270
1272{
1275
1276#else
1277
1278
1281
1282#endif
1283
1284
1285#define HIGHBIT (0x80)
1286#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
1287
1288
1289
1290
1291
1292
1293
1294#define SQL_STR_DOUBLE(ch, escape_backslash) \
1295 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
1296
1297#define ESCAPE_STRING_SYNTAX 'E'
1298
1299
1300#define STATUS_OK (0)
1301#define STATUS_ERROR (-1)
1302#define STATUS_EOF (-2)
1303
1304
1305
1306
1307
1308#ifndef ENABLE_NLS
1309
1310#define gettext(x) (x)
1311#define dgettext(d,x) (x)
1312#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
1313#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
1314#endif
1315
1316#define _(x) gettext(x)
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327#define gettext_noop(x) (x)
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342#ifdef SO_MAJOR_VERSION
1343#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1344#else
1345#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
1346#endif
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368#if defined(__cplusplus)
1369#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
1370#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
1371#else
1372#define unconstify(underlying_type, expr) \
1373 (StaticAssertVariableIsOfTypeMacro(expr, const underlying_type), \
1374 (underlying_type) (expr))
1375#define unvolatize(underlying_type, expr) \
1376 (StaticAssertVariableIsOfTypeMacro(expr, volatile underlying_type), \
1377 (underlying_type) (expr))
1378#endif
1379
1380
1381
1382
1383
1384#if defined(__x86_64__)
1385#define USE_SSE2
1386
1387#else
1388
1389
1390
1391
1392
1393
1394#undef USE_AVX2_WITH_RUNTIME_CHECK
1395#undef USE_AVX512_CRC32C_WITH_RUNTIME_CHECK
1396#undef USE_AVX512_POPCNT_WITH_RUNTIME_CHECK
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406#if defined(__aarch64__) && defined(__ARM_NEON)
1407#define USE_NEON
1408#endif
1409#endif
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427#if defined(WIN32) || defined(__CYGWIN__)
1428#define PG_BINARY O_BINARY
1429#define PG_BINARY_A "ab"
1430#define PG_BINARY_R "rb"
1431#define PG_BINARY_W "wb"
1432#else
1433#define PG_BINARY 0
1434#define PG_BINARY_A "a"
1435#define PG_BINARY_R "r"
1436#define PG_BINARY_W "w"
1437#endif
1438
1439
1440
1441
1442
1443
1444#if !HAVE_DECL_FDATASYNC
1446#endif
1447
1448
1449
1450
1451
1452
1453#if SIZEOF_LONG == 8
1454#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))
1455#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base))
1456#elif SIZEOF_LONG_LONG == 8
1457#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base))
1458#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base))
1459#else
1460#error "cannot find integer type of the same size as int64_t"
1461#endif
1462
1463
1464
1465
1466#if SIZEOF_LONG == 8
1467#define i64abs(i) ((int64) labs(i))
1468#elif SIZEOF_LONG_LONG == 8
1469#define i64abs(i) ((int64) llabs(i))
1470#else
1471#error "cannot find integer type of the same size as int64_t"
1472#endif
1473
1474
1475
1476
1477
1478
1479#ifndef PGDLLIMPORT
1480#define PGDLLIMPORT
1481#endif
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491#ifndef PGDLLEXPORT
1492#ifdef HAVE_VISIBILITY_ATTRIBUTE
1493#define PGDLLEXPORT __attribute__((visibility("default")))
1494#else
1495#define PGDLLEXPORT
1496#endif
1497#endif
1498
1499
1500
1501
1502
1503
1504
1505
1507{
1510
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521#define SIGNAL_ARGS int postgres_signal_arg, const pg_signal_info *pg_siginfo
1522
1523
1524
1525
1526
1527
1528
1529#ifdef WIN32
1530#ifdef __MINGW64__
1532#define sigsetjmp(x,y) __builtin_setjmp(x)
1533#define siglongjmp __builtin_longjmp
1534#else
1535#define sigjmp_buf jmp_buf
1536#define sigsetjmp(x,y) setjmp(x)
1537#define siglongjmp longjmp
1538#endif
1539#endif
1540
1541
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558#ifdef HAVE_UCHAR_H
1559#include <uchar.h>
1560#else
1561#ifndef __cplusplus
1564#endif
1565#endif
1566
1567
1568
1569#endif
static int fd(const char *x, int i)