1017 {
static_assert(condition,
errmessage); }
while(0)
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032#ifndef __cplusplus
1033#if !defined(_MSC_VER) || _MSC_VER >= 1933
1034#define StaticAssertExpr(condition, errmessage) \
1035 ((void) sizeof(struct {static_assert(condition, errmessage); char a;}))
1036#else
1037
1038
1039
1040
1041#define StaticAssertExpr(condition, errmessage) \
1042 ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
1043#endif
1044#else
1045#define StaticAssertExpr(condition, errmessage) \
1046 ([]{static_assert(condition, errmessage);})
1047#endif
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
1062#define StaticAssertVariableIsOfType(varname, typename) \
1063 StaticAssertDecl(__builtin_types_compatible_p(typeof(varname), typename), \
1064 CppAsString(varname) " does not have type " CppAsString(typename))
1065#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
1066 (StaticAssertExpr(__builtin_types_compatible_p(typeof(varname), typename), \
1067 CppAsString(varname) " does not have type " CppAsString(typename)))
1068#else
1069#define StaticAssertVariableIsOfType(varname, typename) \
1070 StaticAssertDecl(sizeof(varname) == sizeof(typename), \
1071 CppAsString(varname) " does not have type " CppAsString(typename))
1072#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
1073 (StaticAssertExpr(sizeof(varname) == sizeof(typename), \
1074 CppAsString(varname) " does not have type " CppAsString(typename)))
1075#endif
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086#define Max(x, y) ((x) > (y) ? (x) : (y))
1087
1088
1089
1090
1091
1092#define Min(x, y) ((x) < (y) ? (x) : (y))
1093
1094
1095
1096#define SIZE_T_ALIGN_MASK (sizeof(size_t) - 1)
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108#define MemSet(start, val, len) \
1109 do \
1110 { \
1111 \
1112 void *_vstart = (void *) (start); \
1113 int _val = (val); \
1114 Size _len = (len); \
1115\
1116 if ((((uintptr_t) _vstart) & SIZE_T_ALIGN_MASK) == 0 && \
1117 (_len & SIZE_T_ALIGN_MASK) == 0 && \
1118 _val == 0 && \
1119 _len <= MEMSET_LOOP_LIMIT && \
1120
1121
1122
1123 \
1124 MEMSET_LOOP_LIMIT != 0) \
1125 { \
1126 size_t *_start = (size_t *) _vstart; \
1127 size_t *_stop = (size_t *) ((char *) _start + _len); \
1128 while (_start < _stop) \
1129 *_start++ = 0; \
1130 } \
1131 else \
1132 memset(_vstart, _val, _len); \
1133 } while (0)
1134
1135
1136
1137
1138
1139
1140
1141#define MemSetAligned(start, val, len) \
1142 do \
1143 { \
1144 size_t *_start = (size_t *) (start); \
1145 int _val = (val); \
1146 Size _len = (len); \
1147\
1148 if ((_len & SIZE_T_ALIGN_MASK) == 0 && \
1149 _val == 0 && \
1150 _len <= MEMSET_LOOP_LIMIT && \
1151 MEMSET_LOOP_LIMIT != 0) \
1152 { \
1153 size_t *_stop = (size_t *) ((char *) _start + _len); \
1154 while (_start < _stop) \
1155 *_start++ = 0; \
1156 } \
1157 else \
1158 memset(_start, _val, _len); \
1159 } while (0)
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173#define FLOAT4_FITS_IN_INT16(num) \
1174 ((num) >= (float4) PG_INT16_MIN && (num) < -((float4) PG_INT16_MIN))
1175#define FLOAT4_FITS_IN_INT32(num) \
1176 ((num) >= (float4) PG_INT32_MIN && (num) < -((float4) PG_INT32_MIN))
1177#define FLOAT4_FITS_IN_INT64(num) \
1178 ((num) >= (float4) PG_INT64_MIN && (num) < -((float4) PG_INT64_MIN))
1179#define FLOAT8_FITS_IN_INT16(num) \
1180 ((num) >= (float8) PG_INT16_MIN && (num) < -((float8) PG_INT16_MIN))
1181#define FLOAT8_FITS_IN_INT32(num) \
1182 ((num) >= (float8) PG_INT32_MIN && (num) < -((float8) PG_INT32_MIN))
1183#define FLOAT8_FITS_IN_INT64(num) \
1184 ((num) >= (float8) PG_INT64_MIN && (num) < -((float8) PG_INT64_MIN))
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197#define INVERT_COMPARE_RESULT(var) \
1198 ((var) = ((var) < 0) ? 1 : -(var))
1199
1200
1201
1202
1203
1204
1205
1207{
1210
1211
1212
1213
1214
1215
1216
1217#if !(defined(__cplusplus) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 9)
1218
1219
1220
1221
1222
1223
1224
1225
1226
1228{
1231
1232
1234{
1237
1238#else
1239
1240
1243
1244#endif
1245
1246
1247#define HIGHBIT (0x80)
1248#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch) & HIGHBIT)
1249
1250
1251
1252
1253
1254
1255
1256#define SQL_STR_DOUBLE(ch, escape_backslash) \
1257 ((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
1258
1259#define ESCAPE_STRING_SYNTAX 'E'
1260
1261
1262#define STATUS_OK (0)
1263#define STATUS_ERROR (-1)
1264#define STATUS_EOF (-2)
1265
1266
1267
1268
1269
1270#ifndef ENABLE_NLS
1271
1272#define gettext(x) (x)
1273#define dgettext(d,x) (x)
1274#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
1275#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
1276#endif
1277
1278#define _(x) gettext(x)
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289#define gettext_noop(x) (x)
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304#ifdef SO_MAJOR_VERSION
1305#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
1306#else
1307#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
1308#endif
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325#if defined(__cplusplus)
1326#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
1327#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
1328#else
1329#define unconstify(underlying_type, expr) \
1330 (StaticAssertVariableIsOfTypeMacro(expr, const underlying_type), \
1331 (underlying_type) (expr))
1332#define unvolatize(underlying_type, expr) \
1333 (StaticAssertVariableIsOfTypeMacro(expr, volatile underlying_type), \
1334 (underlying_type) (expr))
1335#endif
1336
1337
1338
1339
1340
1341#if (defined(__x86_64__) || defined(_M_AMD64))
1342#define USE_SSE2
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352#elif defined(__aarch64__) && defined(__ARM_NEON)
1353#define USE_NEON
1354#endif
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372#if defined(WIN32) || defined(__CYGWIN__)
1373#define PG_BINARY O_BINARY
1374#define PG_BINARY_A "ab"
1375#define PG_BINARY_R "rb"
1376#define PG_BINARY_W "wb"
1377#else
1378#define PG_BINARY 0
1379#define PG_BINARY_A "a"
1380#define PG_BINARY_R "r"
1381#define PG_BINARY_W "w"
1382#endif
1383
1384
1385
1386
1387
1388
1389#if !HAVE_DECL_FDATASYNC
1391#endif
1392
1393
1394
1395
1396
1397
1398#if SIZEOF_LONG == 8
1399#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))
1400#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base))
1401#elif SIZEOF_LONG_LONG == 8
1402#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base))
1403#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base))
1404#else
1405#error "cannot find integer type of the same size as int64_t"
1406#endif
1407
1408
1409
1410
1411#if SIZEOF_LONG == 8
1412#define i64abs(i) ((int64) labs(i))
1413#elif SIZEOF_LONG_LONG == 8
1414#define i64abs(i) ((int64) llabs(i))
1415#else
1416#error "cannot find integer type of the same size as int64_t"
1417#endif
1418
1419
1420
1421
1422
1423
1424#ifndef PGDLLIMPORT
1425#define PGDLLIMPORT
1426#endif
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436#ifndef PGDLLEXPORT
1437#ifdef HAVE_VISIBILITY_ATTRIBUTE
1438#define PGDLLEXPORT __attribute__((visibility("default")))
1439#else
1440#define PGDLLEXPORT
1441#endif
1442#endif
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453#ifndef SIGNAL_ARGS
1454#define SIGNAL_ARGS int postgres_signal_arg
1455#endif
1456
1457
1458
1459
1460
1461
1462
1463#ifdef WIN32
1464#ifdef __MINGW64__
1466#define sigsetjmp(x,y) __builtin_setjmp(x)
1467#define siglongjmp __builtin_longjmp
1468#else
1469#define sigjmp_buf jmp_buf
1470#define sigsetjmp(x,y) setjmp(x)
1471#define siglongjmp longjmp
1472#endif
1473#endif
1474
1475
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492#ifdef HAVE_UCHAR_H
1493#include <uchar.h>
1494#else
1495#ifndef __cplusplus
1498#endif
1499#endif
1500
1501
1502
1503#endif
static int fd(const char *x, int i)